# test own power

By ducksrule

May 3, 2012

May 3, 2012

i have seen it done before and looked around but the only things i can find are voltage dividers and op amps. i am thoroughly confused and just want to make a picaxe monitor its own battery

any help would be appreciated

thanks

## You can use a voltage

You can use a voltage divider (two resistors) to pull the voltage down to a usable level. Take that voltage to a ADC pin and monitor it.

## If your PICAXE is running

If your PICAXE is running off a voltage regulator then the maximum voltage you can measure will be just below 5V, or whatever your regulator puts out.

To measure the battery voltage run the supply from the batteries through a voltage divider to bring it down into the measurable range - a 50/50 voltage divider with total resistance >=20k would be a suitable choice. Feed the output of the voltage divider to an analog input. The battery voltage is then ((analog reading)/255)*(regulator voltage)*2... assuming 8bit ADC resolution on your model of PICAXE.

If your batteries feed the PICAXE directly, then the maximum voltage of your ADC will drift as the battery voltage decreases. To get around this you can use a different reference voltage for the top of the ADC range.

Take a look at the 'adcconfig' command in the PICAXE manuals to get an idea of how this works. Once you've got a solid analog voltage reference set up the process is the same as above, except you'll replace 'regulator voltage' with your chosen reference voltage in the calculations.

## Thanks

## No, you adjust the resistors

No, you adjust the resistors to give you the preferred voltage. Use something like this calculator

http://www.raltron.com/cust/tools/voltage_divider.asp

Say with a 9V input voltage you can use a 800 ohm and a 1000 ohm resistor to give you 5V as probably would be the ADC max. Then as the voltage of the 9V battery goes down the output voltage will drop linear. So when the input voltage is at 8V the output will be 4.4V

## CALIBADC is the key.

Try this on an M2 series chip. The constant will be different for X1 / X2 chips. W1 is the voltage in centi-volts. You can do this with any Picaxe which supports the CALIBADC command - See manual 2 P42.

#picaxe 08m2

do

CalibAdc10 w0

w1 = 52378 / w0 * 2

debug

pause 500

loop

The problem with READADC is that the result is so many 256ths of the supply voltage, so READADC on the supply voltage itself will always return 255. CALIBADC measures the fixed voltage reference (1.024V on an M2 series chip) and from that value you can calculate what 1/256th would be, and hence what 256 256ths (the supply voltage) would be.

Easy with floating point maths but of course the Picaxe is 16 bit integer only, so the 52378 and *2 is to scale the result while keeping maximum resolution. Also it uses CALIBADC10 to return a 10 bit value instead of 8 bit for increased resolution.

(I'm assuming above that you are trying to measure the actual Picaxe supply voltage. If you want to measure a voltage higher than this you will need a potential divider as already mentioned.)

## So if i have a voltage

## old topic

this forum topic is quite old but the project has sprung forward

only really posting this to bring this back to life and see if anyone can just confirm my question below