BeanieBots
Moderator
This is a very simple and basic battery capacity meter.
It uses the volt-drop of the 0v line as a current sense and an analog integrator to avoid 'lost' current signals.
After calibration it should be OK for about 3% accuracy.
I've included a circuit description but feel free to ask if you have any questions.
The code is crude and could be optimised but it fits an 08M and does the job.
I've tarted up the diagram and since since the original so appologies if any errors have crept in.
Enjoy.
It uses the volt-drop of the 0v line as a current sense and an analog integrator to avoid 'lost' current signals.
After calibration it should be OK for about 3% accuracy.
I've included a circuit description but feel free to ask if you have any questions.
The code is crude and could be optimised but it fits an 08M and does the job.
I've tarted up the diagram and since since the original so appologies if any errors have crept in.
Enjoy.
Code:
'08M based battery capacity meter
'by BeanieBots Sep2007
symbol TicksPer_10mAHr=21 'adjust accordingly to suit Rsense
symbol IntegratorMaxV=822 'resets integrator @ ~4v
symbol ResetPulse=71 'resets to ~1v (reducing value will increase mAHr rate)
symbol BatterySize=3800 'Battery capacity in mAHr/10 (eg 3800=38AHr)
symbol Adjustment=38 'Amount each button press decreases capacity (typ Ahr*10)
symbol FSD=963 'PWM value that gives full meter deflection with pwmout 2,255,FSD
symbol IntegratorV=W0 'Raw output voltage of integrator
symbol Capacity=w1 'remaining battery capacity mAHr/10
symbol TickCounter=b6 'number of integrator resets per 10mAHr.
symbol MeterReading=w2 'PWM value to drive meter
symbol UpDown=b7 'Push button drives up or down
Capacity=BatterySize 'initialise reading to 100%
main:
readadc10 4,w0
if IntegratorV > IntegratorMaxV then
pulsout 1,ResetPulse
gosub UpdateCapacity
endif
MeterReading=Capacity/10*96/38 'adjust values for your meter
pwmout 2,255,MeterReading 'ideally Capacity*FSD/BatterySize but watch for overflow
If pin3=0 then gosub AdjustCapacity
goto main
UpdateCapacity:
If Capacity>0 then
TickCounter=TickCounter+1
if TickCounter=TicksPer_10mAHr then
Capacity=Capacity-1
TickCounter=0
endif
endif
return
AdjustCapacity:
pause 100
If pin3=0 then
capacity=capacity-Adjustment max BatterySize
else
return
endif
Return
Attachments
-
18 KB Views: 832
-
6.8 KB Views: 399