A wierd one....any suggestions

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
 

westaust55

Moderator
An initial thought is that you may be overloading the PICAXE chip when illuminating all 8 LEDs on PortB causing the PICAXE to reset.
If Vcc = 5 Volts and assuming LED Vfwd = 2 volts then V across resistor is approx. 3 volts.

Current through resistor is 3 / 220 = 0.0136 A (13.6 mA) per LED and with the command
let pinsb=%11111111
8 LED&#8217;s illuminated the total current is ~109 mA.
Some PIC/PICAXE chips are rated for an absolute maximum total current draw of around 95 mA.

What happens if while waiting you try:

let pinsb=%10101010
pause 100
let pinsb=%01010101
pause 100
 

radiogareth

Senior Member
Spot on :) A 1000uF capacitor across the power pins stopped that and now the programme woks as intended. I guess its the 'snap load' being just enough to upset the applecart.

Case closed.....Thanks :)

Gareth
 

westaust55

Moderator
Albeit that the 8 LEDs may not be all on at the same instant for too long, I would be looking to reduce the current below the Absolute max for the chip.
Thus 250 or 270 Ohm series resistors for LEDs dropping current to around 11 mA per LED is recommended.
 
Top