AnsweredAssumed Answered

ADC reference voltage monitoring

Question asked by jaewoo song on Jul 31, 2017
Latest reply on Aug 2, 2017 by Ovidiu-marius Alexandru

I have question about ADC reference voltage monitoring.

MCU : S32K144

Basically VREFH pin connected to vdd(5V)

I have tested that lower the vdd voltage to 4.8V from 5V.

I think that read value should be different in 5V, 4.8V. But I read always 4095 value about ADC reference voltage (variable name : nAdCodeVdd) in both 5V with 4.8V

 

ADC register setting & implement code as following :

 

void main(void)

{

   for(;;)

   {

      task 10ms :

      Vref_Measure();
      Vref_GetValue(nAdCodeVdd);

   }

}

 

void ADC_Init(void)
{
   /* resolution : 12bit, software trigger, votage reference : VREF */   

    ADC_DRV_ConfigConverter(INST_ADCONV1, &adConv1_ConvConfig0);    /* for cosine & Vref */
    ADC_DRV_ConfigConverter(INST_ADCONV2, &adConv2_ConvConfig0);    /* for sine */

 

    /* Enable

    SIM_HAL_SetAdcSupplyEnCmd(SIM, 1U);   /* Enable internal supply */
    SIM_HAL_SetAdcSupplySrc(SIM, 2U);     /* VREF ADC Reference monitoring */

 

    /* check register setting */
    test_enable = SIM_HAL_GetAdcSupplyEnCmd(SIM);  /* I have checked test_enable is 1U */
    test_src = SIM_HAL_GetAdcSupplySrc(SIM);              /* I have checked test_src is 2U */

 

    /* To verify ADC accuracy */
    ADC_DRV_AutoCalibration(INST_ADCONV1);  /* for cosine & Vref */
    ADC_DRV_AutoCalibration(INST_ADCONV2);   /* for sine */
}

 

void Vref_Measure(void)
{
    uint8_t Vref_SumCnt = 0;                         /* Number of measured channels */


    if (Vref_ModeFlg == STOP)     /* Is the device in different mode than "stop"? */
    {
        Vref_ModeFlg = MEASURE;                   /* Set state of device to the measure mode */
        Vref_OutFlg = FALSE;                            /* Output values aren't available */

        Vref_ClrSumV();                                      /* Clear buffer */

 

        for(Vref_SumCnt=0; Vref_SumCnt<3; Vref_SumCnt++)
        {
            convertAdcChan(INST_ADCONV1, 0U, VrefChannels[0]);    /* Start measurement of next channel */
            adc_complete(INST_ADCONV1);                                           /* Wait for conversion complete flag */
            Vref_OutV[0] += read_adc_chx(INST_ADCONV1, 0U);         /* Save measured value */
        }


        Vref_OutFlg = TRUE;                       /* Measured values are available */
        Vref_ModeFlg = STOP;                      /* Set the device to the stop mode */
    }

}

 

void Vref_GetValue(uint16_t *Values)
{
    if (Vref_OutFlg == TRUE)  /* Is measured value(s) available? */
    {
        ((uint16_t*)Values)[0] = (uint16_t)(Vref_OutV[0] / 3); /* Save measured values to the output buffer */
    }
}

Outcomes