Skip to main content
HJang.3
Associate II
February 23, 2023
Question

In STM32F401 using ADC (4 channels in Scan Conversion mode) using DMA triggered by Timer , Data of different Channels interchanges.

  • February 23, 2023
  • 0 replies
  • 748 views

I am using STM32F401CCU6 for making Oscilloscope with Waveform on display, I need to display upto 1kHz waveform in 300points. For that i am using 4Channels ADC with DMA and timer for Triggering.

The code used for ADC starting :

if(HAL_OK != HAL_ADC_Start_DMA(&hadc1,(uint32_t *)adcRead, bufferSize * ChannelCount)){
	 Error_Handler();
 }

where adcRead is Main DMA buffer ,

bufferSize is Buffer Size for 1 channel,

channelCount is No. of Channels (in my case 4 channels)

after One DMA transfer , I use ADC callback function to stop ADC :

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){
 
if(HAL_ADC_Stop_DMA(&hadc1) != HAL_OK){
	errorcount++;
	Error_Handler();
}
}

After displaying one Buffer , I start ADC again using above starting code again.

To seperate each channel data from Main buffer , I used

 for (int i = 0; i < bufferSize; i++) Adc0[i] = adcRead[(i*ChannelCount) + 0];
 for (int i = 0; i < bufferSize; i++) Adc1[i] = adcRead[(i*ChannelCount) + 1];
 for (int i = 0; i < bufferSize; i++) Adc2[i] = adcRead[(i*ChannelCount) + 2];
 for (int i = 0; i < bufferSize; i++) Adc3[i] = adcRead[(i*ChannelCount) + 3];

BUT the main problem arising here is that,

data of different channel interchanges randomly.

sometime channel 1 waveform in channel 2 or 3 or 4

and vice versa.

I am using max ADC clock , that is 36mHz.

I can't find the problem.

Thank You.

This topic has been closed for replies.