STM32 ADC multi-channel burst capture - Page 1
Forum section: electronics / general

author: BorisRap
author_rank: Contributor
timestamp: April 03, 2023, 02:40:36 pm
content: Hello, I'm fairly new to micro controller programming, I'm trying to design a system that has 4 analog inputs, two are voltages V1 and V2 that have to be sampled for a period of time and two are fairly constant values T from a temperature probe and Vref, a known voltage reference.I'm using a STM32G051In each main loop cycle all 4 values must be measured, T and Vref is ok to make a single conversion for each since they won't be changing.V1 and V2 are fast changing signals and in order to analyze them I have to sample them. I'd like to sample each about 200 times with 12bit resolution, that means two uint16_t buffers.The sampling period should be around 1us.That means 200us total time per input.I'd like to 'fire' the sampling, and just wait until both buffers are full. Then stop the sampling to analyze the data.Can you give me a basic idea on how should I configure the DMA to get that data?The time is not an issue, if I first sample V1 and then V2 and then T and Vref there is no problem, the while loop doesn't have to execute particularly fast, and there is no other thing the processor should be doing at that time so everything can be synchronousThank you very much

author: wek
author_rank: Frequent Contributor
timestamp: April 03, 2023, 04:02:10 pm
content: You mean 200x V1 and after that 200x V2? There's no automatism to do this in hardware.You can do Nx interleaved measurements, wouldn't that fit your purpose?JW

author: thm_w
author_rank: Super Contributor
timestamp: April 03, 2023, 11:38:44 pm
content: You can use multichannel scan continuous conversion:https://www.st.com/resource/en/application_note/an3116-stm32s-adc-modes-and-their-applications-stmicroelectronics.pdfDMA will fill a 4 length buffer with the ADC data (4 different channels). Then you'll get an interrupt when that is done, put the 4 values into your 200 length array. When that 200 length array is full, mark as data ready to process and either move to another buffer or stop conversions until processing is done.https://controllerstech.com/stm32-adc-multiple-channels/https://embedds.com/multichannel-adc-using-dma-on-stm32/

author: BorisRap
author_rank: Contributor
timestamp: April 04, 2023, 07:30:14 am
content: Quote from: thm_w on April 03, 2023, 11:38:44 pmThank you, I presumed it was something like that. I have to do a buffer 4 * 200 uint16_t and the DMA will fill the buffer with samples in order from all 4 channels. Then I just take the ones I need

author: Siwastaja
author_rank: Super Contributor
timestamp: April 04, 2023, 07:45:21 am
content: Is it an absolute must to have this memory layout:Code:uint16_t v1;uint16_t v2;You can't consider this?Code:struct{uint16_t v1;uint16_t v2;} things;The latter isusuallybetter downstream, too (for example, if you plot v1 and v2 together); and would be easier to produce. You could use continuous DMA just converting v1 and v2 alternatively and writing linearly to the buffer.

author: thm_w
author_rank: Super Contributor
timestamp: April 04, 2023, 11:09:33 pm
content: Yeah, forgot about the timing part.You could use either a timer interrupt and trigger the conversion from there.Or set up the timer output compare to automatically start the ADC conversions.