Question about MPC5744P ADC Calibration?

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

Question about MPC5744P ADC Calibration?

898 Views
liwuquan
Contributor III
NXP Expert,
The below code is from NXP DEVKIT- MPC5744P example S32DS project ADC_MPC5744P.
My question is inside the main() Can I switch the two function calls below:
 ADC1_PadConfig_ChanSelect();  /* Configure ADC pads & select scan channels */
 ADC1_Calibration();     /* Calibrate to compensate for variations */
to make it:
 ADC1_Calibration();     /* Calibrate to compensate for variations */
ADC1_PadConfig_ChanSelect();  /* Configure ADC pads & select scan channels */
?
\..\MPC574xP Quick Start Package Rev6\Code Project Examples for MPC574xP\ADC_MPC5744P
int main(void)
{
 int counter = 0;
 
 xcptn_xmpl ();              /* Configure and Enable Interrupts */
 peri_clock_gating();    /* Configure gating/enabling peri. clocks for modes*/
 system160mhz();         /* sysclk=160MHz, dividers configured, mode trans*/
 LED_Config();           /* Assign LED ports on Freescale LED as GPIO outputs*/
 MC_CGM.AC0_SC.B.SELCTL = 0b10; //Select PLL0_PHI as source of ADC analog clock
 MC_CGM.AC0_DC2.R = 0x80040000; //Enable ADC_CLK and divide PLL0_PHI source by 5 (i.e. 4+1)
 ADC1_PadConfig_ChanSelect();  /* Configure ADC pads & select scan channels */
 ADC1_Calibration();     /* Calibrate to compensate for variations */
 ADC1_Init();            /* Initialize ADC1 module & start normal scan mode */
 for(;;) {   
     counter++;
  if (ADC_1.ISR.B.ECH) { /* If normal scan channels finished converting */
    ADC1_Read_Chan();    /* Read conversion results */
    update_LEDs();       /* Update LEDs with scaled chan 1 result */
    ADC_1.ISR.R = 0x00000001; /* Clear End of CHain (ECH) status bit */
  }
 }
 return 0;
}
void ADC1_PadConfig_ChanSelect(void) { /* Config ADC pads & select scan chans */
     /* Note:  MSCR.SSS configuration  is not needed for inputs if there is  */
     /*        no SSS value is in signal spreadsheet */
     /* Note:  ADC1 Channel 6 on PE12 is connected to XDEVKIT-MPC5744P potentiometer. */
 SIUL2.MSCR[PE12].B.APC = 1; //Configure ADC1_AN6 to analog pad control function. Analog is default function so SSS says 0
 ADC_1.NCMR0.B.CH6 = 1; //Enable channel 6 for normal conversion on ADC1
}
void ADC1_Calibration(void) {       /* Steps below are from reference manual */
  uint32_t 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 */
  }
  if(ADC1_Calibration_Failed){} //Functionally useless statement to make compiler happy
}
Another information in your AN4881:
6. SAR ADC initialization example
To initialize the SAR ADC, the following steps must be completed as a minimum:
1. Configure input pads and ADC normal conversion registers
2. Calibrate the ADC
3. Initialize SAR ADC modes and clock
4. Power on the ADC and start conversions
My similar question is Can switch order of 1. and 2. above?
Thank you.
Susan Li
0 Kudos
3 Replies

680 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi liwuquan‌,

I'm not expert in ADC programming - perhaps you should ask that in the MPC community - but according with MPC5744P Reference Manual ($36.5.1.1) 

I quote:

"Programming the available Normal Conversion Mask Register(s) (ADC_NCMRn) selects the channel(s). Each channel can be individually enabled by setting a bit in the corresponding field of the NCMRn register. NCMR0 serves precision channels:

• 0 - 15 (ADC0)
• 0 - 15 (ADC1)
• 0 - 4, 10, 14 (ADC2)
• 0 - 7, 10 - 14 (ADC3)


The mask register(s) must be programmed before starting the conversion and cannot be changed until the conversion of all the selected channels ends. Conversion always starts from the lowest channel number selected and sequentially goes to the highest number." -- end of quote

Therefore you can't switch the function calls.

Anyhow, why would you do that ?

Hope it helps!

Daniel

0 Kudos

680 Views
liwuquan
Contributor III

Daniel,

Thank you for your quick answer.

Why I want to do that, I am thinking that what function ADC1_PadConfig_ChanSelect() does has nothing to do with what the function ADC1_Calibration() does. If so, then for my real motor control application, I would like to do the Calibration first, then configure ADC to CTU mode for the conversion and do the conversion.

Please let me know how function ADC1_PadConfig_ChanSelect() is related with the calibration, why it has to go ahead of function ADC1_Calibration();

Would you please also provide more NXP documentation to help me with MPC5744P ADC calibration?

Why I always prefer to posting my questions to NXP motor control community, the reasons are : first we are using MPC5744P for motor control application; second most time I can get quicker help from you.

Thank you.

Susan Li

0 Kudos

680 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi liwuquan

Thanks for your appreciation!

In the example you shown, the function ADC1_PadConfig_ChanSelect() { } writes in the ADC_1.NCMR0.B.CH6 register since it wants to calibrate for that specific analogue input (PTE12 pin).  Therefore, according with the Reference Manual it has to be called prior to the void ADC1_Calibration(void)

It is normal that you first assign the ADC channel you want to calibrate and then perform the calibration. Otherwise it does not make sense. Am i missing something ?

Best regards,
Daniel

0 Kudos