How to Configure ADC?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to Configure ADC?

1,143 Views
Charith
Contributor I

Hi,

I am using MPC5748G Micro for ADC Conversion. I am using a circuit with 12Volts input. I need to monitor the input to that circuit using ADC, for that I am using Voltage Divider Circuit with 3.3Volts reference. I am continuously taking the readings through ADC channel but the readings are not constant, it is varying. I am using the below configurations for ADC. Please suggest if any corrections required.

void ADC1_PadConfig_ChanSelect(void) {
SIUL2.MSCR[PD0].B.APC = 1; /* PD0 = function ADC1_P[0] = ADC 1 channel 0 */
ADC_1.NCMR0.B.CH0 = 1; /* Enable channel 0 for normal conversion on ADC1 */

}

void ADC1_Calibration(void) {
uint32_t __attribute__ ((unused)) ADC1_Calibration_Failed = 1; /* Calibration has not passed yet */

ADC_1.MCR.B.PWDN = 1; /* Power down for starting calibration process */
ADC_1.MCR.B.ADCLKSEL = 0; /* ADC clock = bus clock/2 (80/2 MHz FS80) */
/* Note: Calibration requires it to be set at max 40MHz for best results */
ADC_1.CALBISTREG.B.TEST_EN = 1; /* Enable calibration test */
ADC_1.MCR.B.PWDN = 0; /* Power back up for calibration test to start */
while(ADC_1.CALBISTREG.B.C_T_BUSY); /* Wait for calibration to finish */
if(ADC_1.MSR.B.CALIBRTD) { /* If calibration ran successfully */
ADC1_Calibration_Failed = 0; /* Calibration was successful */
}
else {
ADC1_Calibration_Failed = 1; /* Calibration was not successful */
}
}

void ADC1_Init(void) { /* Initialize ADC1 module & start normal scan mode */
ADC_1.MCR.B.PWDN = 1; /* Power down for starting module initialization */
ADC_1.MCR.B.OWREN = 0; /* Enable overwriting older conversion results */
ADC_1.MCR.B.MODE = 1; /* Scan mode (1) used instead of one shot mode */
ADC_1.MCR.B.ADCLKSEL = 1; /* ADC clock = FS80 bus clock (80 MHz here) */
ADC_1.MCR.B.PWDN = 0; /* ADC_1 ready to receive conversation triggers */
ADC_1.MCR.B.NSTART = 1; /* Initiate trigger for normal scan */
}

void ADC1_Read_Chan_0 (void) { /* Read conversion results */
Result= ADC_1.CDR[0].B.CDATA; /* Read channel 0 conversion result data */
ResultInMv = (uint16_t) (ADC_VREF*Result/0xFFF); /* Conversion in mV */
}

 

Thanks

Tags (1)
0 Kudos
8 Replies

1,092 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

Could you specify how much it is varying? Conversion accuracy level depends also on noise level and ADC input impedance, usually you can see conversion result floating a bit unless it is high precison analog design what not the case of EVB.

davidtosenovjan_0-1675943534472.png

 

 

0 Kudos

1,075 Views
Charith
Contributor I

I am giving 12V input to the voltage divider circuit having 220k as R1 and 33k as R2, the output from voltage divider is 1.565V.

If I read the ADC readings from the Voltage Divider which should give 1.565V(or 1565mV) I am reading in the range of 1410mV to 1540mV.

0 Kudos

1,062 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

These are very weak resistors and it'll be apparently reason why you are facing conversion inaccuracy.

Pay attention to following appnote, section "Input Leakage Offset Error":
https://www.nxp.com/docs/en/application-note/AN2438.pdf

I would recommend to use resistor divider consisting of resistors in orders units of kiloohms, not hundreds.

 

0 Kudos

1,059 Views
Charith
Contributor I

Actually I am using 220kiloohms and 33kiloohms

0 Kudos

1,050 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

Yes, I understand. These are weak resistors (i.e. high resistance). Use stronger resistors (i.e. with lower resistance).

0 Kudos

1,031 Views
Charith
Contributor I

If I use lower resistor values 2.2Kohms and 330ohms the ADC values is stable.

Can I know how to configure 10bit ADC for the same.

0 Kudos

1,016 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

This is common topic for all kind of ADCs.

0 Kudos

1,003 Views
Charith
Contributor I

Can You Please Help me with Configuration changes to be done in code for 10bit ADC.

0 Kudos