Could I get a Script Review?
It works if I walk it through a mega and relayboard on my desk, but want a peer review before construction begins on new panel
Physical system is a 1000L Bain-Marie Jacketed still with electric heat, agitator, and a two pump and HX cooling fan units for reflux and product condensers.
BruControl is using a mega and relayboard controlling contactors and agitator(no PID or duty cycle) and stepping down power as it warms up (no hysteresis) and a couple SonOff Duals controlling the pumps and fans (actually in place now)
My experience is 10 years with BCS controlling homebrew rig and my first 100-gal still (I wanted to add 4-20mA and RTD) and recently with CBPi3(kinda worked) so that is why it is 'state machine'
Code:
new value StopTemp
new string CurrentState
StopTemp = 207
stop "CoolDownTimer"
reset "CoolDownTimer"
// Enable all devices needed
"9kW 0" Enabled = true
"9kW 1" Enabled = true
"9kW 2" Enabled = true
"9kW 3" Enabled = true
"Agitator" Enabled = true
"Bain Marie" Enabled = true
"Boiler Temp" Enabled = true
"Vapor Temp 1" Enabled = true
"Vapor Temp 2" Enabled = true
"PC Water IN" Enabled = true
"PC Water OUT" Enabled = true
"PC HX Return" Enabled = true
"RC Water IN" Enabled = true
"RC Water OUT" Enabled = true
"PC Pump" Enabled = true
"PC Fan" Enabled = true
"RC Pump" Enabled = true
"RC Fan" Enabled = true
"AlarmOut 1" Enabled = true
"Running" Enabled = true
// start the still run
[State0]
CurrentState = "Heat_36kW"
"Running" State = on
"9kW 0" State = on
sleep 1000 // pause before energizing another contactor
"9kW 1" State = on
sleep 1000 // pause before energizing another contactor
"9kW 2" State = on
sleep 1000 // pause before energizing another contactor
"9kW 3" State = on
"Agitator" State = on
goto State1
[State1]
if "Vapor Temp 1" Value >= 170 // exit to distilling state
goto State6
endif
if "Bain Marie" Value >= 240 // exit to State2 when BM temp reaches 240 (~1 Bar)
goto State2
endif
if "Bain Marie" Value >= 243 // shut off all heat if BM temp gets too high
"Alarm 1" Active = true
goto CoolDown
endif
goto State1
[State2]
CurrentState = "Heat_27kW"
"9kW 0" State = on
sleep 1000
"9kW 1" State = on
sleep 1000
"9kW 2" State = on
sleep 1000
"9kW 3" State = off
goto State3
[State3]
if "Vapor Temp 1" Value >= 170 // exit to distilling state
goto State6
endif
if "Bain Marie" Value >= 241 // exit to State4 when BM temp reaches 241 (~1 Bar)
goto State4
endif
if "Bain Marie" Value >= 243 // shut off all heat if BM temp gets too high
"Alarm 1" Active = true
goto CoolDown
endif
goto State3
[State4]
CurrentState = "Heat_18kW"
"9kW 0" State = on
sleep 1000
"9kW 1" State = on
"9kW 2" State = off
"9kW 3" State = off
goto State5
[State5]
if "Vapor Temp 1" Value >= 170 // exit to distilling state
goto State3
endif
if "Bain Marie" Value >= 241 // exit to State1 when BM temp reaches 241 (~1 Bar)
goto State6
endif
if "Bain Marie" Value >= 243 // shut off all heat if BM temp gets too high
"Alarm 1" Active = true
goto CoolDown
endif
goto State5
[State6]
CurrentState = "Distill"
"PC Pump" State = on
"PC Fan" State = on
"RC Pump" State = on
"RC Fan" State = on
if "Vapor Temp 1" Value >= StopTemp // exit to cooldown state
goto CoolDown
endif
if "Bain Marie" Value >= 243 // shut off all heat if BM temp gets too high
"Alarm 1" Active = true
goto CoolDown
endif
goto State6
[CoolDown]
CurrentState = "CoolDown"
"9kW 0" State = off
"9kW 1" State = off
"9kW 2" State = off
"9kW 3" State = off
restart "CoolDownTimer"
wait "CoolDownTimer" Value > 00:05:00 // waits until the timer exceeds 5 minutes
"PC Pump" State = off
"PC Fan" State = off
"RC Pump" State = off
"RC Fan" State = off
"Agitator" State = off
"9kW 0" Enabled = false
"9kW 1" Enabled = false
"9kW 2" Enabled = false
"9kW 3" Enabled = false
"Agitator" Enabled = false
"PC Pump" Enabled = false
"PC Fan" Enabled = false
"RC Pump" Enabled = false
"RC Fan" Enabled = false
"AlarmOut 1" Enabled = false
"Running" Enabled = false
stop "Still Run Script"
View attachment 599758