S. Marsanne

STM32 ADC Overview

Discussion created by S. Marsanne Employee on Dec 17, 2016
Latest reply on Feb 14, 2018 by Jiri Bilek

Analog to Digital Converter (ADC) is one of the common peripheral in MCU and would be classified in the Analog category.

Choosing, Using, Configuring ADC requires awareness of many parameters which will affect the quality of the result.

Here is a quick list of ADC related topics which might guide users.

 

1. All ADC will convert an analog respective to the ADC supply reference voltage. Depending on STM32 packages, there would be specific supply pin (in richer pincount packages), or shared with an MCU supply voltage internally otherwise. Usually the min value is Ground and the max value match the ADC supply voltage.

 

2. There are many types of ADCs, the most pervasive one is the SAR adc, and some specific STM32 the sigma delta ADC is also available.

 

SAR ADCs (Successive Approximation ADC): the analog input is captured through a switched charging "sample and hold" capacitor, then a binary search method is used to find out the LSB converted value.

The more bits needed, the longer it will take. The digital result is such that the max value is the supply voltage of the ADC and the min value is 0 as ground (in absolute single ended analog input which is the most common one)

Some ADC can measure in differential mode: Instead of measuring from Ground as reference (absolute), it is relative between 2 analog input signals. This yields a signed value and usually provide more accurate and less application noise susceptible result. This scheme is used in many sensors using Wheatstone bridge to factor out some dependencies such as temperature.

 

Sigma Delta type ADC (such as STM32F3 series): It is a different method to get a analog converted value and has its own merits and drawbacks. Get the right ADC best matching your needs.

 

In the following points, we will focus on the SAR ADC which is the most commonly found.

 

3. STM32 ADC have analog input multiplexer to be able to measure analog signals from multiple package pins sequentially.

Some ADC can also measure MCU internal signals such as its chip temperature or its supply voltage (which helps convert the LSB ADC value in milivolts with precision).

 

4. Most ADC can run 1 Msps (1 mega sample per second). When there are more than one ADC available, it is possible to let ADCs co-work on the same channel to increase further the sampling rate.

 

5. ADC has 2 types of inputs, injected and regular channel.

Injected channels have their unique result data register, and they have higher priority with regular channels.

Normal channels share the same data register, so it needed to scan automatically multiple channels, DMA plumbing is needed.

Both type of channel (analog input) can be mesured manually in one shot mode, or automatically sweeped through.

 

6. The conversion time for one channel depends on how to program the sample and hold time, and how many bits are needed. Of course, the right reference ADC clock frequency must be programmed for good results.

 

7. ADC conversion can be triggered by internal signals or GPIO pin (one specific pin for injected, one other for normal). This is very useful when trying to implement something similar to oscilloscope. Use GPIO to be able to probe and debug

 

8. ADC has Analog Watchdog detector, to detect when the analog voltage goes above and/or below a defined limit.

 

9. Depending on the analog input signal being static or dynamic, adjust the sampling frequency. Make sure the ADC sampling rate on a channel is 2 or 3 times faster than the dynamic analog signal (if sine wave).

 

10. The sample and hold time period will result in the analog application line to be terminated by a RC charge, make sure the output impedence of the coming analog signal is low. Monitor the line on an oscillocope to make sure there is no noticeable voltage drops at ADC sampling rate.

 

11. One of the oldest handy use of an ADC was an analog keyboard... if your TV or monitor or washing machine has push buttons, it's probably using an analog keyboard: It is a way to connect 5 or more pins on a single GPIO, as long as only one key is pushed as one time. For a rockswitch (5 way switch + select + user button), 2 Analog inputs will enable diagonal push. The max number of keys depends on the resistance tolerance and ADC precision. With VIL (detecting a logical zero on the pin), adusting the resistor ladder of the keyboard could enable one of the key to go to ground and wake up a sleeping core.

Analog Keyboards

12. With a little bit of DIY there is another way to convert an analog to digital input, using an external RC low pass filter connected to a GPIO wth analog comparator function. Discharge the cap by using GPIO as push-pull low level, then turn it as analog comparator input mode and count the time it takes to reach the comparator value using a timer. This time will be proportional to the analog input voltage. This would be similar to the ramp compare ADC done in discrete fashion.

 

13. Some STM32 ADC have support for Differential inputs, which enables higher end analog measurement techniques, such as cancelling out an environmental parameter: noise on the pcb line, temperature dependency of a sensor using a classical wheatstone bridge, etc...

Outcomes