radiogareth
Senior Member
The code below simulates fine, a simple AA cell tester.
Startup lights all the LEDs and then lops 15 times showing the voltage read across the cell, then drops into a 'cell-loading' loop where a Mosfet and small value resistor load the cell. It continues displaying the cell voltage
As stated, on the simulator everything is fine but on the breadboard version it keeps bouncing back to the startup loop after the first HIGH-Low of port B. What am I missing here? LEDs on port B are all via 220R resistors, running off a quality linear 5 volt PSU.
Any ideas????
'1.5V battery voltage tester
let dirsB = %11111111
let dirsC = %00000001
#define picaxe 18m2
#no_data
fvrsetup FVR2048 'set FVR as 2.048V
adcconfig %011 'set FVR as ADV Vref+, 0V Vref-
initialise:
let pinsb=%00000001
pause 200
let pinsb=%00000010
pause 200
let pinsb=%00000100
pause 200
let pinsb=%00001000
pause 200
let pinsb=%00010000
pause 200
let pinsb=%00100000
pause 200
let pinsb=%01000000
pause 200
let pinsb=%10000000
pause 200
waiting:
'debug
let pinsb=%11111111
pause 100
let pinsb=%00000000
pause 100
if pinC.2=1 then goto main
goto waiting
main:
for b2=0 to 14 'loops for 3 seconds
readadc10 c.0,w0 '10-bit ADC stored to w0
if w0<500 then let pins=%00000001 endif 'voltage below 1.0V, lowest LED on
if w0>499 and w0<550 then let pins=%00000011 endif 'voltage between 1.0V and 1.1V, lower two LEDs on
if w0>549 and w0<600 then let pins=%00000111 endif 'voltage between 1.1V and 1.2V, lower three LEDs on
if w0>599 and w0<650 then let pins=%00001111 endif 'voltage between 1.2V and 1.3V, lower four LEDs on
if w0>649 and w0<700 then let pins=%00011111 endif 'voltage between 1.3V and 1.4V, lower five LEDs on
if w0>699 and w0<750 then let pins=%00111111 endif 'voltage between 1.4V and 1.5V, lower six LEDs on
if w0>749 and w0<800 then let pins=%01111111 endif 'voltage between 1.5V and 1.6V, lower seven LEDs on
if w0>799 then let pins=%11111111 endif 'voltage above 1.6V, all LEDs on
pause 200
next b2
goto MOSFET_test
MOSFET_test: 'tests cell's ability to provide voltage under load
let pinC.0=1 'MOSFET Gate high
for b2=0 to 14 'loops for 3 seconds
readadc10 0,w0 '10-bit ADC stored to w0
if w0<500 then let pins=%00000001 endif 'voltage below 1.0V, lowest LED on
if w0>499 and w0<550 then let pins=%00000011 endif 'voltage between 1.0V and 1.1V, lower two LEDs on
if w0>549 and w0<600 then let pins=%00000111 endif 'voltage between 1.1V and 1.2V, lower three LEDs on
if w0>599 and w0<650 then let pins=%00001111 endif 'voltage between 1.2V and 1.3V, lower four LEDs on
if w0>649 and w0<700 then let pins=%00011111 endif 'voltage between 1.3V and 1.4V, lower five LEDs on
if w0>699 and w0<750 then let pins=%00111111 endif 'voltage between 1.4V and 1.5V, lower six LEDs on
if w0>749 and w0<800 then let pins=%01111111 endif 'voltage between 1.5V and 1.6V, lower seven LEDs on
if w0>799 then let pins=%11111111 endif 'voltage above 1.6V, all LEDs on
pause 200
next b2
let pinC.0=0 'MOSFET Gate low
goto waiting
Thanks, Gareth
Startup lights all the LEDs and then lops 15 times showing the voltage read across the cell, then drops into a 'cell-loading' loop where a Mosfet and small value resistor load the cell. It continues displaying the cell voltage
As stated, on the simulator everything is fine but on the breadboard version it keeps bouncing back to the startup loop after the first HIGH-Low of port B. What am I missing here? LEDs on port B are all via 220R resistors, running off a quality linear 5 volt PSU.
Any ideas????
'1.5V battery voltage tester
let dirsB = %11111111
let dirsC = %00000001
#define picaxe 18m2
#no_data
fvrsetup FVR2048 'set FVR as 2.048V
adcconfig %011 'set FVR as ADV Vref+, 0V Vref-
initialise:
let pinsb=%00000001
pause 200
let pinsb=%00000010
pause 200
let pinsb=%00000100
pause 200
let pinsb=%00001000
pause 200
let pinsb=%00010000
pause 200
let pinsb=%00100000
pause 200
let pinsb=%01000000
pause 200
let pinsb=%10000000
pause 200
waiting:
'debug
let pinsb=%11111111
pause 100
let pinsb=%00000000
pause 100
if pinC.2=1 then goto main
goto waiting
main:
for b2=0 to 14 'loops for 3 seconds
readadc10 c.0,w0 '10-bit ADC stored to w0
if w0<500 then let pins=%00000001 endif 'voltage below 1.0V, lowest LED on
if w0>499 and w0<550 then let pins=%00000011 endif 'voltage between 1.0V and 1.1V, lower two LEDs on
if w0>549 and w0<600 then let pins=%00000111 endif 'voltage between 1.1V and 1.2V, lower three LEDs on
if w0>599 and w0<650 then let pins=%00001111 endif 'voltage between 1.2V and 1.3V, lower four LEDs on
if w0>649 and w0<700 then let pins=%00011111 endif 'voltage between 1.3V and 1.4V, lower five LEDs on
if w0>699 and w0<750 then let pins=%00111111 endif 'voltage between 1.4V and 1.5V, lower six LEDs on
if w0>749 and w0<800 then let pins=%01111111 endif 'voltage between 1.5V and 1.6V, lower seven LEDs on
if w0>799 then let pins=%11111111 endif 'voltage above 1.6V, all LEDs on
pause 200
next b2
goto MOSFET_test
MOSFET_test: 'tests cell's ability to provide voltage under load
let pinC.0=1 'MOSFET Gate high
for b2=0 to 14 'loops for 3 seconds
readadc10 0,w0 '10-bit ADC stored to w0
if w0<500 then let pins=%00000001 endif 'voltage below 1.0V, lowest LED on
if w0>499 and w0<550 then let pins=%00000011 endif 'voltage between 1.0V and 1.1V, lower two LEDs on
if w0>549 and w0<600 then let pins=%00000111 endif 'voltage between 1.1V and 1.2V, lower three LEDs on
if w0>599 and w0<650 then let pins=%00001111 endif 'voltage between 1.2V and 1.3V, lower four LEDs on
if w0>649 and w0<700 then let pins=%00011111 endif 'voltage between 1.3V and 1.4V, lower five LEDs on
if w0>699 and w0<750 then let pins=%00111111 endif 'voltage between 1.4V and 1.5V, lower six LEDs on
if w0>749 and w0<800 then let pins=%01111111 endif 'voltage between 1.5V and 1.6V, lower seven LEDs on
if w0>799 then let pins=%11111111 endif 'voltage above 1.6V, all LEDs on
pause 200
next b2
let pinC.0=0 'MOSFET Gate low
goto waiting
Thanks, Gareth