cancel
Showing results for 
Search instead for 
Did you mean: 

ADC sample rate

Ngai yuk kong
Associate II
Posted on May 04, 2018 at 07:47

Hi all,

I have seven adc channels to convert using STM32F051. I set the ADC to be triggered by timer 15. I also setup DMA to put all the converted results to a memory buffer and have a Transfer complete interrupt set. 

Here is the setting: 

Timer 15 using 100KHz

ADC set to complete whole sequence 

DMA in circular mode

Everything work except that when I toggle a I/O inside the DMA interrupt, I got the frequency around 5KHz.

Any direct correlation between this 5KHz with my timer 100KHz? The MCU specification has a diagram showing that during the conversion the timer trigger will be ignored until all the conversion is complete. Does it mean that there is no way to control the sampling rate????

Many thanks..

20 REPLIES 20
T J
Lead
Posted on May 04, 2018 at 08:16

There is several factors for the ADC timing.

ADC prescaler (don't use 1 or 2 even 4 may be noisy)

ADC Sample rate (don't use fastest or second fastest for better stability), you can test this.

DMA channels is 7

Timer to trigger initial sample/DMA system.  ( should be set to 1KHz, then go faster if you need to)

So the timer should be set to more than 7x less than the sample rate.

5KHz will be 7x your current sample rate.

ie 1/35KHz shows you have a 28uS conversion rate per channel.

Ngai yuk kong
Associate II
Posted on May 04, 2018 at 08:31

Sorry bro I still cannot understand.

i found something strange as well....when i set my timer to 1Hz, I suppose the DMA interrupt will follow this timer frequency.....however, the result shows that my pin toggling inside the DMA interrupt can be up to 60Hz.................

Ngai yuk kong
Associate II
Posted on May 04, 2018 at 09:28

I understand that the DMA is not able to catch up the very high timer speed since the operation involves channel switching. My original question is just want to know if there any way to calculate the actual sampling frequency. The very reason I want to know is, I need to sample AC input voltage and calculate the rms voltage but my colleague keeps saying it will not be accurate to sample using this method. He is using Microchip and has several ADC cores to sample in parallel. For STM32F051, there is only one ADC core and we need to switch channels. 

If you guys have good method to sample half period AC voltage (the negative side of sine wave will flip to positive) and then do the rms calculation please share with me as well. Right now I am reading seven channels in one scan using DMA interrupt and timer trigger.

Many thanks to all of you, even for spending time reading my questions...

T J
Lead
Posted on May 04, 2018 at 09:52

Did you use the cube ?

in the cube, you can select the ADC speed from 1.5cycles to 239.5 cycles. I would start at 13.5 @14Mhz is approx 1uS per conversion, it may be unstable, see how you go.

I think you could select 1 channel and use the DMA read it continuously into a circular buffer of your calculation length.

for the best RMS reading

seems there is no clock selection in the 'F051  you have a 14MHz clock.

AvaTar
Lead
Posted on May 04, 2018 at 10:45

I have total 7 ADC inputs have to be served.

Usually, one would configure DMA to create a TC interrupt after each sequence, i.e. 7 values in your case.

It is probably useful to show the relevant code here.

Posted on May 04, 2018 at 08:48

My fault for the 60Hz, it is due to my wrong setting in the 16 bit register.........sorry about that

Posted on May 04, 2018 at 08:51

Are you sure that your core clock is properly set up to the frequency you intended ?

I often check this with GPIO toggle in the SysTick interrupt, set at (supposedly) 1kHz.

Posted on May 04, 2018 at 08:54

Yes, I am sure. I did check the timer frequency by enabling the interrupt and toggle pin inside..........

Posted on May 04, 2018 at 09:55

I am not using Cube. I have total 7 ADC inputs have to be served. The fastest ADC clock I can set is Fclk/2 inside ADC_CFGR2 register.