Author Topic: STM32 ADC multi-channel burst capture  (Read 1707 times)

0 Members and 1 Guest are viewing this topic.

Offline BorisRapTopic starter

  • Contributor
  • Posts: 37
  • Country: de
STM32 ADC multi-channel burst capture
« on: April 03, 2023, 02:40:36 pm »
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 STM32G051

In 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[200] 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 synchronous

Thank you very much
« Last Edit: April 03, 2023, 02:44:23 pm by BorisRap »
 

Offline wek

  • Frequent Contributor
  • **
  • Posts: 495
  • Country: sk
Re: STM32 ADC multi-channel burst capture
« Reply #1 on: April 03, 2023, 04:02:10 pm »
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
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6389
  • Country: ca
  • Non-expert
Re: STM32 ADC multi-channel burst capture
« Reply #2 on: April 03, 2023, 11:38:44 pm »
You can use multichannel scan continuous conversion: https://www.st.com/resource/en/application_note/an3116-stm32s-adc-modes-and-their-applications-stmicroelectronics.pdf
DMA 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/
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline BorisRapTopic starter

  • Contributor
  • Posts: 37
  • Country: de
Re: STM32 ADC multi-channel burst capture
« Reply #3 on: April 04, 2023, 07:30:14 am »
You can use multichannel scan continuous conversion: https://www.st.com/resource/en/application_note/an3116-stm32s-adc-modes-and-their-applications-stmicroelectronics.pdf
DMA 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/

Thank 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
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8179
  • Country: fi
Re: STM32 ADC multi-channel burst capture
« Reply #4 on: April 04, 2023, 07:45:21 am »
Is it an absolute must to have this memory layout:
Code: [Select]
uint16_t v1[200];
uint16_t v2[200];

You can't consider this?
Code: [Select]
struct
{
    uint16_t v1;
    uint16_t v2;
} things[200];

The latter is usually better 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.
 
The following users thanked this post: thm_w

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6389
  • Country: ca
  • Non-expert
Re: STM32 ADC multi-channel burst capture
« Reply #5 on: April 04, 2023, 11:09:33 pm »
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.

Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf