2015-06-12 03:02 AM
Hi All,
I am learning how the ADCs modes are working on the ST32F4 MCU (using Olimex board). I got operational ADCs (running independently) in a single a and continuous mode. The next step is to get a coherent sampling from two ADCs (for all cases I am explicitly polling measurements within my program). The multimode configuration is presented below. I would like to read the data from both (ADC1 and ADC2) converters into an array of samples using the following function (S1, S2 are for debugging purposes only):void Get_RawSamples( __IO uint16_t Ch1[], __IO uint16_t Ch2[], int NumSamples){ int16_t i, S1,S2 ; __IO uint32_t S12; for (i = 0; i < NumSamples; i++) { ADC_SoftwareStartConv(ADC1); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); S1 = ADC_GetConversionValue(ADC1); Ch1[i] = S1; S2 = ADC_GetConversionValue(ADC2); Ch2[i] = S2; }} /* end Get_RawSamples */According to the documentation, to retrieve samples from multiple ADCs I should use the ADC_GetMultiModeConversionValue() function. When I call the ADC_GetConvertionValue function for each ADC, I am getting correct values (connected a 1.5 V battery, and checked against the digital multimeter measurements). When I replace the content of the loop with: ADC_SoftwareStartConv(ADC1); //this is the master while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); S12 = ADC_GetMultiModeConversionValue(); and run/debug it, the value of S12 is always zero. So, I have some questions: 1. If I call ADC_GetConversionValue for each ADC separately do I get coherent measurements ? 2. Why the value of S12 is zero? Is there any special way of dealing with the multimode data conversion? After getting the ADCs in the polling mode working, I will switch to the DMA approach with timers to control sampling rate. Thanks in advance for your help. Cheers, Darek P.S. I have noticed that calling: ADC_EOCOnEachRegularChannelCmd(ADC1, ENABLE) (or ADC_EOCOnEachRegularChannelCmd(ADC1, DISABLE) for tests) in the configuration of the ADCs does not have any influence on the behaviour of my code./* ADC Configuration */void Configure_ADCs(void){ ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult; ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInit(&ADC_CommonInitStructure); ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC1,&ADC_InitStructure); ADC_Init(ADC2,&ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_5,1, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC2, ADC_Channel_6,1, ADC_SampleTime_3Cycles); ADC_Cmd(ADC1,ENABLE); ADC_Cmd(ADC2,ENABLE); ADC_EOCOnEachRegularChannelCmd(ADC1, ENABLE);} /* end Configure_ADCs */2015-06-12 06:15 AM
I'd go directly for the DMA+TIM implementation, as that's how you'd actually want to pace sampling.
[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/stm32f207%20ADC%2BTIMER%2BDMA%20%20Poor%20Peripheral%20Library%20Examples&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=4333]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2Fstm32f207%20ADC%2BTIMER%2BDMA%20%20Poor%20Peripheral%20Library%20Examples&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=4333Perhaps you can work this backward to manually polling the EOC2015-06-13 11:33 PM
Hi Clive1,
thanks for the link. I will go for that solution in the future. Just curious, did anybody get the multimode (at least dual) ADCs working in the polling mode? If yes, what is the right way of doing the data extraction?Cheers, Darek