How to allocate different Buffersize in DMA for multiple ADC's which are running in continuous conversion mode.
- I am using a STM32F4 microcontroller, I have to read the ADC values from 3 gpio pins so i am using ADC1, ADC2, ADC3, with DMA and all ADC's is configured in a continuous mode, because i have to collect the ADC values from all ADC's during pulse time period, then have to find the mean value of each ADC for the data collected during the pulse time.
So, with ADC1 i enabled and disabled the ADC1 with Capture Compare interrupt, and the found the mean of the data collected in the buffer of DMA, this is all good. But, when i use ADC2 and ADC3, how can I allocate the different Buffersize for each ADC's?? so that i can collect the data stored in each buffer to find the mean value of the data stored in each ADC.
Below code is the initialization of DMA and ADC's (however for single ADC's DMA initialization is working, but if i enable ADC2 and ADC3 which has different channel's how can i initialize different buffersize for each ADC's so that i can take each buffer to process it), what approach is suitable to do that.
Below code is for initializing the ADC's channel and stream.
cADCReadout::sADCInitStruct adc1;
adc1.ADCChannel = ADC1;
adc1.DMAChannel = DMA_Channel_0;
adc1.DMAStream = DMA2_Stream0;
adc1.DMATRSFCompleteFlag = DMA_FLAG_TEIF0;
cADCReadout::sADCInitStruct adc2;
adc2.ADCChannel = ADC2;
adc2.DMAChannel = DMA_Channel_1;
adc2.DMAStream = DMA2_Stream3;
adc2.DMATRSFCompleteFlag = DMA_FLAG_TEIF0;
cADCReadout::sADCInitStruct adc3;
adc3.ADCChannel = ADC3;
adc3.DMAChannel = DMA_Channel_2;
adc3.DMAStream = DMA2_Stream1;
adc3.DMATRSFCompleteFlag = DMA_FLAG_TEIF0;
m_oADC1.initialize(adc1);
m_oADC1.addChannel(GPIOA, GPIO_Pin_1,ADC_Channel_1,ADC_SampleTime_112Cycles);
m_oADC1.initialize(adc2);
m_oADC1.addChannel(GPIOA, GPIO_Pin_2,ADC_Channel_2,ADC_SampleTime_112Cycles);
m_oADC1.initialize(adc3);
m_oADC1.addChannel(GPIOA, GPIO_Pin_3,ADC_Channel_3,ADC_SampleTime_112Cycles);Below is the function for DMA and ADC initialization.
void cADCReadout::initialize(sADCInitStruct init)
{
m_sInitStruct = init;
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
DMA_InitTypeDef DMA_InitStructure;
//DMA
DMA_InitStructure.DMA_Channel = init.DMAChannel;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(init.ADCChannel->DR);
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)(&m_aRecBuffer);
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = BUFFERSIZE;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(init.DMAStream, &DMA_InitStructure);
DMA_Cmd(init.DMAStream, ENABLE);
//ADC
ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_RegSimult;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode =ADC_DMAAccessMode_1;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion =3;
ADC_Init(init.ADCChannel, &ADC_InitStructure);
ADC_EOCOnEachRegularChannelCmd(init.ADCChannel, ENABLE);
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(init.ADCChannel, DISABLE);
// ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
}- My next question is, I know the formula to find the conversion time of the ADC and also the parameters, but I am bit confused in finding the ADC clock for the stm32f4 chip, i also checked in the datasheet but couldnot figure out what exactly is the ADC clock for the stm32f4 chip if i am using "ADC_Prescaler_Div2". It would really helpfull if any one could also let me know the ADC clock value for the stm32f4 chip with ADC prescaler 2.
