Picaxe on a LiPo rechargeable battery

My latest project must run om a Lipo batterywithout internal protection circuit

Charging will be done by a chinese circuit costs €1.50 and has a protection circuit, charging the LiPo to 4.2 volts max.
That's the easy part.

Discharging is a bit more difficult because 3.0 volts is the absolute minimum voltage on a Lipo

The load is behind the protection circuit, so this won't help me. So I need to measure the voltage of the battery

I made a 1.3 volts reference voltage (20M) on pin b.3 by a resistor of 1 K through 2 diodes to ground
A signalling LED is connected to pin b.2


Measuring takes place by comparing VCC to a reference
We will use readadc10 that gives a value of 0-1023 for a voltage from 0-vcc
At VCC =4.1 volts, the value 1 stands for 0.004 volts
At VCC =3.0 volts, the value 1 stands for 0.003 volts

So at readadc10 (where the 1.3 referencevoltage is measured we will see:
at 4.1 volts: 1.3/0.004 = 325
at 3.0 volts: 1.3/0.003 = 433
at 2.95 volts 1,3/0.0028 = 450
For low voltage, I used the higher value (450) in the program
the difference is 125

Finally we get a value from 100 to 0 percent of the remaining available energy in the battery
As we reach zero, the picaxe shuts itself down until it is switched off and on again

shdn will count 100 low battery measurements before the shutdown is performed

Have fun with this.

Regards,
Erik

This goes in your main loop
Code:
                                      ;it's good practice to claim all variables used in your program
symbol batt=w1          ;Here comes the ADC reading
symbol shdn=w2         ;a treshold counter to fill
symbol tmp=w3          ;a disposable container for for-next-loops etc

main:
pause 1000			;here you put your program code 
low b.0			;switch off LED

readadc10 b.3,batt	;measure 1.3v ref to battery

if batt < 450 then		;when using in a loop you can use a counter
	shdn=shdn+1
end if
if batt > 449 then
	shdn=shdn-1
end if

;calculating a percentage from 'batt'
;next 4 lines can be omitted if not needed 
batt=batt-325		;vcc 4.1v=325 vcc=3.0v=450 (difference=125)
batt=125-batt		;offset to zero		
batt=batt*8		;make it a promillageage (0-1000)
batt=batt/10		;make it a percentage (0-100%)

; batt is representing a percentage of available energy in the battery here
; it can be used for display purposes
if shdn >200 then		;prevent counting down below zero (65535)
	shdn=0
end if

if shdn>100 then		;only after 100 low bat measurements we shut
	goto shutdown
end if


debug				;to be omitted in final version
goto main
The shutdown routine:
Code:
shutdown:				;in battery low condition this routine is hit
					;to protect the LiPo battery
	for tmp=1 to 10		;slow flash led 10 times
		high b.0		;to indicate shutdown
		pause 1000		;totally useless :-)
		low b.0
		pause 1000
	next tmp				
	sleep 0			;processor shutdown, reset by powerflip
;	hibernate 0			;better way on some picaxes
end
 
Last edited:

hippy

Technical Support
Staff member
at 3.0 volts: 1.3/0.003 = 433 (I used a bit higher value (450) in the program)
Should the value used not be lower rather than higher ? By increasing the value you allow the battery to drop below 3.0V which is what you are seeking to avoid.

It is probably better to determine the absolute voltage of the battery and act on that, rather than convert to a percentage first with the rounding errors that introduces.
 
Hippy,

Let me explain you how ADC works... hehe

I am measuring the voltage the Picaxe is running on (vcc) so, it may vary form 3.0 to 4.2 volts (btw brownout is switched off on the picaxe)

I am always measuring a 1.3 V reference (i.e. that's the voltage connected to the adc input and will not change)

in readadc10, every 'step' ,or resolution if you prefer, is vcc/1024.
Hence, resolution is higher as VCC is lower, steps are smaller and more steps 'fit in' the 1.3V reference giving a higher value

If I read your answer more carefully... (who am I to explain to you how a picaxe works... :) )
Actually, the value 450 compares to 2.95V and gives a nice value of 125 for the difference between min and max and makes the code easier to read
I will change this in the original post.

I will stick to detecting the 0% instead of the initial value of 'batt' because this will always work when other values are altered but you are right, it will be more precise so I will also change this in the example code above

Also, there is a GSM module in the circuit that will send out a low bat warning on SMS just before shutting down. By giving the picaxe a bit lower value, it will shut down after the GSM module.

Some more info on the project:
I am building a birth detector for our horse that's carrying a faul. It will be fitted on a belt, normally used to prvent a horse rolling over it's back.
Built-in are the Picaxe, an accellerometer, a GSM module and is running on a 3400mAh LiPo battery

As the horse lays on it's side the way they do when getting into labour, the angle will be detected by the accellerometer and if the horse stays in this position long enough, the GSM will be activated to call home.
A microphone is part of the GSM so you can listen in to find out what is happening around the horse.
All user interfacing will be done by just 1 flashing LED
We talked with the horse about the angle to detect and found +-15 degrees from the horizontal position should work. She agreed to this so we hope for the best.
How many horses have their own GSM to call home when needed huh? :)

I will post the complete code and schematics later on in the projects thread



rgds,
Erik
 
Last edited:
Top