2016-11-03 04:59 PM
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 #stm32f0722016-11-03 06:49 PM
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 . If you get X for the internal reference, then VDDA = (4096 / X) * 1.22016-11-03 07:03 PM
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_CALRight ?Thank you