0
\$\begingroup\$

I am using an STM8L151Cx with the Cosmic C compiler to develop a 3 phase ammeter. I rsn into an issue during my last stage of development.

3 phase current is connected to 3 channels in the controller via op-amps. I calibrated the ADC channels so that it shows the current injected into it over the display connected to the controller.

When I operate it only by injecting current to a single ADC keeping other ADC channels open, the display shows correct a reading (i.e. exact injected current is been shown in the display.) The ADC calibration is correct and the meter is working perfectly.

Next I started injecting 3 phases simultaneously, and the problem started.

When all the 3 phases are injected simultaneously, the reading dropped from the actual current injected. It is not showing the actual injected current reading. I cross checked whether the ADC reading measured is correct. There is a drop in the ADC reading value for about 8-12 points, so there is a problem in the ADC reading.

I measured the voltage levels a ADC channel port using a multimeter. There is no change in voltage level when I inject a single phase or three phase current, so there is some problem with my ADC code. I think the problem is with my ADC READ. I am sharing my adc_read code here.

uint16_t ADC_Read(ADC_Channel_TypeDef ADC_Channel_No)
{
  uint16_t ADCval = 0;

  ADC_DeInit(ADC1);

  ADC_Init(ADC1, ADC_ConversionMode_Single, ADC_Resolution_12Bit, ADC_Prescaler_1);
  ADC_VrefintCmd(DISABLE);
  ADC_Cmd(ADC1, ENABLE);
  ADC_ChannelCmd(ADC1, ADC_Channel_No, ENABLE);
  ADC_SoftwareStartConv(ADC1);
  while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == FALSE);
    ADCval = ADC_GetConversionValue(ADC1);
    ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
  ADC_DeInit(ADC1);
  return ADCval;
}

Can someone help me in identifying the problem? I think the problem is with reading multiple ADC channels. Here I read multiple channels one by one at a time.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Just drop(ignore the result) 2 or 3 reads after change ADC channel.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.