Season Switch or temperature Deadbond control

Hi dear all ,
the summer End,school is open and i back to painting!
between the season , 4 pipe AHUs need changeover switch and for example at the noontime , cold valve in action and in the nighttime hot valve in action . there is a set point and dead-bond factor . in the picture , show obviously that when temperature feedback cross (Setpoint+deadbond) , cold valve is in action and open with pid 2 , and when the temperature feedback below( Set point - deadbond) , hot valve is in action and open with pid 1 .and for the temperature inside the bond , valve action must be work in the previous stage .
in below you can see my program about this job , any idea about this ? or more simple program ?
Details : Temp is feedback , Hot_s is a switch value that hot valve in action for the temp below bounds , EXP is switch value that work inside the bond , col_s is a switch value that cold valve in action for the temp upper bounds , db is dead-bond factor

9 IF Temp <= AHU_SP-DB THEN GOSUB 120 ELSE HOT_S=0
10 IF Temp > AHU_SP+DB THEN GOSUB 130 ELSE COL_S=0
11 IF COL_S=0 AND HOT_S=0 THEN GOSUB 170 ELSE EXP=0
12 RETURN

120 HOT_S=1
140 Hotvalve= PID2
141 Coldvalv=0
122 RETURN

130 COL_S=1
160 Coldvalv= PID1
161 Hotvalve=0
132 RETURN

170 EXP=1
171 IF TIME-OFF( COL_S ) > TIME-OFF( HOT_S ) THEN GOSUB 176 ELSE GOSUB 173
172 RETURN

173 Hotvalve= PID2
174 Coldvalv=0
175 RETURN

176 Coldvalv= PID1
177 Hotvalve=0
178 RETURN

Thanks for posting Nick and I like your program, complete with a graphic even. Nice.

The only little suggestion I am thinking about is how to do this without gosubs which I like to avoid as you’ll know from my other examples.

[Update] 5 minutes later…

1 REM *** HEAT OR COOL REQUIRED ? *****
10 IF+ TEMP < AHU_SP - DB THEN START HEATREQ
20 IF+ TEMP > AHU_SP + DB THEN START COOLREQ
21 REM *** TIMERS AND MODE ***
30 HEATOFF = TIME-OFF( HEATREQ )
40 COOLOFF = TIME-OFF( COOLREQ )
50 IF HEATOFF > COOLOFF THEN START HEATMODE ELSE STOP HEATMODE
51 REM *** VALVES ***
60 IF NOT HEATMODE THEN COLDVALVE = PID1 ELSE COLDVALVE = 0
70 IF HEATMODE THEN HOTVALVE = PID2 ELSE HOTVALVE = 0

This has the slight advantage of being a little easier to follow since it avoids the gosubs. The main advantage though is the timers and modes are global variables which you can put on the user displays and trend logs for debugging later.

I really appreciate your post Nick, keep it up.