i was wondering how would i go about measuring the voltage of a battery powering a PIC 16f877 via the pic's ADC? i need to keep track of the battery's power and need to detect when the battery goes bellow a certainlevel (eg under 3 volts). from what i understand the 16f877's integrated ADC can be used. can i set thins up so no other power source is needed to keep a reference voltage. I just wanna have one battery and wanna detect when its below a ceratin level.......
The pic requires a reference voltage for it's ADC, these negative and positive references will be used to compare against the measured signal.
so you need a stable voltage to be used as a reference for the adc, if you want to measure the battery powering the pic, then the reference voltage will drop along with the measured voltage... The ADC will report a full battery every time...
Do you need to measure the voltage level (e.g.: 4.8V) or is it enough just to know when a voltage level reaches a certain treshold (e.g.: falls below a certain level)? If that is the case, then you can use a comparator that would output HIGH when voltage falls low enough...
You may setup the F877's internal A/D converter to use VCC as reference. However, it is only as accurate as the VCC's value. That is, if the VCC has a tolerance of 10% (4.5V-5.5V), then the error of measuring @ 3V threashold is +/- 0.3V.