cancel
Showing results for 
Search instead for 
Did you mean: 

How to get best ADC sample using ADC + TIM + DMA.??

MGami.1
Associate III

Hello everyone,

I am using ADC + DMA + TIMER for my analog samples on STM32 nucleoF401RE.

I am new into the STM32 family.So I refer some code as per given some examples in this community.But I am not able to achieve it.

I wanted to follow below method for my code.

1) Configure Peripherals

  (For that any External trigger convergence required in terms of ADC.)

2) I want sample at every 1 ms.

3) Wanted to collect 1400 samples in DMA(Approx time to collect all samples is 1.4 seconds).

4) After 1400 Samples successfully completed, trigger interrupt.

5) Want to process on received samples.

6) Again follow same procedure from step number 3.

I have attached my code for better understanding. 

In that i have tried 2 method. Both i have tried and output also i have written in that file.

I don't quite understand the relationship between the Timer's interrupt rate and the sampling frequency. 

Can someone help me with sample code?I searched but can not find proper explanation.

Thank you in advance

Regards,

Milan

3 REPLIES 3

Don't want TIM interrupting, the Update rate should be 1.4ms​ and trigger the ADC, this will define the sample rate.

The DMA should be in continuous mode, to a 2800 sample buffer. You can get interrupts at HT and TC points, each occurring when there are 1400 samples to process.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for your reply...

You are correct. And I also got one mistake in my code. I have configured hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD and now i changed to hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD .So now I am able to get my adc value as I expected.

Hi sir,

Now I am performing operation for 10 samples using below pseudo code.

//Pseudo Code

HAL_ADC_Start_DMA(&hadc2, (uint32_t*)&adc_buffer, 10);

HAL_TIM_Base_Start_IT(&htim4);

while(1)

{}

void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)

{

 /* Toggle LED */ HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_5);

}

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

 /* Toggle LED */ HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_6);

}

Internally This HAL_ADC_ConvHalfCpltCallback & HAL_ADC_ConvCpltCallback setting HT & TC bits.

But when I am using HAL_ADC_ConvHalfCpltCallback function and for debug I am toggling LED in this function. Because of Half transfer complete I have to get 5 samples But I am getting all 10 values in my buffer.

Can you please help on this.

Thank you in advance.

Regards,

Milan