2023-04-19 02:31 AM
Hello All,
I have some questions regarding the ADC of the STM32G071RBT6. Technically we can reach a conversion time of 400 ns if we use the internal ADC clock (35 MHz) and a sampling time of 1.5 cyc. OK, that's pretty good idealy.
I am running my microcontroller at a 48 MHz frequency, and the ADC with a PCLK of 12/24 MHz (depending if I convert one or two ADC signals "at the same time").
In the worst case, for a short period of time (between 30-70 us), I will need to convert two ADC signals at as sample rate of about 2 us and I don't want to use DMA. Is that possible? Should I use polling instead?
What I see is that I can not reach such conversion time as the CPU gets overloaded by interrupts (I guess) and I start getting overrun errors. Seems clear that I can not manage this with just the CPU interrupt, even as a high prioriy one. If I increase the sampling time to 160.5 cyc, it runs without overruns, but obviously I do not get the desired sampling rate.
Another question is, how do I know which channel has been converted when I reach the ADC ISR? I only have de ADC_DR register to recover the converted data, but "no idea" of the channel that has been converted. This is specially important when using the ADC in sequence mode. I hope that every obtained sample has the order I have defined in the sequence, but then I have to control by myself the identifier. Is there any way to obtain the converted channel when in the ISR?
2023-04-19 02:37 AM
Use DMA, I don't see any other sensible way at that sampling rate.
And you will have the sequenced channels in a defined order in the DMA buffer.
2023-04-19 02:52 AM
Then I have another doubt, when using the DMA should I simply trust that the ADC is converting the channels with the expected sampling rate according to the set configuration? I was able to enable the DMA using an example, but I am not sure if the data has being converted at the desired sampling rate. I understand from the fact that the ADC does not get overrun error that all the data is read properly, but still I need to confirm that I am getting the samples on time. It's a quite critical function. And I am pretty sure that with these conditions I won't be able to measure it with a GPIO, if the CPU gets overwhelmed by interrupt at every EOC... Am I correct?