cancel
Showing results for 
Search instead for 
Did you mean: 

How to choose ADC clock frequency.

GHARI.1
Associate II

Hi,

My project goal to digitize a sine wave of frequency 20KHz and voltage varying from 0V to 3.3V using ADC of STM32H743ZI. I am using NUCLEO-H743ZI2.

My doubt is how to choose ADC clock frequency so that I would be able to digitize the signal with high accuracy?

How to choose the channel whether Direct channel or fast or slow?

Whether using Timmers is the best option or continous conversion using DMA is better option?

4 REPLIES 4
TDK
Guru

> My doubt is how to choose ADC clock frequency so that I would be able to digitize the signal with high accuracy?

ADC clock frequency is relatively low on the list of things to worry about when trying to improve accuracy, if it's even on there at all.

https://www.st.com/resource/en/application_note/cd00211314-how-to-get-the-best-adc-accuracy-in-stm32-microcontrollers-stmicroelectronics.pdf

> How to choose the channel whether Direct channel or fast or slow?

I suspect direct and fast channels will be more accurate that slow ones, but the datasheet doesn't say anything about this. Perhaps they are all equal.

> Whether using Timmers is the best option or continous conversion using DMA is better option?

If you're trying to capture 20kHz signals, DMA seems like the best choice. Using a timer to trigger sampling at a regular interval (say, 100k samples/sec), also seems like the best choice. After you've chosen an ADC clock and a sampling frequency, you should generally use the largest sampling interval possible.

Perhaps it would be useful to determine what amount of noise is tolerable to you, and decide if the STM32 can meet that goal. The datasheet lists effective number of bits for several scenarios.

If you feel a post has answered your question, please click "Accept as Solution".

Right now I am using a Timer to trigger ADC at 100ksamples/sec and storing the data in a array of size 10000.

In debug session when I observed the data there is lot of variation. It is a sine wave but from sample to sample there is lot of voltage variation.​

>How to debug whether 100ksamples/sec are stored in the array or not.​

>How to use DMA when using timers.

Initialize the array beforehand to some known value. Write the code such that it changes all 10000 values. Observe that all 10000 values change accordingly.
There should be ADC DMA examples in the relevant repository for your chip that you can follow.
If you feel a post has answered your question, please click "Accept as Solution".
Philippe Cherbonnel
ST Employee

Hello @GHARI.1​ ,

STM32H7 ADC frequency can be up to 3.6Msamples/sec (resolution 16 bits, fast sampling time), therefore to capture a signal at 20kHz should be feasible.

About ADC channels fast and slow: 

fast channels and direct channels have a lower input impedance, allowing higher sampling frequency.

On STM32H7 datasheet, you can refer to tables "ADC characteristics" and "Minimum sampling time vs RAIN".

About mode continuous:

Be careful to confusion between ADC mode continuous (from 1st trigger, conversions are performed one after each other, without delay) and ADC trigger periodic from timer (conversions are performed in unitary way at each trigger event)

If you are using conversion trigger from timer, do not use mode continuous (do use mode single instead).

For your application, the best choice is to use trigger from timer.

As mentionned by @TDK​ , there are examples in STM32H7 FW package:

Using data transfer by DMA:

...\Firmware\Projects\NUCLEO-H743ZI\Examples\ADC\ADC_DMA_Transfer\EWARM

Using ADC conversion trigger from timer:

...\Firmware\Projects\NUCLEO-H743ZI\Examples\ADC\ADC_DualModeInterleaved

About debug:

You can place an event generation in "HAL_ADC_ConvCpltCallback()" (GPIO toggle, variable increment, ...), so you will be able to monitor data transfer rate.

Best regards

Philippe