Skip to main content
MGami.1
Associate III
March 2, 2020
Question

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

  • March 2, 2020
  • 3 replies
  • 1006 views

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

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
March 2, 2020

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
MGami.1
MGami.1Author
Associate III
March 3, 2020

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.