cancel
Showing results for 
Search instead for 
Did you mean: 

VREFINT Measurement Issue in STM32L

gilt
Associate
Posted on January 11, 2014 at 17:28

Hello

I am trying to implement indirect voltage measurement in a battery operated application.

Our MCU supports VREF+ and VREF+ is derived from the battery voltage.

Therefore - VREFINT must be used to extract VREF+.

The trouble is I keep getting a wrong digital value when measuring VREFINT via ADC (I get a digitized value of around 600 for the first measurement and from the second measure and forth I receive a value around 1400).

Thus the VREFINT I get is ~1.12V (when neglecting the first measurement).

VREF+ is stable at 3.3V during the measurements.

The ADC is configured to a sampling time of 384 cycles 

The code for indirect VREF+ measurement is based on AN3964 (see below).

Please be so kind to share your thoughts as to why the ADC measurement deviates.

Thank you very much

/Gil

void Indirect_Input_BatterySampling( void )

{

    static  U16       val_vrefint;   //for vref int (1.2 volt via channel17

    static  U16       val_bat_mon;         // bat volt in units via adc

    static  U32       v_bat;               // bat in volt 

    static  U32       vref_plus;

//    For Indirect VREF+ calculation

    while((PWR->CSR & PWR_CSR_VREFINTRDYF) == RESET)

    {

    }

    ADC_TempSensorVrefintCmd(ENABLE);                                        // ENABLE VREFINT

    val_vrefint = Adc_GetAdcValue ( ADC_Channel_17 ); // Measured value of VREFINT via ADC.

    val_bat_mon = Adc_GetAdcValue (ADC_BATTERY ); 

    vref_plus = (vrefcal*3*10000) / val_vrefint;

    

    v_bat = ((val_bat_mon * vref_plus) / 4096) * 2;

}

 

#stm32l #vrefint
1 REPLY 1
gilt
Associate
Posted on January 12, 2014 at 21:18

The problem was found and fixed.

The ADC initialization to 384 sampling cycles was rewritten by a redundant command back to 4 cycles thereby causing a faulty measurement.