AnsweredAssumed Answered

Question regarding ADC Example project in MPC5748G

Question asked by Junyi Zhang on May 21, 2020
Latest reply on May 25, 2020 by Petr Stancik

I've been running the ADC example code in S32DS, which converts the ADC result to illuminate the LED light on the MPC7548G board. The example code contains ADC1_Calibration(), ADC_Init(), ADC1_Read_Chan() and update_LEDs(), which works fine.

 

1) My question is how to set the ADC sampling rate? I want to implement the 'oversampling' method into my project but couldn't find where to set. Let's say I want to manually set the ADC sampling rate at 20KHz, and the incoming analog signal is 10KHz.

 

2) Also the example project only reads and stores the latest value of the ADC conversion result, how to store and monitor the entire ADC conversion result(continuously)? Is there a way to monitor the ADC conversion result in real-time or store it somewhere so I can check it later? 

 

 

Reference Codes from the Example:

 

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 = 1; /* 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 (void) { /* Read conversion results */
   Result= ADC_1.CDR[8].B.CDATA; /* Read channel 9 conversion result data */
   ResultInMv = (uint16_t) (ADC_VREF*Result/0xFFF); /* Conversion in mV */
}

 

void ADC1_Calibration(void) { /* Calibrate to compensate for variations. Steps below are from reference manual */
   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 update_LEDs(void) { /* Update LEDs with scaled channel 9 Result */
   SIUL2.GPDO[PA4].R = ~(Result & 0x0800)>>11;/* LED1: scaled channel 9 LSB */
   SIUL2.GPDO[PA0].R = ~(Result & 0x0400)>>10;/* LED2 */
   SIUL2.GPDO[PJ4].R = ~(Result & 0x0200)>>9; /* LED3 */
   SIUL2.GPDO[PH5].R = ~(Result & 0x0100)>>8; /* LED4 */
   SIUL2.GPDO[PC4].R = ~(Result & 0x0080)>>7; /* LED5 */
   SIUL2.GPDO[PH13].R = ~(Result & 0x0040)>>6;/* LED6 */
   SIUL2.GPDO[PA7].R = ~(Result & 0x0020)>>5; /* LED7 */
   SIUL2.GPDO[PA10].R = ~(Result & 0x0010)>>4; /* LED8: scaled channel 9 MSB */
}

Outcomes