cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072 battery reading

giulio
Associate II
Posted on November 04, 2016 at 00:59

Hi All

I have the attached circuit and I need to read the battery level using ADC_IN18. I have the following instructions:

Init:

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;

  ADC_Init(ADC1, &ADC_InitStructure);

///// other stuffs ///

ADC_AutoPowerOffCmd(ADC1, ENABLE);//Enables or disables the ADC Power Off.

ADC_VbatCmd(ENABLE);

/* Start ADC1 Software Conversion */

ADC_StartOfConversion(ADC1);

/* Wait until ADC end of conversion */

while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET) {}

/* Read ADC conversion result */

V_Value = ADC_GetConversionValue(ADC1);

I'm getting the value 2072 +/- 4

This value I'm getting whether the battery is charged or empty. 

Can someone help understand and solve it ? I'm not fw programmer, this just fall over me because our guy is sick and I need to deliver this project.

Any help welcome.

Thanks

#battery #adc #stm32f072
2 REPLIES 2
Posted on November 04, 2016 at 02:49

As both VBAT and VDDA are connected you are basically measuring a voltage against itself. ie VDDA (VREF) is full scale

You'd need to measure VREFINT the internal reference voltage, and use that to scale your measurement into a voltage. It should nominally be 1.2V, but there is calibration data, review

http://www.st.com/content/ccc/resource/technical/document/datasheet/cd/46/43/83/22/d3/40/c8/DM00090510.pdf/files/DM00090510.pdf/jcr:content/translations/en.DM00090510.pdf

.

If you get X for the internal reference, then VDDA = (4096 / X) * 1.2

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
giulio
Associate II
Posted on November 04, 2016 at 03:03

Thank you very much for your reply.

So if I understood, I need the value of: 

VREFINT_CAL (0x1FFF F7BA - 0x1FFF F7BB) 

to get calibrated value and then:

val_vrefint = Adc_GetAdcValue ( ADC_Channel_17 ); 

VDDA = (4096 /

val_vrefint

) * VREFINT_CAL

Right ?

Thank you