Hi Capps314,
The Kinetis baremetal example code has implementation of the ADC16 calibration code.
Goto: K60_100: Kinetis K60 Ethernet Crypto 100 MHz MCUs
Look for following:
KINETIS512_V2_SC
: Kinetis 100MHz Rev 2 Example Projects.
Size (K): 705 Format: zip Rev #: 1.0 Modified: 5/23/2013
The KINETIS512_SC contains:
/******************************************************************************
Function 1. Name AUTO CAL ROUTINE
Parameters ADC module pointer points to adc0 or adc1 register map
base address.
Returns Zero indicates success.
Notes Calibrates the ADC16. Required to meet specifications
after reset and before a conversion is initiated.
******************************************************************************/
uint8 ADC_Cal(ADC_MemMapPtr adcmap)
{
unsigned short cal_var;
ADC_SC2_REG(adcmap) &= ~ADC_SC2_ADTRG_MASK ; // Enable Software Conversion Trigger for Calibration Process - ADC0_SC2 = ADC0_SC2 | ADC_SC2_ADTRGW(0);
ADC_SC3_REG(adcmap) &= ( ~ADC_SC3_ADCO_MASK & ~ADC_SC3_AVGS_MASK ); // set single conversion, clear avgs bitfield for next writing
ADC_SC3_REG(adcmap) |= ( ADC_SC3_AVGE_MASK | ADC_SC3_AVGS(AVGS_32) ); // Turn averaging ON and set at max value ( 32 )
ADC_SC3_REG(adcmap) |= ADC_SC3_CAL_MASK ; // Start CAL
while ( (ADC_SC1_REG(adcmap,A) & ADC_SC1_COCO_MASK ) == COCO_NOT ); // Wait calibration end
if ((ADC_SC3_REG(adcmap)& ADC_SC3_CALF_MASK) == CALF_FAIL )
{
return(1); // Check for Calibration fail error and return
}
For comparison MQX4.02 ADC Calibration has:
static _mqx_int adc_calibrate(_mqx_int adc_index)
{
uint_16 cal_var;
ADC_MemMapPtr adc_ptr = _bsp_get_adc_base_address(adc_index);
struct {
uint_8 SC2;
uint_8 SC3;
} saved_regs;
if (adc_ptr == NULL)
return ADC_ERROR_BAD_PARAM; /* no such ADC peripheral exists */
saved_regs.SC2 = adc_ptr->SC2;
saved_regs.SC3 = adc_ptr->SC3;
/* Enable Software Conversion Trigger for Calibration Process */
adc_ptr->SC2 &= ~ADC_SC2_ADTRG_MASK;
/* Initiate calibration */
adc_ptr->SC3 |= ADC_SC3_CAL;
/* Wait for conversion to complete */
while (adc_ptr->SC2 & ADC_SC2_ADACT_MASK){}
/* Check if calibration failed */
if (adc_ptr->SC3 & ADC_SC3_CALF_MASK) {
/* Clear calibration failed flag */
adc_ptr->SC3 |= ADC_SC3_CALF_MASK;
/* calibration failed */
return -1;
}
...
Regards,
David