One way would be to use a voltage divider on the battery pack so when it reaches 3.6 the divider returns 2.8.
One way would be to use a voltage divider on the battery pack so when it reaches 3.6 the divider returns 2.8.
Dave
Always wear safety glasses while programming.
If you set Vref to Vdd and read the A/D, you will find that the constant 2.8V will give you an A/D count of LARGER than 716 when the battery voltage drops below 4V. No resistors needed.
Charles Linquist
What setting of ADCON1 should I choose and what to connect where? I need maximum number of PortA pins as digital. Thanks
I think you can read the datasheet as far as ADCON1 goes.
Most PICs let you choose between two sources of Vref. You can choose AN3 or Vdd. If you choose AN3, then you must connect a reference voltage to that pin. All A/D readings will be compared against that reference.
If the reference is 3.0V the a 10 bit A/D will read 3.0V on any other A/D input as 1023. The "count" (1023) is equal to (input/reference) * ((2^10) - 1).
If you apply 2.0V to an A/D input, and the reference is 3.0V, the count will be 2/3 * 1023 = 682.
Everything is compared AGAINST the reference.
If you set Vdd as your reference, then every A/D conversion will be compared to Vdd.
Since your external chip puts out a constant 2.8V, if Vdd (the reference) is 5.0V then the A/D will output 2.8/5 * 1023 = 573
If Vdd drops to 4.0V, then the A/D will output 2.8/4 * 1023 = 716
If Vdd drops even further, the A/D output will go higher than 716
If you set
Charles Linquist
Additionally, if you have any other voltages to measure, connect your 2.8V to AN3. You can change Vref on the fly. Set Vref to AN3, and you can measure the other voltages accurately without regard to the battery voltage. Then set Vref to Vdd and measure the battery voltage, switch it back and measure your other voltages...
I use this technique often when reading absolute voltages (which must be compared against a constant reference) and ratiometric sensors, whose output varies as a percentage of their supply voltage (such as Hall-effect current sensors).
Charles Linquist
Thanks Charles. Points noted. Very useful information. I am going to go ahead and try to play with Analog settings a little. Thanks again.
Just a quick question to re-confirm my understanding.
I will be using a 3V fixed voltage regulator for my PIC. Now I just to know that, If the setting of ADCON1 can be "1110" ?
I am planning to use supply voltage as reference and by using a voltage divider, send the battery voltage to PortA.0.
PIC is - 16f877a
Bookmarks