Home

STM32L1x temperature sensor example

image

Contents

1. July 2013 2 AN3964 y Rm Application note STM32L1x temperature sensor example Introduction This application note describes a method of implementing a simple application for temperature measurement using the STM32L DISCOVERY and 32L152CDISCOVERY boards The solution described in this document uses the integrated temperature sensor of the STM32L1x microcontroller The factory or user calibration method is described to improve the accuracy of the temperature sensor The demonstration application does not require any additional hardware Once the STM32L DISCOVERY and 32L152CDISCOVERY are updated with the associated firmware and is powered up through a USB cable connected to the host PC the application is ready to display the temperature of the STM32L1x microcontroller The temperature sensor example firmware is included in the STM32L 1x discovery firmware package STSW STM32072 available from http www st com Reference documents e SIM32L DISCOVERY and 32L152CDISCOVERY user manual UM1079 e Getting started with software development toolchains for the STM32L DISCOVERY and 32L152CDISCOVERY boards UM1451 e SIM32L1x current consumption measurement and touch sensing demonstration AN3413 e Ultra low power STM32L15xx6 8 B datasheet e Ultra low power STM32L151xC and STM32L152xC datasheet e Ultra low power STM32L151xD and STM32L152xD datasheet e Ultra low power STM32L162xD datasheet e SIM32L100xx STM32L151xx STM32L152xx and
2. depending on the selected power saving mode When the device enters Stop mode the HSI oscillator is switched OFF and the LSE crystal oscillator feeds the RTC until the device is woken up by an external event RTC wakeup or USER button pushed When exiting Stop mode the MCU switches back the system clock from the defailt MSI oscillator to the HSI oscillator DoclD022101 Rev 3 11 14 Conclusion AN3964 3 2 STM32L15x standard firmware library configuration The stm32H xx conf h file of the STM32L1x standard firmware library allows you to configure the library by enabling the peripheral functions used by the application The header files of the library modules are included in the stm32H xx conf h file as listed below e include stm32l1xx adc h e include stm32l1xx exti h e include stm32l1xx flash h e include stm32l1xx gpio h e include stm32l1xx syscfg h e include stm32l1xx lcd h e include stm32l1xx pwr h e include stm32l1xx rcc h e include stm32l1xx rtc h e include misc h The corresponding library modules must be included in the project for successful compilation and linking 4 Conclusion This application note shows how to use the internal temperature sensor embedded in your STM32L1x microcontroller The firmware example associated with this application note allows you to explore the temperature sensing capability of STM32L1x microcontrollers and at the same time demonstrate its ultra low power features It can
3. EXPRESSLY DESIGNATED BY ST AS BEING INTENDED FOR AUTOMOTIVE AUTOMOTIVE SAFETY OR MEDICAL INDUSTRY DOMAINS ACCORDING TO ST PRODUCT DESIGN SPECIFICATIONS PRODUCTS FORMALLY ESCC QML OR JAN QUALIFIED ARE DEEMED SUITABLE FOR USE IN AEROSPACE BY THE CORRESPONDING GOVERNMENTAL AGENCY Resale of ST products with provisions different from the statements and or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever any liability of ST ST and the ST logo are trademarks or registered trademarks of ST in various countries Information in this document supersedes and replaces all information previously supplied The ST logo is a registered trademark of STMicroelectronics All other names are the property of their respective owners 2013 STMicroelectronics All rights reserved STMicroelectronics group of companies Australia Belgium Brazil Canada China Czech Republic Finland France Germany Hong Kong India Israel Italy Japan Malaysia Malta Morocco Philippines Singapore Spain Sweden Switzerland United Kingdom United States of America www st com 14 14 DocID022101 Rev 3 ky
4. STM32L162xx advanced ARM based 32 bit MCUs reference manual RMO0038 The above documents are available at http www st com Table 1 Application products and firmware Part numbers and product categories MCU evaluation tools STM32L DISCOVERY 32L152CDISCOVERY MCU software STSW STM32072 DoclD022101 Rev 3 1 14 www st com Contents AN3964 Contents 1 Application overview es 5 1 1 Temperature sensor llle 5 1 2 Temperature measurement and data processing 005 5 1 3 Application example description llle 6 2 Getting started 0 0 es 8 2 1 Setting up the board 1 ee eens 8 2 2 Using the demonstration application 0 0 00 cee eee 8 2 2 1 Temperature sensor calibration llle 8 2 3 Estimation of temperature sensor engineering tolerance 10 3 Software description llllllllleelrer 11 3 1 STM32L1x peripherals used by the application 11 3 2 STMS32L15x standard firmware library configuration 12 4 CONGCIUSION PCT rcrRm 12 5 Revision history ousuna cekisiRE TE E euERE E KEEN RES DETEEES EE in 13 2 4 DoclD022101 Rev 3 Ly AN3964 List of tables List of tables Table 1 Application products and firmware n aoaaa aaaea aa eee ees 1 Table 2 Document revision history llle hrs 13 ky DocID022101 Rev 3 3 14 List of figures AN3964 L
5. be used as a starting point for your own development 12 14 DocID022101 Rev 3 Ly AN3964 Revision history 5 Revision history Table 2 Document revision history eae ronson Changes 27 Sep 2011 Initial release Added 32L152CDISCOVERY and related information Addeed reference to STSW STM32072 firmware Replaced STM32L by STM32L1x in the whole document Updated memory address in Section 1 2 Temperature measurement 04 Jul 2013 D and data processing Updated Section 2 2 1 Temperature sensor calibration to add Section Temperature measurement on battery operated devices Changed reference voltage in Section 2 3 Estimation of temperature sensor engineering tolerance Updated Section Clocks 16 Jul 2013 Updated Table 1 Application products and firmware 3 DocID022101 Rev 3 13 14 AN3964 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics NV and its subsidiaries ST reserve the right to make changes corrections modifications or improvements to this document and the products and services described herein at any time without notice All ST products are sold pursuant to ST s terms and conditions of sale Purchasers are solely responsible for the choice selection and use of the ST products and services described herein and ST assumes no liability whatsoever relating to the choice selection or use of the ST products and services de
6. e STM32L 1 Discovery such a normalization is not needed and the sampled temperature data can be directly used to determine the temperature as described in Section 2 2 1 Temperature sensor calibration Application example description Every 2 seconds the application acquires 16 samples from the temperature sensor voltage The ADC raw data are filtered and averaged using an interquartile mean algorithm to reduce noise from the power supply system and the result is recalculated into standard units of temperature measurement C in this example The LCD display is updated every 2 seconds either by ADC raw data or by the current temperature value in degrees Celsius The user can switch between both temperature data representations by pressing the user button To demonstrate the low power capabilities of the STM32L 1x ultra low power microcontroller the CPU is switched to Stop mode with the RTC real time clock wake up set to 2 seconds within the time interval between temperature sensor data measurements The ADC data acquisition and data transfers are managed by direct memory access DMA while the CPU is in Low power Sleep mode The CPU is in Run mode at 16 MHz based on the HSI oscillator clock only during the initialization phase and during the data processing period DoclD022101 Rev 3 Ly AN3964 q Figure 1 Example LCD display ETT d Wri TLL Wii m fa 71 allaan LES F m a T ium gt a mm
7. e hot temperature pair as TC2 ValC2 Temp TC2 TC1 ValC2 ValC1 x ValTS ValC1 TC1 Using the factory calibration data the formula can be rewritten as follows Temp 80 TS CAL2 TS CAL1 x ValTS TS CAL1 30 DoclD022101 Rev 3 9 14 Getting started AN3964 2 3 10 14 Estimation of temperature sensor engineering tolerance The two point calibration method significantly improves the accuracy of the measurement as can be seen in Figure 2 The bias of the temperature measurement is mainly given by two sources the temperature margin of the calibration points and the linearity of the sensor Other sources of bias such as the ADC reference voltage margin can be effectively reduced It can be neglected for factory calibrated values measured with the 3 V 10 mV reference voltage The engineering tolerance of the temperature estimation is illustrated in Figure 2 where it is limited by the two boundary lines of the minimum biased values green and the maximum biased values blue The area between the calibration points has a constant tolerance with a slight increase of the tolerance outside For this reason the recommended position of the calibration points should be as close as possible to the maximum and minimum values of the measurement range DoclD022101 Rev 3 Ly AN3964 3 3 1 Software description Software description STM32L1x peripherals used by the application This application example uses the followi
8. ist of figures Figure 1 Example LCD display 0 0 ccc eee eee I n 7 Figure 2 Transfer characteristics of the temperature sensor 0000 0c eee eee 9 AN3964 1 1 1 Note 1 2 Application overview Application overview This section describes how the temperature sensor works and how the temperature measurement is performed by the STM32L1x microcontroller embedded on the STM32L DISCOVERY or 32L152CDISCOVERY A brief description of how the example temperature measurement application was implemented follows afterwards STM32L1xxDISCOVERY stands either for STM32L DISCOVERY or 32L152CDISCOVERY evaluation kit throughout the document Temperature sensor The temperature sensor integrated in the STM32L 1x microcontroller provides an analog output voltage proportional to the chip junction temperature of the device Please note that the temperature information provided by sensor is the thermal chip junction temperature actual temperature of semiconductor surface and may differ from the ambient temperature Please see section Thermal characteristics of product datasheet for more details The integrated temperature sensor provides reasonably linear characteristics with a deviation typically of 1 from linear asymptotic functions and a temperature range equal to that of the device 40 C to 85 C with a maximum junction temperature of 150 C The sensor provides good linearity but quite poor intercha
9. m M hel m em Fue al Prud mt TS Application overview L ri X i E 5B1 on ure on LE ETE Yo ELI Orr mak RE y e R27 MB963 B NM L n iil mm Gi 8 foe Nili iii T SUDER RE gps s SHE ux LE a DoclD022101 Rev 3 pp e C12 pc pcio pais paw pa BS Py paul ie NDS 2 7 14 Getting started AN3964 2 2 1 Note 2 2 2 2 1 8 14 Getting started Before getting started the firmware must be updated and hardware configured as described in the following sections Setting up the board Updating the firmware The STM32L1x program memory needs to be updated with the firmware associated with this application note For information on how to update the firmware please read the readme txt file in the project folder Used hardware components This application example uses the hardware components available on the STM32L1xxDISCOVERY boards the embedded peripherals of the STM32L1x microcontroller the 6 digit LCD glass display and the user push button No additional components are required STM32L1xxDISCOVERY hardware settings The Ipp jumper JP1 must be placed in the ON position Both jumpers on CN3 must be fitted to enable communication between the STM32L1x microcontroller and the ST Link debugging tool through the serial wire debug SWD interface All solder bridges must be i
10. n data are tested for validity when the example application is initialized If data is present in the memory it is used for temperature calculation Otherwise the user calibration data stored during user calibration in EEPROM memory area is tested and used instead If the user calibration data is not available either the default values are used for calculation The factory calibration or user calibration data provides good accuracy of the temperature measurement The use of the default calibration data which is statistically based on the typical characteristics of the temperature sensor may provide less accurate temperature estimations due to significant variations of the temperature sensor characteristics during the manufacturing process It is recommended to use either the factory calibration data or to perform the two point calibration of the temperature sensor which respects the individual characteristics of the temperature sensor to obtain reasonably accurate measurements Figure 2 Transfer characteristics of the temperature sensor gt E o D is gt Y Temperature K MS31894V1 The temperature can be evaluated from the digital value ValTS sampled by the ADC using linear approximation It can be applied if the coordinates of two calibration points C1 and C2 are known as shown in Figure 2 The current temperature can be evaluated as follows where the cold temperature coordinate pair is designated as TC1 ValC1 and th
11. n their default state as described in UM1079 Using the demonstration application It is very easy to start using the demonstration firmware When powered up the temperature sensor application example first displays a welcome message before immediately displaying the current temperature in degrees Celsius with a 2 second refresh rate When the User button is pressed once the display shows the mean value of an array of 16 samples acquired by the ADC One more press of the User button toggles between displaying the current temperature in degrees Celsius or the averaged value The averaged value can be used later as a calibration point with a known temperature to improve overall accuracy of the temperature measurements Temperature sensor calibration The temperature sensor calibration data are stored during the manufacturing process in the protected memory area from where the user can read it and use it to improve the accuracy of the temperature measurements The two point calibration data is measured during production e At ambient temperature 30 C 5 C T8 CAL1 e Athot temperature 110 C 5 C TS CAL2 Refer to the product datasheet for the memory address where calibration data are stored DoclD022101 Rev 3 Ly AN3964 3 Getting started The temperature sensor calibration data is a 12 bit unsigned number stored in 2 bytes acquired by the STM32L1x ADC with a 3 V 10 mV reference voltage The factory calibratio
12. nal voltage reference Vperint The value sampled by the ADC Val_Vperint on ADC_IN17 internal reference input can be expressed by the following formula V 12 REFINT V REFINTX Vmgr VneriNT X 4096 VppA Val V The accurate embedded internal reference voltage VngriwT is individually sampled by the ADC and the converted value for each device Val VnpgriNT caL is stored during the manufacturing process in the protected memory area at address VREFINT CAL specified in the product datasheet The internal reference voltage calibration data is a 12 bit unsigned number right aligned bits stored in 2 bytes acquired by the STM32L1x ADC referenced to VVREF MEAS REF V 0 01V The total accuracy of the factory measured calibration data is then provided with an accuracy of 5 mV refer to the datasheet for more details We can determine the actual Vppa voltage by using the formula above as follows V 3x Val_V DDA REFINT CAL V8 VgErFINT The temperature sensor data ValTS bat are sampled with the ADC scale referenced to the actual Vppa value determined at the previous steps Since the temperature sensor factory calibration data are acquired with the ADC scale set to 3 V we need to normalize ValTS bat to get the temperature sensor data ValTS as it would be acquired with ADC scale set to 3 V ValTS bat can be normalized by using the formula below If the ADC is referenced to the 3 V power supply which is the case of th
13. ng STM32L1x peripherals with the settings described below For more information please refer to the STM32L151xx datasheet Analog to digital converter ADC The ADC performs analog to digital conversions of the internal reference voltage 4 samples and of the temperature sensor voltage 16 samples driven by DMA e ADC resolution 12 bit e ADC conversion mode Scan mode driven by DMA e ADC sampling time 384 cycles SysTick timer The SysTick timer is used only to generate the delay needed for display refresh and is disabled during temperature measurements General purpose inputs outputs GPIOs Ports C and E are connected to the User push button and the LEDs e PB1 is set as an input floating pin with interrupt connected to User push button e PB green LD3 and PB6 blue LD4 are set as an output push pull e During low power modes I Os are placed in analog input mode to reduce power consumption except for a few pins related to the hardware interface PB7 green LD3 and PB6 blue LD4 It means that all Schmitt triggers on unused standard I O pins are disabled to reduce power consumption LCD controller The several functions available in the firmware library for the liquid crystal display LCD are used to initialize clear display strings and scroll messages needed in the application code Clocks The high speed internal HSI RC oscillator is selected as the main clock source The application manages the peripheral clocks
14. ngeability and must be calibrated to obtain good overall accuracy If the application is designed to only measure the relative temperature variations the temperature sensor does not need to be calibrated Temperature measurement and data processing The temperature sensor is internally connected to Channel 16 ADC IN16 of the ADC analog to digital converter in the STM32L1x and is used to sample and convert the temperature sensor output voltage The raw ADC data must be further processed to display the temperature in a standardized unit of measurement Celsius Farenheit or Kelvin The ADC reference voltage Vppa Vref is connected to the 3 V Vpp power supply of the STM32L1xxDISCOVERY boards If the Vpp value is not accurately known as in case of battery operated applications it must be measured to obtain a correct overall ADC conversion range see below section for details Temperature measurement on battery operated devices The power supply voltage applied to the microcontroller is subject to change on devices directly powered from a battery The value converted by the ADC follows the drift of the battery voltage if the ADC reference voltage is tied to Vppa which is the case for devices in low pin count packages The supply voltage needs to be known to compensate for such voltage drift The actual supply voltage VppA can be determined by using the embedded DoclD022101 Rev 3 5 14 Application overview AN3964 1 3 6 14 inter
15. scribed herein No license express or implied by estoppel or otherwise to any intellectual property rights is granted under this document If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION OR INFRINGEMENT OF ANY PATENT COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT ST PRODUCTS ARE NOT AUTHORIZED FOR USE IN WEAPONS NOR ARE ST PRODUCTS DESIGNED OR AUTHORIZED FOR USE IN A SAFETY CRITICAL APPLICATIONS SUCH AS LIFE SUPPORTING ACTIVE IMPLANTED DEVICES OR SYSTEMS WITH PRODUCT FUNCTIONAL SAFETY REQUIREMENTS B AERONAUTIC APPLICATIONS C AUTOMOTIVE APPLICATIONS OR ENVIRONMENTS AND OR D AEROSPACE APPLICATIONS OR ENVIRONMENTS WHERE ST PRODUCTS ARE NOT DESIGNED FOR SUCH USE THE PURCHASER SHALL USE PRODUCTS AT PURCHASER S SOLE RISK EVEN IF ST HAS BEEN INFORMED IN WRITING OF SUCH USAGE UNLESS A PRODUCT IS

Download Pdf Manuals

image

Related Search

Related Contents

アイディS D200S0 取扱説明書  Manuel d`utilisation rapide  liteCam GAME GUIDE  Parmi nos nouveautés :  user manual in PDF  Panasonic TH-65PB1U Operating Instructions  Tektronix 11402A User's Manual  「取扱説明書」 35RP2シリーズ (20070701-H007)  Hama ANT1703BK  

Copyright © All rights reserved.
Failed to retrieve file