cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 ADC DMA Sample Rate Time

gokhannsahin
Associate II

Hi everyone, 

I have some questions about using ADC. I have an analog channel and want to read it for a specified time according to my PWM signal because it has been used as a voltage sense on an inductor. However, I need more samples and have to check the changes. To do this, set two-timers, one has been used to get compare of PWM value, other trig the ADC for 100samples. Here I am confused right here. I'm not sure how to calculate the timing, also I'm afraid of getting overrun and wrong data. So, I need your help and have some questions about this application. By the way, I'm using STM32G431 which is new MCU.

  1. The datasheet says that the maximum of the clock frequency of the ADC module is 40MHz. The clock frequency of MCU is 160MHz. Then, should I set the clock prescaler of ADC as "Sync divided 4" or does it never exceed 40MHz anyway? (for example, what about in async 1?)
  2. If a new trig occurs by the timer used for trig before the adc read cycle is complete, will raw value be wrong?
  3. How should I set the trig time according to adc reading time?
16 REPLIES 16

DMA transfers nonetheless occupy the bus.

And the core must still process the high amount of ADC samples.

DMA should be started once the signal reaches a certain level, leaving the analog watchdog window. When the required amount of samples are collected, DMA stops, and no longer occupies the bus. ADC doing conversions itself have no impact on the rest of the system (except on power consumption).

> DMA should be started once the signal reaches a certain level, leaving the analog watchdog window.

Which would require careful evaluation of the attached hardware. Noise shall not trigger false "PWM" cycles then.

With motor control or similar hardware with substantial coil inductances (and the resulting EMF), this could be the case.

Then, if I use the compare event of PWM to start DMA while in ADC conversion mode, it will take as many samples as the number of samples I have specified and occur interrupt. It will wait until the next event, so it will not work. I'm right?

gokhannsahin
Associate II

Then, if I use the compare event of PWM to start DMA while in ADC conversion mode, it will take as many samples as the number of samples I have specified and occur interrupt. It will wait until the next event, so it will not work. I'm right?

Hi

If you want to convert the maximum of samples during the T (according to your drawing) using the ADC in DMA mode with the Trigger on the rising edge of your signal, yes if it will work.

Have you tried to code something in this way ?

Is that what you asked for and explained in your diagram ?

And what do you want to do with ADC converted value ? mathematical post processing ? amplitude monitoring ?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I have tried continous mode and trigged compare event but there has been sync error.

To test sampling time, I toggles a pin. The time is not constant, always changes.