element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
In the Air Design Challenge
  • Challenges & Projects
  • Design Challenges
  • In the Air Design Challenge
  • More
  • Cancel
In the Air Design Challenge
Blog AirMobile - 6 - Temperature sensor
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 24 Nov 2014 9:51 AM Date Created
  • Views 575 views
  • Likes 1 like
  • Comments 1 comment
  • low_power
  • iot_distributed
  • _adc
  • internet_of_things
  • msp_430
  • in_the_air
  • texas_instruments
  • low-power
  • internet-of-things
  • msp430
  • tmp36
  • adc
  • adcs
Related
Recommended

AirMobile - 6 - Temperature sensor

amgalbu
amgalbu
24 Nov 2014

Temperature sensor TMP36

Today I connected the temperature sensor Analog Devices TMP36 to the MSP430 Launchpad.

I chose his sensor for my project because it is widely used, cheap and very easy to use

 

Hardware considerations

TMP36 has only three connections:

  • Vcc
  • GND
  • Output

The TMP36 sensor can measure temperatures between -40 °C and +125 °C and provides an linear output voltage between 0.1 V and 1.7 V. At 0 °C, the sensor outputs 0.5 V. The output changes of 10 mV for each degree of temperature. So the maximum output voltage is

 

  image

 

This means that output of the sensor can be connected directly to the input of the MSP430's ADCs. Just to prevent any possible impedance mismatch between the TMP36 output and the ADC input, I added a 741 operational amplifier in buffer configuration

 

  image

 

The supply voltage of the sensor comes from the LTC3108 VOUT2. VOUT2 can be configured to output several voltage ranges by properly connecting input pins VS1 and VS2. In this case, LTC3108 is configured to output 5V.

To save energy, all the logic driven by the 5V supply voltage is switched on request. The MSP430 drives the LTC3108's VOUT2_EN pin to switch on and off the 5V output.

The temperature sensor (as well all other sensors on the board) are switched on when required by a ULN2003LV integrated circuit

In the next picture, the 5V supply voltage path is highlighted in red color. The 5V is output by the LTC3108 and is connected to the COM+ pin of the ULN2003LV. When a sensor needs to be switched on, the MSP430 drives high the corresponding output pin (see yellow path). When a ULN2003LV's input pin is high, the corresponding relay closes and this let current flow from 5V to ground thus powering up the sensor. ULN2003LV minimum input voltage is 1.8V, so no extra circuitry is required

 

  image

 

It's very easy to connect the sensor to the MSP430 demo board. I placed on a breadboard the TMP36 sensor and the 0.1 µF capacitor. This capacitor must be placed between Vcc and ground and is required in order to improve the precision of readings

 

Software

To read output from TMP36, I first configured the MSP430's ADC by means of Grace

 

image

 

I'm going to perform a single acquisition of the ADC value, so the clock source and the sample&hold time is not important. I will use a resolution of 10 bits, because this resolution gives me steps of

image


which is sufficient for this type of application

 

To read the ADC value, I use the Texas Instruments driverlib library, which provides a convenient way of accessing the MSP430 peripheral. This library basically wraps the access to peripheral registers in human-readable C functions.

For example, to start an ADC acquisition, instead of


    ADC10CTL0 |= ADC10ENC + ADC10SC;        // Sampling and conversion start

 

I will write


     ADC12_B_startConversion(ADC12_B_BASE,

           ADC12_B_MEMORY_0,

           ADC12_B_SINGLECHANNEL);

 

which, in my opinion, is much more clear

To save energy, I will not loop waiting for the conversion being completed, but I will instead put the MCU in sleep

 

    __bis_SR_register(LPM0_bits + GIE);    // LPM0, ADC12_ISR will force exit

 

and will read the ADC value in the ADC12_ISR function

extern void SENSORS_SetADCReading(uint16_t memory, uint16_t value);

 

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)

#pragma vector=ADC12_VECTOR

__interrupt

#elif defined(__GNUC__)

__attribute__((interrupt(ADC12_VECTOR)))

#endif

void ADC12_ISR(void)

{

    uint16_t value;

 

    switch(__even_in_range(ADC12IV,12))

    {

    case  0: break;                        // Vector 0:  No interrupt

    case  2: break;                        // Vector 2:  ADC12BMEMx Overflow

    case  4: break;                        // Vector 4:  Conversion time overflow

    case  6: break;                        // Vector 6:  ADC12BHI

    case  8: break;                        // Vector 8:  ADC12BLO

    case 10: break;                        // Vector 10: ADC12BIN

    case 12:                                // Vector 12: ADC12BMEM0 Interrupt

        value = ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);

        SENSORS_SENSORS_SetADCReading(ADC12_B_MEMORY_0, value);

__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU

        break;                              // Clear CPUOFF bit from 0(SR)

    ...

    }

}

 

The SENSORS_SetADCReading function simply set a global variable

 

uint16_t SENSORS_Adc;

 

void SENSORS_SetADCReading(uint16_t memory, uint16_t value)

{

      SENSORS_Adc = value;

}

 

This said, the function that reads the ADC value can be written as follow

 

uint16_t SENSORS_AnalogRead(uint16_t memory)

{

    // Base address of ADC12B Module. Start the conversion into memory buffer 0

    // Use the single-channel, single-conversion mode

ADC12_B_startConversion(ADC12_B_BASE,

memory,

ADC12_B_SINGLECHANNEL);

    __bis_SR_register(LPM0_bits + GIE);    // LPM0, ADC12_B_ISR will force exit

 

    return SENSORS_Adc;

}

 

The sensor output voltage has linear relationship with the temperature

image 

The formula to convert ADC reading into degrees Celsius is

image

where

  • "°C" is the temperature value in degrees Celsius
  • "ADC reading" is value returned by the AD converter
  • "ADC precision" is the ADC reference voltage (2.0 V) divided by the maximum value returned by the AD converter (1024). This resulting value is 2,0 V / 1024 = 0.00195
  • "output @ 0 °C" is the output voltage when the sensor is at 0°C
  • "voltage step per °C" is the variation in the voltage output when temperature changes of 1 degree °C. According to TMP36 datasheet, this value is 10 mV / °C

The final function for reading temperature value can be written as

#define SENSORS_ADC_V_MAX        2.0f

#define SENSORS_ADC_STEPS_MAX    1024

 

#define SENSORS_TMP36_V_0DEG    0.5f

#define SENSORS_TMP36_V_PER_DEG  0.010f

 

void SENSORS_ReadTemp()

{

  float val = SENSORS_AnalogRead(ADC12_B_MEMORY_0);

  val = (val * SENSORS_ADC_VMAX) / SENSORS_ADC_STEPS_MAX;

  val = (val - SENSORS_TMP36_V_0DEG) / SENSORS_TMP36_V_PER_DEG;

 

SENSORS_Data.temperature = val;

}

  • Sign in to reply
  • DAB
    DAB over 10 years ago

    Nice update.

     

    I have been meaning to dig into Grace, but you make it look simple enough that even I might be able to use it.

     

    Thanks

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube