About ST
Products
Applications
Support
Buy
News & Events
ST Worldwide
Contact Us
Login
Application Notes
|
STM32F10xxx ADC application examples
Application Note
Format:
(96 kb)
or
(14 kb)
Last Updated: 15/06/2007
Pages: 10
Related Datasheets
Medium-density access line, ARM-based 32-bit MCU with 32 to 128 KB Flash, six timers, ADC and 7 communication interfaces
Medium-density performance line ARM-based 32-bit MCU with 32 to 128 KB Flash, USB, CAN, 7 timers, 2 ADCs, 9 communication interfaces
Raw Ascii Text
- (
Hide
)
(Unformatted textual content of the document used by search engines)
AN2558 Application note
STM32F10xxx ADC application examples
Introduction
This application note is intended to provide practical application examples of the STM32F10xxx ADC peripheral use. This document, its associated firmware, and other such application notes are written to accompany the STM32F10xxx firmware library. These are available for download from the STMicroelectronics microcontrollers website: www.st.com.
June 2007
Rev 1
1/10
www.st.com
Contents
AN2558 - Application note
Contents
1 STM32F10xxx ADC-converted data transfer using DMA . . . . . . . . . . . . 3
1.1 1.2 1.3 1.4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Firmware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 C onclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2
ADC conversion with auto-injected conversion on external trigger . . 4
2.1 2.2 2.3 2.4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Firmware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 C onclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3
ADC analog watchdog guard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1 3.2 3.3 3.4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Firmware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 C onclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4
ADC conversion triggered by an EXTI line in discontinuous mode . . . 6
4.1 4.2 4.3 4.4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Firmware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 C onclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5
Regular simultaneous conversion in dual ADC mode . . . . . . . . . . . . . . 8
5.1 5.2 5.3 5.4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Firmware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 C onclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2/10
AN2558 - Application note
STM32F10xxx ADC-converted data transfer using DMA
1
STM32F10xxx ADC-converted data transfer using DMA
Overview
This section describes how to transfer a converted ADC_IN input channel value using DMA.
1.1
1.2
Hardware description
Figure 1 shows a typical connection between the STM32F10xxx ADC_IN14 and a potentiometer. Figure 1. STM32F10xxx ADC_IN14 interface
3.3 V ADC_IN14 10 K
STM32F10xxx
ai14320
1.3
Firmware description
The provided firmware includes the ADC driver that supports all ADC functionalities through a set of functions. DMA Channel1 is configured to transfer the converted value to the ADC_ConvertedValue variable each time ADC_IN14 is converted. The transfer is made continuous by enabling the circular mode on the used DMA Channel. ADC_IN14 is configured to be converted continuously. This firmware is provided as ADC example 1 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website.
1.4
Conclusion
The use of DMA facilitates the transfer of data from the ADC to the memory in terms of code size and time. The DMA circular mode also allows continuous data transfer without any user intervention.
3/10
ADC conversion on external trigger with auto-injected conversion
AN2558 - Application note
2
ADC conversion on external trigger with autoinjected conversion
Overview
This section describes how to set an ADC regular conversion triggered by an external event followed by an auto-injected conversion.
2.1
2.2
Hardware description
Figure 2 shows a typical connection between STM32F10xxx ADC_IN11 and ADC_IN14 and two external analog inputs (in the example, two potentiometers). Figure 2. STM32F10xxx ADC_IN11 and ADC_IN14 conversion
3.3 V ADC_IN14 10 K
3.3 V ADC_IN11 10 K
STM32F10xxx
ai14321
2.3
Firmware description
The provided firmware includes the ADC driver that supports all ADC functionalities through a set of functions. ADC1 is configured to convert ADC_IN14 as a regular channel and ADC_IN11 as an injected channel. The regular conversion is triggered by the TIM1 CC1 signal and the autoinjected mode is enabled for the start of the injected channel conversion. The end of the injected conversion interrupt is enabled so as to ensure that the converted value is saved and pin PC6 is toggled in the ADC interrupt routine. The regular-channel converted values are transferred by means of DMA Channel1. Once 32 regular-channel values have been transferred, TIM1 is disabled in order not to trigger any new ADC regular conversion and, so, no auto-injected conversion is done. This firmware is provided as ADC example 2 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website.
2.4
Conclusion
There are several ways of starting regular and injected conversions in the STM32F10xxx ADC. This gives the user a large choice when implementing any application.
4/10
AN2558 - Application note
ADC analog watchdog guard
3
3.1
ADC analog watchdog guard
Overview
This section describes how to set an ADC analog watchdog to guard an ADC_IN input channel.
3.2
Hardware description
Figure 3 shows a typical connection between the STM32F10xxx ADC_IN14 and a potentiometer. Figure 3. STM32F10xxx ADC_IN14 interface
3.3 V ADC_IN14 10 K
STM32F10xxx
ai14320
3.3
Firmware description
The provided firmware includes the ADC driver that supports all ADC communications through a set of functions. ADC1 is configured to convert regular channel ADC_IN14 continuously. Both upper and lower analog watchdog thresholds are configured and enabled to guard only ADC_IN14. The analog watchdog event is enabled to generate an ADC interrupt within the program, which toggles the PC6 pin in the routine. Each time the converted value passes the upper or lower threshold, the interrupt is generated and the pin toggles continuously since the value is no longer in the defined range, limited by the defined thresholds. This firmware is provided as ADC example 3 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website.
3.4
Conclusion
The STM32F10xxx ADC provides an analog watchdog to guard any/all ADC_IN inputs when the converted value passes a defined, upper or lower threshold.
5/10
ADC conversion triggered by an EXTI line in discontinuous mode
AN2558 - Application note
4
ADC conversion triggered by an EXTI line in discontinuous mode
Overview
This section describes how to trigger an ADC regular and injected group conversion by EXTI lines with discontinuous mode enabled for a regular group.
4.1
4.2
Hardware description
Figure 4 shows a typical connection of the STM32F10xxx ADC_IN4, ADC_IN10, ADC_IN11 and ADC_IN14 to four potentiometers. The PE11 and PE15 pins are connected to two pushbuttons to generate the rising edge to start ADC conversion. Figure 4. STM32F10xxx ADC_IN4, ADC_IN10, ADC_IN11 and ADC_IN14 connection
3.3 V 4.7 K 3.3 V 100 nF PE11 3.3 V 100 ADC_IN14 10 K 3.3 V ADC_IN10 3.3 V PE15 100 nF ADC_IN11 10 K 10 K ADC_IN4 10 K
3.3 V 4.7 K
STM32F10xxx
100
ai14322
6/10
AN2558 - Application note
ADC conversion triggered by an EXTI line in discontinuous mode
4.3
Firmware description
The provided firmware includes the ADC driver that supports all ADC functionalities through a set of functions. ADC_IN4 and ADC_IN14 are configured as regular channels with a start of conversion triggered by EXTI line11 mapped to PE11. ADC_IN10 and ADC_IN11 are configured as injected channels with a start of conversion triggered by EXTI line15 mapped to PE15. Discontinuous mode is enabled for regular channel with a number of one channel on each trigger. DMA Channel1 is configured to transfer 64 pieces of data from the ADC1 DR register to ADC_RegularConvertedValueTab. The ADC1 end of injected conversion interrupt is enabled. On each rising edge detected on PE11, one regular channel is converted and its value is transferred by DMA to the ADC_RegularConvertedValueTab buffer. On each rising edge detected on PE15, both injected channels are converted and on the ADC1 interrupt routine, both converted values are stored into the ADC_InjectedConvertedValueTab buffer. This firmware is provided as ADC example 4 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website.
4.4
Conclusion
The STM32F10xxx ADC offers a new way of starting conversion for regular and injected group channels using EXTI lines. The discontinuous mode is also available for both regular and injected conversions to allow the conversion of a specified number of channels as a subgroup of the total number of channels to be converted.
7/10
Regular simultaneous conversion in dual ADC mode
AN2558 - Application note
5
5.1
Regular simultaneous conversion in dual ADC mode
Overview
This section describes how to set the regular simultaneous dual mode with ADC1 and ADC2.
5.2
Hardware description
Figure 5 shows a typical connection between the STM32F10xxx ADC_IN10, ADC_IN11 and ADC_IN14 and three potentiometers. Figure 5. STM32F10xxx ADC_IN10, ADC_IN11 and ADC_IN14 connection
3.3 V ADC_IN14 10 K 3.3 V ADC_IN11 3.3 V ADC_IN10 10 K 10 K
STM32F10xxx
ai14323
5.3
Firmware description
The provided firmware includes the ADC driver that supports all ADC functionalities through a set of functions. ADC_IN14 and ADC_IN17 are configured as regular channels for ADC1. They are converted continuously with a software start of conversion. ADC_IN10 and ADC_IN11 are configured as regular channels for ADC2 and are converted continuously with a start of conversion synchronized to that of ADC1. DMA Channel1 is configured to transfer 16 pieces of 32-bit data from the ADC1 DR register to ADC_DualConvertedValueTab. Once the ADC1 software start is enabled, regular channel conversion begins simultaneously on both ADCs and completes after 16 conversions on each ADC. All converted values are transferred by DMA to the 32-bit data buffer ADC_DualConvertedValueTab that holds both ADC1 and ADC2 conversion results. This firmware is provided as the ADC example 5 of the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website.
5.4
Conclusion
The STM32F10xxx gives the user the possibility of converting two channels at the same time owing to the presence of two ADCs that can be synchronized to work in different dual modes such as the regular simultaneous mode.
8/10
AN2558 - Application note
Revision history
6
Revision history
Table 1.
Date 14-Jun-2007
Document revision history
Revision 1 Initial release. Changes
9/10
AN2558 - Application note
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 described 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. UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER'S OWN RISK.
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.
2007 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 - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com
10/10
Document Number: 13592