PICAXE battery voltage monitor

does anyone have an idea of how one could get a picaxe to monitor its own battery source and light an LED when the voltage drops below a certain value. I am thinking that there might be a way to do it using a ADC input. Perhaps a zener diode could be used and the voltage above its threshold could be measured.

Picture of PICAXE battery voltage monitor
sort by: active | newest | oldest

If I were you I would use the Calibadc10 command to measure the voltage of the power supply.

gmoon8 years ago
A voltage divider with the ADC will do it.

          Sample Voltage           |           R1           |ADC---------            |           R2           |           GND

Most micro ADCs have an input range dictated by their supply voltage (0-5V, or instance.) Need to sample a larger value, say 15V for your car? No problem. The voltage divider scales the sampled voltage down to an acceptable range.

Example-- to scale a sample voltage of 15V down to 5V:
R1 = 10K
R2 =5K

(or other proportional values...100K and 50K, for instance. The actual values used depends on the input Z (impedance) of the ADC. Lower resistance values will have greater current loss.)
biochemtronics (author)  gmoon8 years ago
I want to monitor the picaxe's supply voltage - not an external voltage. I tried the setup you gave but the adc did not change when I raised and lowered the picaxe's supply voltage. There has got to be a way to do this.
OK, then using the ADC exclusively (not external components) depends on the PIC--and if the PICAXE firmware is flexible enough to take advantage of the PIC's capabilites. Most micros have the option of using an internal reference voltage, for this very reason. I.E., if the micro Vcc can vary from 2.7 to 5V, then the ADC results will always be proportional to the supply voltage (the current supply voltage will be the max ADC result.) Not what you want... Some micros also have an external ADC reference voltage pin, and you can supply that reference with a regulator or Zener, as you suggested.
gmoon gmoon8 years ago
Some elaboration:

Your problem is discussed in this thread. As suspected, the ADC reference voltage is the present Vcc, so the results of an ADC read vary with the supply voltage.

They discuss two real options (basically what was outlined above):

1) use a picaxe X1 chip, which has an internal voltage reference.

2) create an external reference; although there's no external reference voltage pin (like AREF on AVRs), you can use a a separate ADC pin and track how the ADC reads the reference voltage--the reference voltage will be unchanged, but you can derive the supply voltages from how much the ADC values deviate.

They propose using the forward voltage drop of a diode as the reference voltage.

In your case, you don't even need to use two ADC channels. You're not reading an external voltage, rather your tracking changes in the ADC readings of a fixed reference voltage. I.E., the reference doesn't change, but the ADC reads change with the supply voltage...