Battery monitor when running on battery

XLSERVICE

New Member
Hi Guys

I would like to monitor the battery voltage of my Picaxe project.

The manual states that the 'reference voltage for the 'readadc' command is the supply voltage' (the same one I am measuring).

Am I correct in thinking that as the voltage drops, so does the reference and therefore the adc value would effectively not change??

What can I do to workaround this?

Cheers
Alan
 

testerrrs

New Member
1) Run the project from a 9V battery and the PICAXE from a 5V regulator. Then use a 50:50 potential divider across the 9V-0V rails and connect the junction to an ADC input.

2) There are also microcontroller supervisor ICs available, some of which can determine battery voltage.

3) Stick a 3.3V regulator in the circuit and connect the output to the ADC input. The value will vary with supply voltage.

4) If it happens to be a 28X1, the calibadc10 (I think) command can be used to determine supply voltage. However it's a bit unreliable and need calibration itself first before use (ask for some more info if required).

Hope that helps, and if you want any more details post back.
 

kranenborg

Senior Member
Hi,

There are several possibilities, each with its own cost and accuracy. An accurate one that I have applied successfully in my "Picaxe Satellite" project ( http://www.picaxeforum.co.uk/showthread.php?t=9236 ) is by using a MAX6018A Voltage Reference (1.2V output version) and connect it to a Picaxe ADC input.

The following code (written for a Picaxe-18X) then delivers the Vcc value in millivolts:

Code:
ReadBatteryVoltage:

	REM Calculate Battery level (Vcc. in mV) using Vref (1263 mV at 25 degr. C) delivered by MAX6018
	REM Only 8-bit ADC value is used, accuracy for calculated Vcc in the critical range 
	REM 	of 2.0V is approx. 10mV, for Vcc of 3.6 (maximum battery voltage) the error is approx 40mV.
	REM Calculation formula: Vcc(mV) = 1263mV (=Vref) * (255 / ADC_Vref)
	REM  			        = (1263 * 51 * 5) / ADC_Vref
	REM 			        = (64413 / ADC_Vref) * 5
	REM Note that 16 bits integer calculus is used using as large integers possible
	REM   before a division is done, in order to minimize round-off errors
	
	SYMBOL ADC_Vref = b0
	SYMBOL Vcc_Calculated = w1
	SYMBOL Pin_Vref_MAX6018 = 1     REM Voltage reference at ADC 1 input!
	
	LET Vcc_Calculated = 0
	READADC Pin_Vref_MAX6018, ADC_Vref
	LET Vcc_Calculated = 64413 / ADC_Vref
	LET Vcc_Calculated = Vcc_Calculated * 5	REM Vcc calculated in mV's
	
	RETURN
Note the way the integer arithmetic has been done in order to minimize errors; first multiply to as large numbers as possible within a 16-bit word before a division is done.

I particularly like the 1.2V Vref version of the MAX6018 because it functions at a Vcc down to 1.8V (which is about the limit of the Picaxes as well) and their power consumption is in the microamp area. Most other voltage references that I know of have both higher minimum Vcc as well as much higher power consumption, easily into the milliamps. Last but not least, the choice of Vref = 1.2V lin combination with 8-bit ADC eads during integer arithmetic to a very large multiplied value (64413) close to the 16-bit limit (65535) just before division, which implies a very accurate calculation given the restrictions of Picaxe integer arithmetic.

Note that the MAX6018 output needs to be grounded with a small capacitor for stable operation.

Hope this gives you some inspiration.

/Jurjen

EDIT: Small correction for room temperature operation (initially the application was aimed at very low temperatures with slightly lower Vref)
 
Last edited:

XLSERVICE

New Member
Thank you for the advice..
I have gone for the Calibadc option.

As the requirement for battery power was a last minute request, I did'nt want to spend the time adding a 'propper' solution like the MAX6018.

Soldering a battery output to an ADC port and editing a bit of code works fine in this case. All I am doing is triggering a warning on the LCD screen and illuminating a battery warning LED

It seems to work fine

Thank's for your efforts
Alan
 
Last edited:
Top