AnsweredAssumed Answered

Coherent dual channel (multimode) sampling on STM32F4

Question asked by darek.max on Jun 12, 2015
Latest reply on Jun 14, 2015 by darek.max
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 */


Outcomes