Error in fsl_adc12.c

Showing results for 
Search instead for 
Did you mean: 

Error in fsl_adc12.c

Contributor I

I am using an MKE18F512VLH16 MCU.

I have found a small issue in the ADC12_DoAutoCalibration function that is in the fsl_adc12.c file.

The function attempts to reset the SC3 register back to its original state after it does some auto calibrating.  However, when attempting to restore the AVGS field in the SC3 register, the code does this to restore it:

// Stores current SC3 register value

tmp32 = base->SC3;
averageMode = ((tmp32 & ADC_SC3_AVGS_MASK) >> ADC_SC3_AVGS_SHIFT); // (Saves the AVGS Field)

// Triggers a calibration

tmp32 &= ~ADC_SC3_AVGS_MASK;

tmp32 |= ADC_SC3_CAL_MASK;
base->SC3 = tmp32;

// Attempt to restore

tmp32 = base->SC3;

tmp32 |= ADC_SC3_AVGS(averageMode); // (This is where I see an issue)
base->SC3 = tmp32;

The or'ing  of tmp32 and ADC_SC3_AVGS(averageMode) will result in no change to the field if the averageMode is 0, and can cause errors for other values as well.

I would also like to understand if this AVGS field will tamper with ADC data results after calibration, or is this field only for doing an auto calibration?

I have attached the code to this post as well.

Labels (1)
0 Kudos
1 Reply

NXP TechSupport
NXP TechSupport

Hello Sean Dvorscak


When you enter ADC12_DoAutoCalibration function, the variable averageMode stores the value that is in AVGS field of ADC_SC3 register.

In order to calibrate the ADC the average value must be 32 samples, so you change temporarily this field to calibrate the device, when the calibration is complete you return to the average value that was before entering the function.


Let me know if this is helpful.

Best regards,


0 Kudos