AnsweredAssumed Answered

S32K142_AD

Question asked by 成宇 韩 on May 22, 2019
Latest reply on May 28, 2019 by Daniel Martynek

I am using the AD function of S32k142,start AD function every 50us,and collect 5 channels every time.Now, I find that the voltage of the port being collected will be pulled down.

Inside the red box,The high level voltage is pulled down to 4.1v,Under normal circumstances, the high level voltage should be 4.8v.I want to know why the voltage is pulled down and how to solve this problem.

The code:

void ADC_init(void)
{
PCC->PCCn[PCC_ADC0_INDEX] &=~ PCC_PCCn_CGC_MASK; /* Disable clock to change PCS */
PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_PCS(1); /* PCS=1: Select SOSCDIV2 */
PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable bus clock in ADC */


ADC0->SC1[0] |= ADC_SC1_ADCH_MASK;         /* ADCH=1F: Module is disabled for conversions */
                                                                                 /* AIEN=0: Interrupts are disabled */
ADC0->CFG1 |= ADC_CFG1_ADIV_MASK
                             |ADC_CFG1_MODE(1);              /* ADICLK=0: Input clk=ALTCLK1=SOSCDIV2 */
                                                                                 /* ADIV=0: Prescaler=1 */
                                                                                 /* MODE=1: 12-bit conversion */

ADC0->CFG2 = ADC_CFG2_SMPLTS(12);          /* SMPLTS=12(default): sample time is 13 ADC clks */
ADC0->SC2 = 0x00000000;                                    /* ADTRG=0: SW trigger */
                                                                                  /* ACFE,ACFGT,ACREN=0: Compare func disabled */
                                                                                    /* DMAEN=0: DMA disabled */
                                                                                  /* REFSEL=0: Voltage reference pins= VREFH, VREEFL */
ADC0->SC3 = 0x00000000;                                    /* CAL=0: Do not start calibration sequence */
                                                                                  /* ADCO=0: One conversion performed */
                                                                                   /* AVGE,AVGS=0: HW average function disabled */
}

 

void adc_test()
{
ADC0->SC1[0]&=~ADC_SC1_ADCH_MASK;                                    /* Clear prior ADCH bits */
ADC0->SC1[0] = ADC_SC1_ADCH(9);                                               /* Initiate Conversion */
while(((ADC0->SC1[0] & ADC_SC1_COCO_MASK)>>ADC_SC1_COCO_SHIFT)==0){}
adc_result=ADC0->R[0];

 

ADC0->SC1[0]&=~ADC_SC1_ADCH_MASK;                                     /* Clear prior ADCH bits */
ADC0->SC1[0] = ADC_SC1_ADCH(8);                                                /* Initiate Conversion */
while(((ADC0->SC1[0] & ADC_SC1_COCO_MASK)>>ADC_SC1_COCO_SHIFT)==0){}
adc_result=ADC0->R[0];

 

ADC0->SC1[0]&=~ADC_SC1_ADCH_MASK;                                  /* Clear prior ADCH bits */
ADC0->SC1[0] = ADC_SC1_ADCH(0x0A);                                      /* Initiate Conversion */
while(((ADC0->SC1[0] & ADC_SC1_COCO_MASK)>>ADC_SC1_COCO_SHIFT)==0){}
adc_result=ADC0->R[0];

 

ADC0->SC1[0]&=~ADC_SC1_ADCH_MASK;                                  /* Clear prior ADCH bits */
ADC0->SC1[0] = ADC_SC1_ADCH(0x0C);                                       /* Initiate Conversion */
while(((ADC0->SC1[0] & ADC_SC1_COCO_MASK)>>ADC_SC1_COCO_SHIFT)==0){}
adc_result=ADC0->R[0];

 

ADC0->SC1[0]&=~ADC_SC1_ADCH_MASK;                                   /* Clear prior ADCH bits */
ADC0->SC1[0] = ADC_SC1_ADCH(0x0B);                                       /* Initiate Conversion */
while(((ADC0->SC1[0] & ADC_SC1_COCO_MASK)>>ADC_SC1_COCO_SHIFT)==0){}
adc_result=ADC0->R[0];
}

Outcomes