2022-02-08 03:18 PM
Hi, I am using a STM32F407. I programmed one channel of ADC1 to start on the falling edge of TIM8, which has a frequency of 100 kHz. So far so good, the ADC performs a conversion every 10 us (100kHz), measured with the HAL_ADC_ConvCpltCallback function call.
The problem is when I want to use the DMA. When trying to transfer the data to memory with DMA, the time it takes increases to 120 us and if instead of converting 1 channel, I convert 2, the time goes to 60 us (the more channels I convert, the faster it is)
Could someone help me understand what is happening?
I leave the code below.
2022-02-08 04:45 PM
You're overloading the processor with interrupts. Convert more values per DMA call instead of just a few.
Having an interrupt at 100kHz is also likely swamping the main loop and preventing progress, especially since it's going through the HAL logic. There is no need to have HAL_TIM_PWM_PulseFinishedCallback defined. You can verify the pulse on a scope or logic analyzer.
Slow down the sample rate by an order of magnitude until you've verified your logic is correct.
2022-02-09 12:58 PM
Hello!
I'm not sure that's the problem, I reduced the frequency of the PWM that fires the ADC to 10kHz and removed the HAL_TIM_PWM_PulseFinishedCallback() function and noticed that it enters the HAL_ADC_ConvCpltCallback() function every 1200us (833Hz). I don't understand the relationship between the number of channels that convert and the time it takes. I would have ensured that the more channels you want to convert, the longer it would take.
Inside the while(1) loop there is absolutely no going.
What I need is quite simple, a PWM No Output channel at 100kHz that will trigger the ADC on the falling edge and have the DMA transfer that data to an array. All at a frequency of 100k! But even though I reduce the sample rate, the rate at which DMA transfers data is less than PWM.
I can't understand what's going on!