File IO write causes reset
Posted: Sun Nov 04, 2018 11:04 am
Hi all I am have an issue with a reset when the file IO write command is issued. I am using an ESP-07 ( mostly because of the external antenna connection ) for an engine driven off grid solar backup charger. I like to keep track of engine hours so I use the micro controller to add a time constant each time the engine running is detected. All of this works great, my problem is I like to store the accumulated engine run time in a file called hours.dat. This allows the engine hours to be retained in the case of a power down reset of the controller. The file write command writes the engine hours multiplied by 10 ( this allows me to preserve the hours down to tenths ). About half of the time when the file write command is issued it resets to ESP-07. This causes the loss of the accumulated engine run time and stops the execution of the program short of the auto oil change cycle. I will post my code so you can review, I am using version 3 alpha 69. BTW Mike great job on this firmware!
Code: Select all
memclear
udpbegin 7531
io(po,16,0) 'Gas Valve & Ignition
io(po,5,0) 'Starter Solenoid
io(po,4,0) 'Alternator Control
io(po,14,0) 'Alternator High Charge
io(po,12,0) 'Oil Change Pump Fill
io(po,13,0) 'Oil Change Pump Empty
io(pi,3) ' Engine Running Input
delay 100
overcrank = 0
normal = 0
high = 0
starttimer = 0
stoptimer = 0
starthour = 0
oilchange = 0
R = 0
T = 0
reset = " "
system = "Auto"
hourmeter = read.val(hours)
hourmeter = hourmeter / 10
starthour = hourmeter
time.setup(-6,-5)
[status]
cls
R = io(pi,3)
analog = io(ai)
voltage = analog * .029
udpwrite "192.168.10.240", 10000, str(voltage * 10)
celsius = temp(0)
if celcius > -60 then oiltemperature = (celsius * 1.8) + 32
round(oiltemperature)
celsius1 = temp(1)
if celcius1 > -60 then alternatortemperature = (celsius1 * 1.8) + 32
round(alternatortemperature)
wprint "Daveco Engine Charge Controller APU#1 "
wprint "<br>"
wprint "System Control "
dropdown system, "Auto,Manual Start,Off"
wprint "<br>"
wprint "OverCrank Reset "
dropdown reset, "Reset"
if reset = "Reset" then gosub [clearovercrank]
wprint "<br>"
wprint "<hr>"
wprint "Update Time = "
wprint time("hour")
wprint ":"
wprint time("min")
wprint "<br>"
wprint "Engine Total Hours = "
wprint hourmeter
wprint "<br>"
wprint "Battery Bank Voltage = "
wprint voltage
wprint "<br>"
wprint "<br>"
wprint "Crankcase Temperature = "
wprint oiltemperature
wprint " F "
wprint "<br>"
wprint "<br>"
wprint "Alternator Temperature = "
wprint alternatortemperature
wprint " F "
wprint "<br>"
wprint "<br>"
if R = 0 then wprint "Engine is Stopped "
if R = 1 then wprint "Engine is Running "
wprint "<br>"
wprint "<br>"
if R = 0 and overcrank = 1 then wprint "Engine Overcrank "
if R = 1 and normal = 0 and high = 0 then wprint "Cold Engine Delay "
if R = 1 and normal = 1 and high = 0 then wprint "Bank is Charging at Normal Rate "
if R = 1 and normal = 0 and high = 1 then wprint "Bank is Charging at High Rate "
wprint "<br>"
if starttimer > 0 then wprint "Timing for Start "
if stoptimer > 0 then wprint "Timing for Stop "
if oilchange > 0 then wprint "Engine in Maintenance Cycle "
wprint "<br>"
wprint "<br>"
wprint "<hr>"
wprint "Last / Current Cycle Time = "
wprint (hourmeter - starthour)
if voltage < 11.8 and R= 0 and overcrank = 0 and system = "Auto" then starttimer = starttimer + 1
If voltage < 11.8 and overcrank=0 and R = 0 and starttimer > 10 and system = "Auto" and oilchange = 0 then gosub [start]
if R = 0 and system = "Manual Start" and overcrank = 0 then gosub [start]
If R = 1 and oiltemperature > 55 and normal = 0 and high = 0 then gosub [normalcharge]
if voltage > 12.8 and R = 0 then starttimer = 0
if voltage > 14.0 and R = 1 and normal = 1 and (hourmeter - starthour) > 1.0 then gosub [highcharge]
if voltage < 14.0 and R = 1 then stoptimer = 0
if voltage > 14.4 and R = 1 and (hourmeter - starthour) > 3.0 then stoptimer = stoptimer + 1
if voltage > 14.4 and R = 1 and stoptimer > 20 and (hourmeter - starthour) > 3.0 then gosub [shutdown]
if voltage > 14.7 and R = 1 and (hourmeter - starthour) > 2.0 then stoptimer = stoptimer + 1
if voltage > 14.7 and R = 1 and stoptimer > 20 and (hourmeter - starthour) > 2.0 then gosub [shutdown]
If R = 0 and normal = 1 then gosub [shutdown]
if R = 0 and high = 1 then gosub [shutdown]
if R = 1 and system = "Off" then gosub [shutdown]
if R = 1 then hourmeter = hourmeter + .0038
if oilchange = 1 and oiltemperature < 125 then gosub [drain]
if oilchange = 1 and voltage < 12 then gosub [drain]
timer 10000,[status]
wait
[start]
starttimer = 0
stoptimer = 0
io(po,16,1) ' Turn on Gas Valve & Ignition
delay 5000
' Crank #1
R = io(pi,3)
if R = 0 then io(po,5,1)
delay 5000
io(po,5,0)
delay 5000
R = io(pi,3)
' Crank #2
if R = 0 then io(po,5,1)
R = io(pi,3)
if R = 0 then delay 5000
io(po,5,0)
if R = 0 then delay 5000
R = io(pi,3)
' Crank #3
if R = 0 then io(po,5,1)
R = io(pi,3)
if R = 0 then delay 5000
io(po,5,0)
if R = 0 then delay 5000
R = io(pi,3)
if R = 0 then delay 5000
R = io(pi,3)
if R = 0 then overcrank = 1
if R = 1 then overcrank = 0
if R = 1 then starthour = hourmeter
If overcrank = 1 then io(po,16,0) ' Turn off Gas Valve & Ignition for Overcrank
system = "Auto"
return
[normalcharge]
io(po,4,1)
normal = 1
return
[highcharge]
io(po,14,1)
normal = 0
high = 1
return
[shutdown]
starttimer = 0
stoptimer = 0
io(po,14,0) ' Turn off High Charge
delay 10000
io(po,4,0) ' Turn off Normal Charge
delay 10000
io(po,16,0) ' Turn off Gas Valve & Ignition
overcrank=0
normal = 0
high = 0
write(hours,hourmeter * 10)
R = io(pi,3)
if R = 1 then delay 10000
R = io(pi,3)
if R = 1 then delay 10000
R = io(pi,3)
if R = 1 then delay 10000
R = io(pi,3)
if R = 0 then io(po,12,1)
delay 40000
io(po,12,0)
oilchange = 1
return
[drain]
io(po,13,1)
delay 40000
io(po,13,0)
oilchange = 0
return
[clearovercrank]
overcrank = 0
reset = " "
return