This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ADC Single Conversion Sample

Hi

I am currently having a issue about ADC conversion because I always get the first wrong ADC sample but get correct reading after second try. I assume it is reading dummy data.

Now I tried to read three channels starting from channel 0 to channel 2 respectively at first try and second try.

I measured the voltage signal on each channel and know what to expect from ADC channel from zero to two. I obtained incorrect readings.

Here is my extracted code:


// 1st Try
// Channel 0
ADC_vConfConv(ADC_FIXED, ADC_ANA_0);
ADC_vStartConv();
while(ADC_ubBusy());
ReturnedADC = ADC_DAT & 0x0FFC;
adc_result[ADC_ANA_0] = _iror_(ReturnedADC,2);
First_Try_Channel[0]=adc_result[ADC_ANA_0];


// Channel 1
ADC_vConfConv(ADC_FIXED, ADC_ANA_1);
ADC_vStartConv();
while(ADC_ubBusy());
ReturnedADC = ADC_DAT & 0x0FFC;
adc_result[ADC_ANA_1] = _iror_(ReturnedADC,2);
First_Try_Channel[1]=adc_result[ADC_ANA_1];


// Channel 2
ADC_vConfConv(ADC_FIXED, ADC_ANA_2);
ADC_vStartConv();
while(ADC_ubBusy());
ReturnedADC = ADC_DAT & 0x0FFC;
adc_result[ADC_ANA_2] = _iror_(ReturnedADC,2);
First_Try_Channel[2]=adc_result[ADC_ANA_2];



// 2nd Try
// Channel 0
ADC_vConfConv(ADC_FIXED, ADC_ANA_0);
ADC_vStartConv();
while(ADC_ubBusy());
ReturnedADC = ADC_DAT & 0x0FFC;
adc_result[ADC_ANA_0] = _iror_(ReturnedADC,2);
Second_Try_Channel[0]=adc_result[ADC_ANA_0];

// Channel 1
ADC_vConfConv(ADC_FIXED, ADC_ANA_1);
ADC_vStartConv();
while(ADC_ubBusy());
ReturnedADC = ADC_DAT & 0x0FFC;
adc_result[ADC_ANA_1] = _iror_(ReturnedADC,2);
Second_Try_Channel[1]=adc_result[ADC_ANA_1];

// Channel 2
ADC_vConfConv(ADC_FIXED, ADC_ANA_2);
ADC_vStartConv();
while(ADC_ubBusy());
ReturnedADC = ADC_DAT & 0x0FFC;
adc_result[ADC_ANA_2] = _iror_(ReturnedADC,2);
Second_Try_Channel[2]=adc_result[ADC_ANA_2];

Is there summat wrong with my snippet code?

Regards

RC

Parents
  • If you are using an XC16x device then if is recommended not to used the ADBSY bit (Sorry DAvE).

    ADC_X.H1 Polling of Bit ADBSY
    After an A/D conversion is started (standard conversion by setting bit ADST = 1, injected conversion by setting ADCRQ = 1), flag ADBSY is set 5 clock cycles later. When polling for the end of a conversion, it is therefore recommended to check e.g. the interrupt request flags ADC_CIC_IR (for standard conversions) or ADC_EIC_IR (for injected conversions) instead of ADBSY.

    Meaning you read it before it was actually converted.

Reply
  • If you are using an XC16x device then if is recommended not to used the ADBSY bit (Sorry DAvE).

    ADC_X.H1 Polling of Bit ADBSY
    After an A/D conversion is started (standard conversion by setting bit ADST = 1, injected conversion by setting ADCRQ = 1), flag ADBSY is set 5 clock cycles later. When polling for the end of a conversion, it is therefore recommended to check e.g. the interrupt request flags ADC_CIC_IR (for standard conversions) or ADC_EIC_IR (for injected conversions) instead of ADBSY.

    Meaning you read it before it was actually converted.

Children
No data