S128 ADC voltage reference

Hello,

We are developing an application that must monitor the battery remaining.

For this purpose, the AN008 channel is used to obtain an ADC conversion.

The voltage reference is the 3.3V from the VCC. Is that right?

Is is possible to configurate the S128 to  get a reference more stable (for example from the VREFH0 pin)?

I tried to configure it from the Peripherals->Analog:ADC->ADC but nothing change. Neither this post with a "possible solution" change the values.

 

For more information, with a 1.8V (we use a divisor to reduce the range) in the pin P0_13 (AN008) the value read is more less 0x22FF.

 

Thanks for advance.

Ismael.

 

 

  • Have you tried running 1.8V into the AVCC pin, physically?

    It should show up in the "Other Pins " section when in the "Pins" configuration tab. This will show you where to connect the 1.8V to.
  • In reply to gregk:

    Only do as gregk suggests if you plan on running your entire system at 1.8V

    From the electrical specs, AVcc must equal Vcc

    VCC = AVCC0 = VCC_USB = VCC_USB_LDO = 2.7 to 5.5 V
  • In reply to Richard:

    No, I want to run the whole system at 3.3V but from a power supply of 3.6V (standard battery) so to approximate the live time remaining we want to get the voltage of it using the ADC.
  • Ismael,

    In the pin configuration tool, have you enabled AN05 & AN06?
    This will configure P010 & P011 (the VRefH & VRefL pins) for Analogue function in the PFS registers


    Then, use the code in the post that you refer to.

     

    /* HAL-only entry function */
    #include "hal_data.h"

    ssp_err_t ssp_err;

    void hal_entry(void)
    {
        /* TODO: add your own code here */

        adc_instance_ctrl_t * lp_ctrl;       /* local pointer to ADC control instance */
        R_S14ADC_Type * lp_adc0;             /* local pointer to ADC register */

        ssp_err = g_adc0.p_api->open(g_adc0.p_ctrl, g_adc0.p_cfg);
        if(SSP_SUCCESS != ssp_err)
        {
            __BKPT(1);
        }

        ssp_err = g_adc0.p_api->scanCfg(g_adc0.p_ctrl, g_adc0.p_channel_cfg);
        if(SSP_SUCCESS != ssp_err)
        {
            __BKPT(1);
        }

        /* Initialise the pointers to access the ADC0 control / config */
        lp_ctrl = g_adc0.p_ctrl;
        lp_adc0 = lp_ctrl->p_reg;

        /* Enable VREFH0 and VREFL0 functionality
         * This is done via the A/D High-Potential/Low-Potential Reference Voltage Control Register (ADHVREFCNT)
         */
        /* Set High-Potential Reference Voltage Select */
        lp_adc0->ADHVREFCNT_b.HVSEL = 1;        /* 0 0: AVCC0 is selected as the high-potential reference voltage
                                                 * 0 1: VREFH0 is selected as the high-potential reference voltage
                                                 * 1 0: Internal reference voltage is selected as the high-potential reference voltage
                                                 * 1 1: Internal node discharge (no reference voltage pin is selected)
                                                 */

        /* Low-Potential Reference Voltage Select */
        lp_adc0->ADHVREFCNT_b.LVSEL = 1;        /* 0: AVSS0 is selected as the low-potential reference voltage
                                                 * 1: VREFL0 is selected as the low-potential reference voltage.
                                                 */

        while(1);

    }


    When the code is run, it can be seen in the I/O register view that the registers are now configured correctly.

     

    Can you verify what I/O register settings you are getting when you configure the pins and registers?

     

    Regards,

    Richard

  • In reply to Richard:

    Hello Richard,

    I think I forgot to enable the AN05 and AN06 :'(

    Thanks so much for your answer, It solve my doubt.