cancel
Showing results for 
Search instead for 
Did you mean: 

sample rate using DMA, ADC and Timer

LSoll.1
Associate II

Hi, I need to sample a signal at a frequency of 10kHz. To avoid the use of the microprocessor I thought of doing it using a 10kHz Timer that triggers the ADC conversion on its falling edge, in addition, I need the ADC read value to be transferred via DMA to an array of 10 positions (HAL_ADC_Start_DMA( &hadc1, adc1_array, 10)).

I am using the HAL_ADC_ConvCpltCallback() function to toggle an output pin to measure how often the DMA is transferring data.

The problem is that I am measuring a frequency of 1kHz (10 times lower), but if I change the length of the array to 1 (HAL_ADC_Start_DMA(&hadc1, adc1_array, 1)) I get the frequency of 10 kHz.

So the conversions run every 10kHz and am I using the wrong function to measure it (HAL_ADC_ConvCpltCallback()) or does the frequency actually depend on the length of the array I need to fill?

Thanks!!

7 REPLIES 7
Piranha
Chief II

The ADC is sampling with a 10 kHz, but the callback is made when the data array is filled.

LSoll.1
Associate II

Hi!!

Good, I understand. And how can I make the array fill at the same frequency? I don't understand how it can take so long for the DMA to fill the array.

I need to use some function that tells me when the array was filled after each ADC trigger signal (I thought this would be the correct function HAL_ADC_ConvCpltCallback())

TDK
Guru

The setting should be in ADC parameters. Is scan conversion mode enabled?

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

Yes, scan mode is enabled.

I attach the main.c, the msp.c and the ADC configuration.

If you need more information, please tell me.

Thanks!!

Piranha
Chief II

The ADC hardware definitely can issue an interrupt after each conversion is complete and one can use ADC interrupts and DMA simultaneously, but I'm not sure if this usage scenario is supported by HAL/Cube broken bloatware.

S.Ma
Principal

Step 1, use timer to generate the adc start one conversion signal at 10khz as output compare pin. Check with oscilloscopd that all works.

Step 2, connect the signal to the adc trigger pin and use it to kick one adc conversion.

Step 3, once all ok, use internal events between timer and adc to free the 2 pins.

LSoll.1
Associate II

Hello, sorry for the delay, I was absent for a few days.

I tried setting the ADC to perform a conversion with the external pin, set the timer to a frequency of 20Hz and within the HAL_ADC_ConvCpltCallback() function it toggled a pin. With the oscilloscope I checked the frequencies and indeed the PWM was 20Hz and the pin which toggled inside HAL_ADC_ConvCpltCallback() had a frequency of 10Hz (half that due to using the rising edge). The problem is when I configure the DMA, the frequency is now reduced to half and I don't understand why.

The only thing I do is configure the DMA. Does anyone have an explanation? I don't know how to solve it.

Thank you very much.