# ADC conversion Time/Frequency Calculation in STM32

I have already covered How to use ADC in STM32. None of those tutorials actually covered the precise way to measure the conversion time or frequency for the ADC. Today in this tutorial, we will cover How to measure ADC conversion Time or conversion Frequency.

This tutorial will be divided into two halves. I will demonstrate how to utilize the datasheet to do these calculations. The first half of the tutorial will cover the STM32F103C8 controller, and the second half will cover STM32F446RE.
But this is not specific to these two microcontrollers. If you read everything carefully, you can implement the same logic for whatever series of microcontroller you have.

Some of the important ADC features of STM32 F1 series, from the calculation point of view, are listed below

• 12 BIT Resolution. This is fixed, and can’t be changed.
• ADC clock is derived from the APB2 Clock. And using the prescalar, we can further control the ADC clock
• MAX ADC Clock can be 14 MHz

Below is the picture from the reference manual of F103 controller.

It shows that the ADC Conversion Time = Sampling Time + 12.5 Cycles. Here Sampling Time is something that you can choose during the setup in the CubeMX. Below is the modified formula to do this calculation

The formula mentioned above is the same, but little better representation of what’s there in the reference manual. See the example below

I want the conversion time to be of 17 microseconds. It’s not a random time, this is the requirement for the internal Temp sensor to work.
We need to select the values of Sampling Time and ADC Clock in such a way, so as to get this 17 microseconds of Conversion Time.
There can be many possibilities for doing this, and one of them is if we select the Sampling Time of 71.5 CYCLES along with the ADC CLOCK of 5 MHz
(71.5 + 12.5)/14MHz = 17 us

In the similar way, the Conversion frequency can be calculated by reversing the formula mentioned above

With the same setup of Sampling time (71.5) and same ADC Clock (14 MHz), the Conversion Frequency would be around 59 KHz.

Some of the ADC Key points from the Reference manual of F446RE are as follows:

• 12-bit, 10-bit, 8-bit or 6-bit configurable resolution
• ADC Sampling Time changes based on the resolution Selected
• ADC Clock is derived from the APB2 clock, and can be configured using the prescalar

F446RE reference manual also have a formula to calculate the Conversion time and that is as shown below

I have modified this a bit in order for you to understand it, and the modified formula to calculate the conversion time is given below

Here, Cycles depends on the resolution you select for the ADC

• For 12 bit Resolution CYCLES = 12
• For 10 bit Resolution CYCLES = 10
• For 6 bit Resolution CYCLES = 6

The rest of the variables, like Sampling Time, and ADC CLOCK are configurable during the setup.

For eg:- Let’s say I want the ADC conversion time of 10 microseconds, for the Temperature Sensor. Here is the setup I an do for the same

• Keep the APB2 CLOCK at 50 MHz
• I am using 12 bit Resolution for this purpose, so the Cycles = 12
• Use the prescalar as 4. This is bring the ADC CLOCK to 12.5 MHz
• Use the Sampling Time of 112 CYCLES.
• Now conversion Time = (112 + 12) / 12.5 MHz = 9.9 us

The above example is just one of the combinations of many, that you can do for the same conversion time.

The same setup would also result in Conversion Frequency of 1/10 us = 100 KHz

You can apply the same Logic to any other STM32 controller you have. Just remember to look for the formula in the datasheet or the reference manual.

Subscribe
Notify of Inline Feedbacks