dir gpio.0 in 'a/d
dir gpio.2 in 'nimh
dir gpio.3 in 'start
dir gpio.4 out 'relay
dir gpio.5 out 'led
dim volt1 as byte
dim volt2 as byte
start:
if gpio.3 on then
set gpio.4 on 'relay
set gpio.5 on 'led
wait 1 s
if gpio.2 on then nimh
if gpio.2 off then lipo
end if
wait 255 ms
wait 255 ms
set gpio.5 on 'led
wait 255 ms
wait 255 ms
set gpio.5 off 'led
goto start
sub lipo
do
if readad10(an0) >= 156 then
set gpio.4 off 'relay
exit sub
end if
loop
end sub
sub nimh
volt1 = 0
do
volt2 = readad10(an0)
if volt2 >= volt1 then
volt1 = volt2
end if
volt2 = readad10(an0)
if volt2 < volt1 -1 then
set gpio.4 off 'relay
exit sub
end if
loop
end sub
when in the sub lipo it works great
but when in the sub nimh it is exiting the sub when the a/d reaches 156 just like in the sub lipo, and I don't know why?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok... i suposse you declared both volt1 and volt2 as word.
I think this is a battery charger and you want to detect when voltage start to go down for nimh battery.
I think you sould have a delay inside nimh sub to take readings every 1seg for example and filter this readings to avoid reading errors.
And i think you should have an infinite loop to stay when charging is complete... i think in your actual code when you exit from nimh sub you go to start again... if gpio2 is off then you will go to lipo sub... not sure but may be this.
Perhaps you need a blinking led sub (for example) to go when charging is complete.
Regards.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i did this:
sub nimh
volt1 = 0
do until gpio.4 off
volt2 = readad10(an0)
wait 1 s
volt2 = volt2 + readad10(an0)
volt2 = volt2 / 2
if volt2 >= volt1 then
volt1 = volt2
end if
volt2 = readad10(an0)
wait 1 s
volt2 = volt2 + readad10(an0)
volt2 = volt2 / 2
if volt2 < volt1 -1 then
set gpio.4 off 'relay
exit sub
end if
loop
end sub
but when it exits the sub it goes to start but the start switch is off so it just flashes the led to say it is done, so I do not know why it exits the nimh sub at the ad value of 156?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
using:
#chip 12F683, 8 'mhz
#config OSC=INTOSC, MCLRE=off, WDT=off
dir gpio.0 in 'a/d
dir gpio.2 in 'nimh
dir gpio.3 in 'start
dir gpio.4 out 'relay
dir gpio.5 out 'led
dim volt1 as byte
dim volt2 as byte
start:
if gpio.3 on then
set gpio.4 on 'relay
set gpio.5 on 'led
wait 1 s
if gpio.2 on then nimh
if gpio.2 off then lipo
end if
wait 255 ms
wait 255 ms
set gpio.5 on 'led
wait 255 ms
wait 255 ms
set gpio.5 off 'led
goto start
sub lipo
do
if readad10(an0) >= 156 then
set gpio.4 off 'relay
exit sub
end if
loop
end sub
sub nimh
volt1 = 0
do
volt2 = readad10(an0)
if volt2 >= volt1 then
volt1 = volt2
end if
volt2 = readad10(an0)
if volt2 < volt1 -1 then
set gpio.4 off 'relay
exit sub
end if
loop
end sub
when in the sub lipo it works great
but when in the sub nimh it is exiting the sub when the a/d reaches 156 just like in the sub lipo, and I don't know why?
You are using byte variables to 10 bit ADC... use 8 bit ADC:
volt2 = readad(an0)
i fixed that it is "dim volt1 as word" now, but not the problem
Ok... i suposse you declared both volt1 and volt2 as word.
I think this is a battery charger and you want to detect when voltage start to go down for nimh battery.
I think you sould have a delay inside nimh sub to take readings every 1seg for example and filter this readings to avoid reading errors.
And i think you should have an infinite loop to stay when charging is complete... i think in your actual code when you exit from nimh sub you go to start again... if gpio2 is off then you will go to lipo sub... not sure but may be this.
Perhaps you need a blinking led sub (for example) to go when charging is complete.
Regards.
i did this:
sub nimh
volt1 = 0
do until gpio.4 off
volt2 = readad10(an0)
wait 1 s
volt2 = volt2 + readad10(an0)
volt2 = volt2 / 2
if volt2 >= volt1 then
volt1 = volt2
end if
volt2 = readad10(an0)
wait 1 s
volt2 = volt2 + readad10(an0)
volt2 = volt2 / 2
if volt2 < volt1 -1 then
set gpio.4 off 'relay
exit sub
end if
loop
end sub
but when it exits the sub it goes to start but the start switch is off so it just flashes the led to say it is done, so I do not know why it exits the nimh sub at the ad value of 156?