2020/10/29 22:44:26
arslan43711
Hi, Hopefully you are doing good.
I am working on a project in which I have to measure the battery voltage(fully charged 5V and discharged voltage are 2.5V), I am using pic16f688. I have connected the battery pin to one of the analog pin. So ADC read 1023 all the time whatever the voltage is. I mean when the VDD is 3.3v it gives 1023 and when it 5v it gives 1023.  I know there is no fixed voltage reference in the pic16f688.
Is there any solution to this? or a way with which I measure the battery voltage while the PIC is connected to the same battery.
2020/10/30 07:46:40
Jim Nickerson
Maybe you could provide a voltage reference rather than using VDD.
Something like https://www.microchip.com/wwwproducts/en/MCP1525
2020/10/30 08:02:50
Or switch to the microchip recommended replacement PIC16F18325.  It has a fixed voltage reference.  By measuring the fixed voltage you can infer Vdd.

Are you building one of these or many?  If this is a one-off hobby project that will be used at a consistent temperature you could also use a resistor and a diode.  Use a GPIO pin to turn on the voltage, measure the voltage across the diode, then turn it back off.  You'll want to use a 5k or less resistor to limit input impedance to the ADC sampling cap.  You can measure the voltage across your diode under different battery conditions to characterize it.
2020/10/30 08:28:56
Mysil
Hi,
Or you may make your own comparision using one or two ordinary diodes in series,
and a pull-up resistor (10 kOhm) to Vdd,
The diodes connected such that they conduct current in the forward direction to Vss.
Measure the voltage at top of the diodes at connection to pull-up resistor.
With ordinary ADC voltage measurement at this point,
and Vref voltage still at Vdd, ADC measurement will be higher, when battery voltage is falling.

You may do some math, and some calibration to determine  voltage from the battery.
The result will be influenced by temperature also.

Mysil

2020/10/30 13:10:23
upand_at_them
arslan43711I have connected the battery pin to one of the analog pin. So ADC read 1023 all the time whatever the voltage is. I mean when the VDD is 3.3v it gives 1023 and when it 5v it gives 1023.  I know there is no fixed voltage reference in the pic16f688.

So why do you expect anything different?  In order to not give you 1023 it has to be compared to something else, right?  What do you want to compare it to?

Read section 8.1.3 of the datasheet over and over again until it convinces you to buy a different (modern!) PIC.
2020/10/31 11:08:22
arslan43711
I have selected this because this is available in the local market. There is no other reason,  I have selected the other micro-controller before posting this. I have posted this to get the idea of what might be the other options.
© 2021 APG vNext Commercial Version 4.5