2018-02-10 02:39 AM
Hi all,
Just wanted to check with the collective wisdom on this forum. I'm planning to do 3-channel ADC periodic sampling at 10kHz sampling rate. After reading up on the internet resources, two ways appeared to be the most reliable:
I'm planning to go for injected conversion for its seeming ease of implementation using the HAL. However, I would like to check with you guys if this is a recommended solution? Thanks in advance~
#injected-conversion #stm32f4-adc2018-02-10 03:04 AM
Injected channels are the 'high priority' channels to be converted. The ADC results are accessible on specific register and enable future min/max thresholds. They also have their own trigger pin vs normal channels.
It's easier to debug: Even with breakpoint and SW paused, you can see the registers change step by step.
2018-02-10 06:31 AM
I'm still not sure what the 'injected channels' are actually good for, use-case wise.
IMHO the suggested multichannel regular conversion (scan mode) is the way to go.
And 10kHz are not a very demanding sample rate.
I wanted to do a simple polling routine but seemed like the normal polling method might not work that well for multi-channel as some other forum posts have suggested that some of the channels' value might get swapped at a certain interval. So this is a non-option for me.
Because polling is strongly discouraged, even by ST. The ADC peripheral has one result register for all channel, so keeping track of the sequence manually is a second-best idea.
Better setup DMA for 3 channels, and enable the DMA TC interrupt (Transmission Complete).
This way, you get an interrupt when the DMA has copied one set of converted input values (3 in your case) to the supplied buffer address.
2018-02-10 08:38 AM
Yup, that's what I thought as well. I will definitely try it out. Thanks~
2018-02-10 08:47 AM
My understanding with the injected channel is for aperiodic sampling while having an on-going periodic sampling since injected has higher priority. I might be wrong but that how I have used injected channel with other MCU, e.g. PSoC.
The only reason I'm planning to use the injected channels for STM32F4 is that only they have dedicated data registers while the regular channels share one as you have mentioned. Logistically, it will be easier to manage individual data registers.
Regardless, my gut feeling is also to use regular scanning but with interrupt since my MCU should be relatively free in my intended application.
2018-02-10 09:38 AM
DMA can keep loading the 3 values into an array in the background, you can read/poll the array when you need the most current values. Have a TIM trigger the ADC at a convenient periodic rate.
Samples get skewed when the ADC isn't serviced promptly, or DMA is stopped/started. When taking a few dozen cycles to do the conversion the ADC needs a lot of attention.
If you want to poll and only have 3 channels, consider using ADC1, ADC2 and ADC3 to do a single channel each.
2018-02-10 09:21 PM
That's an interesting proposal. However, my worry is on the power consumption for running 3 ADC simultaneously. Not sure about STM32 but on other MCU, ADC can be pretty power hungry for a low power device like the one I'm working on. Regardless, this would probably be perfect for simultaneous measurement without scanning delay between channel sweep.
However, you are right on the DMA. It will probably be the better way forward with enough flexibility for me to increase the sampling rate if needed.