AnsweredAssumed Answered

ADC Calibration Related Issue for mpc5777c

Question asked by Vignesh V on Oct 13, 2019
Latest reply on Oct 18, 2019 by David Tosenovjan

Hi,

    Im using eqadc  module for ADC . Without Calibration it was working fine. But there are some deviations from ADC values and hence decided to use the calibration as suggested in AN2989 . followed the example given below

Example MPC5676R-eQADC_PMC_chnl_conv+calib CW210  

but the issue is it gets 

stuck either in while (EQADC_A.FISR[0].B.EOQFX !=1) {} /* Wait for End Of Queue flag */

or

while (EQADC_A.FISR[0].B.RFDFX != 1){}

line in convert channel

There was an issue with qsort function as library support error was there and i also included own sort function but still same result.

If I comment those two lines seems to work but its wrong so i kindly request to know possible reason for the same.

 

int32_t EQADC_PowerUpCalibration(void)
{
unsigned long raw_res75, raw_res25;
unsigned long cal_res75, cal_res25;

float gccf, occf;

unsigned short gain;
short offset;

/* Convert channel 43 (75%VRH)with CAL=0 */
raw_res75 = ConvertChannel_Median(43,0);
/* Convert channel 44 (25%VRH)with CAL=0, 64 sample time (errata) */
raw_res25 = ConvertChannel_Median(44,0);

/* Compute Gain and Offset */
gccf = (float)(8192.0)/(raw_res75 - raw_res25);
gain = gccf * 16384;
occf = (float)(IDEAL_RES75 - (gccf * raw_res75) - 2.0);
offset = occf;

/* now store Gain in ADCn_GCCR */
EQADC_A.CFPR[0].R = (gain<<8) | 0x00000004;
/* now store offset in ADCn_OCCR */
EQADC_A.CFPR[0].R = ((unsigned short)offset << 8) | 0x00000005;

/* now store Gain in ADCn_AGR */
EQADC_A.CFPR[0].R = (gain<<8) | 0x00000031;
/* now store offset in ADCn_ACR */
EQADC_A.CFPR[0].R = ((unsigned short)offset << 8) | 0x00000032 | 0x80000000;

EQADC_A.CFCR0.R = 0x0410; /* Trigger CFIFO 0 using Single Scan SW mode */
while (EQADC_A.FISR[0].B.EOQFX !=1) {} /* Wait for End Of Queue flag */
EQADC_A.FISR[0].R = 0x10000000;

cal_res75 = ConvertChannel(43,1);
cal_res25 = ConvertChannel(44,1);

// Check the results
if ((ABS(cal_res75 - IDEAL_RES75) > 0xF) || (ABS(cal_res25 - IDEAL_RES25) > 0xF))
{
/* error */
return 1;
}

return 0; /* no error */
}

 

uint32_t ConvertChannel(int32_t channel, int32_t bCal)
{
uint32_t ret = 0;

/* Conversion command: convert "channel" */
/* with ADC0, set EOQ, and send result to RFIFO 0 */
/* 128 adc clocks sampling */
EQADC_A.CFPR[0].R = 0x800C0000 | (channel<<8) | (bCal<<24);
EQADC_A.CFCR0.R = 0x0410; /* Trigger CFIFO 0 using Single Scan SW mode */
/* Wait for RFIFO 0's Drain Flag to set */
while (EQADC_A.FISR[0].B.RFDFX != 1){}

ret = EQADC_A.RFPR[0].R;

/* Clear RFIFO 0's Drain Flag */
/* Clear CFIFO's End of Queue flag */
/* RFDF + EOQF */
EQADC_A.FISR[0].R = 0x10020000;

return ret;
}

uint32_t ConvertChannel_Median(int32_t channel, int32_t bCal)
{
uint32_t results[21];

int32_t i = 0;
for(i=0;i<sizeof(results)/sizeof(results[0]);i++)
{
results[i] = ConvertChannel(channel, bCal);
}

/* sort results */
qsort((void*)results,11,sizeof(results[i]),Compare);

return results[10]; /* median */
}

Attachments

Outcomes