'Batery Tester - David Eather ' 'This program is to support a capacity tester for NiCd / NiMh single cells 'It produces a serial output through the normal programming socket of the 'PICAXE (4800,8,1,N) and also a voltage level (1v per Amp hour) on the PWM 'output C.2. The PWM output only supports mAH capacity to 5000mAH 'The program saves the value of the last completed test and recalls that at 'power-on (both serial output and PWM) and when the press button on C.3 is 'activated (Serial only). Activating c.3 does not disrupt the current test. 'The objective has been to get a result that is accurate to within 2-3 percent. 'It will also test standard primary cells - Zinc Carbon, Alkaline, Titanium 'for capacity and could be modified for use with lithium cells. ' 'This program produces useful results without the need to have a PC attached. 'defining symbols Symbol mA = w0 Symbol mV = w1 Symbol uAH = w2 Symbol mAH = w3 Symbol Duty = w4 Symbol R10ths = 52 'in tenths of ohms. Change this for different discharge currents 'Initialising. 'The internal pullups cannot be used on the ADC without creating large errors 'The Interrupt routine deals with presses of the button on C.3 Pullup %00001000 Setint %00000000, %00001000 'Start displays last saved result with both serial out and pwm and tests 'to see if a battery is currently connected - this is so that a discharged 'battery is not retested every time the power is turned on. Start: low c.4 read 0, word w6 Duty = w6 /5 '1 amp/Hr equals 1 volt out approx pwmout 2, 250, Duty pause 3000 sertxd ("Last completed test result was ...",#w6,"maH",13,10) Remove: readadc c.1, w5 'C.1 controls the discharge circuit. A Low turn it off pause 1000 'this and the next two lines form a simple de-bounce routine readadc c.1, w6 w5=w5+w6/2 if w5 < 200 then sertxd ("Please remove the battery...",13,10) pause 3000 goto remove endif StartNoBattWait: readadc c.1, w5 pause 1000 readadc c.1, w6 w5=w5+w6/2 if w5 < 200 then StartNoBattWait: sertxd ("Ready...",13,10) WaitForBatteryIn: do readadc c.1, w5 pause 1000 'this and the next two lines form a simple de-bounce routine readadc c.1, w6 w5=w5+w6/2 loop while w5 > 105 pwmout 2, 250, 0 pause 3000 sertxd ("Test Started...",13,10) uAH = 0 mAH = 0 'This is the start of the discharge test. Data is accumulated in uA/Hrs high c.4 'start discharge cycle do pause 3600 'wait for 1/1000 Hour readadc c.1, w5 mV = w5 * 20 'each 1 from the adc equals 20mV mA = mV * 10 / R10ths 'for maximum resolution without overflowing uAH = uAH + mA 'mA flows for 1/1000 of 1 hour 'keep track of the mA/Hrs do while uAH > 1000 mAH = mAH + 1 uAH = uAH - 1000 Duty = mAH /5 '1 amp/Hr equals 1 volt out approx pwmout 2, 250, Duty loop sertxd (#mV,"mV ",#mAH,"mA/H",13,10) loop while mV > 1000 and mV < 2000 low c.4 'stop discharge cycle write 0, word mAH sertxd ("Test Compleated.",13,10) WaitForBatteryOut: do readadc c.1, w5 pause 1000 'this and the next two lines form a simple debounce routine readadc c.1, w6 w5=w5+w6/2 loop while w5 < 200 goto Start 'This simply displays the last save result. It never interferes with anything 'else as the variable w7 is only used here. Interrupt: read 0, word w7 sertxd ("Last completed test result was ...",#w7,"maH",13,10) pause 1000 setint %00000000, %00001000 're-enable the interrupt Return