cancel
Showing results for 
Search instead for 
Did you mean: 

read multiple samples from adc each 10 seconds with dma

frankers
Associate II

i want to read every 10 seconds a few samples from a adc channel and let the dma bring the data to my variables.

i have that working with 1 sample. the timer trigger the adc. adc trigger the dma channel and my 

HAL_ADC_ConvCpltCallback get called and the adc channel value is in the data variables. i can do this also with 2 channels. good.
now i want read 2 or 4 samples from the adc channel. i can setup the timing there with the adc setup. thats ok.
i want trigger the sampling every 10sek then read fast 2 or 4 samples. exact timing not relevant just fast.  but if i setup this  for 2 samples, the completion callback is now only called every 20 seks.  .. i think the adc does not trigger the dma 2x for the 2 samples , but only 1x and so the dma need 2 timer triggers until I have my 2 samples complete and so it takes 20secs instead of the 10sek.  please show a init of the adc so i can get 2 or 4 samples per timer trigger.

i need help with setup combination: 
//hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE; // Single channel
  hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE; // 2 channel
  hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV; //das war
  //hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  //hadc2.Init.LowPowerAutoWait = DISABLE; das war
  //hadc2.Init.ContinuousConvMode = DISABLE;
  //hadc2.Init.ContinuousConvMode= ENABLE;
  hadc2.Init.NbrOfConversion = 2; // One channel , 2 burst
  //hadc2.Init.NbrOfConversion = 2; // for 2 channel 1 sample
  //hadc2.Init.NbrOfConversion = 4; // channel  2 samples 
  hadc2.Init.DiscontinuousConvMode = DISABLE;
  //hadc2.Init.DiscontinuousConvMode = ENABLE; // burst, 2 samples von 1 trigger ?
  //hadc2.Init.NbrOfDiscConversion = 2; // 2 samples im burst
 
the mcu is stm32G4 G431  170MHz .. 
thank you
Frank
1 ACCEPTED SOLUTION

Accepted Solutions

no os .  i use HAL  .. and i solved it already.

 

the adc can do multiple conversions .. i add rank1 rank2 .. for my aim to get 2 or 4 fast samples every 10 seconds, i just use this ranks 1 and 2 and give the same channel again. 

now when timer trigger the adc, adc will do the number of conversions.. here 2! and channel is same.. so it will get 2 samples frome the same channel. exactly what i want. 

 

in real i use 2 adc and each adc watch 2 channel and with the ranks trick i get 2 samples from each channel and from each adc .. the data is transfered by 2 dma channels.. i got a complete-callback where i can use all the sample data.  all good.  i do it every 100 microseconds and have 5 samples from the 4 wires, 4Mega samples  per sec speed.

i do the calculations in the 100 micro secs windows , need about 20usec.. plenty of room.

the question is solved.

View solution in original post

2 REPLIES 2
mbarg.1
Senior II

In these kind of problems, OS plays a vital role.

With AZRTOS, we have one thread per device-type and we could keep all under control with very fast sample rate and reliability. what is your OS?

no os .  i use HAL  .. and i solved it already.

 

the adc can do multiple conversions .. i add rank1 rank2 .. for my aim to get 2 or 4 fast samples every 10 seconds, i just use this ranks 1 and 2 and give the same channel again. 

now when timer trigger the adc, adc will do the number of conversions.. here 2! and channel is same.. so it will get 2 samples frome the same channel. exactly what i want. 

 

in real i use 2 adc and each adc watch 2 channel and with the ranks trick i get 2 samples from each channel and from each adc .. the data is transfered by 2 dma channels.. i got a complete-callback where i can use all the sample data.  all good.  i do it every 100 microseconds and have 5 samples from the 4 wires, 4Mega samples  per sec speed.

i do the calculations in the 100 micro secs windows , need about 20usec.. plenty of room.

the question is solved.