I'm getting strange behavior with this NiMH battery charger circuit where it will start charge even with no battery inserted. It worked fine for months but a couple days ago started with this problem. I haven't yet removed the circuit board from the charger to debug and see what the ADC is doing, but I've seen similar problems and had it work by simply replacing the Picaxe. The supply voltage is supposed to be 5V but I have seen about 5.2V from the power supply. Either that is causing damage over time, or perhaps the battery positive connection to the ADC pin needs something to remove possible spikes. I have the 22K resistor there for that purpose, but that may not be working the way I think.
Code:
Code:
Code:
init:
setfreq m32
symbol battery = c.1
symbol currentsns = c.4
symbol pwmoutput = c.2
symbol led = c.0
symbol current = w0
symbol currentcount = w1
symbol currentsum = w2
symbol dutycyc = w3
symbol voltcount = w4
symbol volts = w5
symbol voltavg1 = w6
symbol voltsum = w7
symbol peakvolt = w8
symbol deltapeak = w9
symbol modulus = w10
symbol highvolt = w11
dutycyc = 0
current = 0
currentcount = 0
currentsum = 0
voltcount = 0
volts = 0
voltavg1 = 0
voltsum = 0
peakvolt = 0
deltapeak = 0
pwmout pwmoutput, 200, dutycyc
low led
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
toggle led
pause 1000
pause 16000
start:
gosub battdetect
main:
for voltcount = 0 to 199
modulus = voltcount // 5
if modulus = 0 then
toggle led
endif
current = 0
gosub getcurrent
if current < 125 then
dutycyc = dutycyc + 1 max 900
endif
if current > 125 then
dutycyc = dutycyc min 1 - 1
endif
pwmduty pwmoutput, dutycyc
next voltcount
gosub getvolts
if volts < 100 then init
if volts > peakvolt then
peakvolt = volts
deltapeak = 0
endif
if volts <= peakvolt then
inc deltapeak
endif
if deltapeak > 5 then endchg
debug
goto main
getcurrent:
fvrsetup FVR2048 ; set to 2.048V
adcconfig %011
current = 0
currentcount = 0
currentsum = 0
for currentcount = 0 to 49
pause 7
current = 0
readadc10 currentsns, current
currentsum = current + currentsum
next currentcount
current = currentsum / 50
return
getvolts:
fvrsetup FVR4096 ; set to 4.096V
adcconfig %011
volts = 0
voltsum = 0
voltavg1 = 0
pwmduty pwmoutput, 0
pause 8000
for voltavg1 = 0 to 19
readadc10 battery, volts
voltsum = volts + voltsum
next voltavg1
volts = voltsum / 20
pwmduty pwmoutput, dutycyc
return
battdetect:
dutycyc = 500
pwmduty pwmoutput, dutycyc
gosub getvolts
if volts < 100 then start
dutycyc = 0
return
endchg:
pwmduty pwmoutput, 5
high led
pause 8000
gosub getvolts
if volts < 100 then
goto init
endif
pwmduty pwmoutput, 0
pause 24000
debug
goto endchg