ADC VALUES

Hi,

I'm trying to give ADC INPUT value which is very less the range of values are from -0.098v to 0.09v

When I was giving the value -0.098v, I was able to get the output value as 98 or 101 as my adv_to_mv value. But when I try to give adc input as 0.055v the output, I'm getting is value 8. When I try to give adc input as 0 I was getting 8 itself .so is there any way that I can give adc input as 0.05 and get corresponding output value.

static uint16_t gpadc_read(void)
{
    /* Initialize the ADC */
    adc_config_t adc_cfg =
    {
        .input_mode = ADC_INPUT_MODE_SINGLE_ENDED,
        .input = ADC_INPUT_SE_P0_7,
        .smpl_time_mult = 2,
        .continuous = false,
        .interval_mult = 0,
        .input_attenuator = ADC_INPUT_ATTN_NO,
        .chopping = false,
        .oversampling = 0,
    };
    adc_init(&adc_cfg);

    /* Perform offset calibration of the ADC */
    adc_offset_calibrate(ADC_INPUT_MODE_SINGLE_ENDED);

    adc_start();
    uint16_t result = adc_correct_sample(adc_get_sample());
    adc_disable();

    return (result);
}

  • Hi FEMY,

    Thank you for posting your question online.
    Let me try to recreate this and I will get back to you as soon as possible.

    Best Regards,
    OV_Renesas

  • Hi,

    I would like to know whether you were able to recreate this. Because I'm stuck in this point. Can't find the reason why the reading changes even applying adc input 0.

  • Hi Femy,

    Thank you for the reply and apologies for the delay.
    I was able to recreate this issue at 10mV (and any lower value). 
    I am able to see the expected mV value for 55mV. 
    For instance, for 25.3mV I can see:

    Please also refer on the DA14531 Datasheet, on section 27.2.1 Input Channels on page: 148

    On the gpadc_sample_to_mv function we use the as reference the LDO (which is specific for ADC) voltage , 900mV but we also scale based in input attenuation. This is done based on the GP_ADC_CTRL2_REG register and you can set the attenuator voltage range based on the Datasheet and the definitions on da14531.h file

    static long gpadc_sample_to_mv(long sample)
    {
        /* Resolution of ADC sample depends on oversampling rate */
        long adc_res = 10 + ((6 < adc_get_oversampling()) ? 6 : adc_get_oversampling());
    
        /* Reference voltage is 900mv but scale based in input attenation */
        long ref_mv = 900 * (GetBits16(GP_ADC_CTRL2_REG, GP_ADC_ATTN) + 1);
    
        return (long)((((long)sample) * ref_mv) >> adc_res);
    }
    
    
    /*===========================================================================*/
    /* memory map GPADC */
    /*===========================================================================*/
    
    
    
    #define GP_ADC_CTRL2_REG                     (0x50001502) /* General Purpose ADC Second Control Register */
    #define GP_ADC_CTRL2_REG_RESET               (0x00000210)
    
    /*=============================*/
    struct __GP_ADC_CTRL2_REG
    /*=============================*/
    {
        volatile uint16_t BITFLD_GP_ADC_ATTN                       : 2;
        volatile uint16_t BITFLD_GP_ADC_I20U                       : 1;
        volatile uint16_t BITFLD_GP_ADC_OFFS_SH_EN                 : 1;
        volatile uint16_t BITFLD_GP_ADC_OFFS_SH_CM                 : 2;
        volatile uint16_t BITFLD_GP_ADC_CONV_NRS                   : 3;
        volatile uint16_t BITFLD_GP_ADC_SMPL_TIME                  : 4;
        volatile uint16_t BITFLD_GP_ADC_STORE_DEL                  : 3;
    };
    #define GP_ADC_ATTN                           (0x0001) //(0x0003)
    #define GP_ADC_I20U                           (0x0004)
    #define GP_ADC_OFFS_SH_EN                     (0x0008)
    #define GP_ADC_OFFS_SH_CM                     (0x0030)
    #define GP_ADC_CONV_NRS                       (0x01C0)
    #define GP_ADC_SMPL_TIME                      (0x1E00)
    #define GP_ADC_STORE_DEL                      (0xE000)
    
    



    Best Regards,
    OV_Renesas