Daily timer
I'm trying to schedule a cooler to come on and turn off at a set time of day. My code keeps blowing by my if statement and going to the else and turning it off. Can anyone give me a hint or point me at a good sample of code? The week day or weekend selection works ok. This is the section of code where I'm having the problem.
Pub Timer
Time_total := ((hour*60)+minute)
Wkdystrt_total := ((Wkdy_hrstart*60)+Wkdy_minstart)
Wkdystp_total := ((Wkdy_hrstop*60)+Wkdy_minstop)
Wkndstrt_total := ((Wknd_hrstart*60)+Wknd_minstart)
Wkndstp_total := ((Wknd_hrstop*60)+Wknd_minstop)
case dow
1,7: Wknd_Timer
2,3,4,5,6: Wkdy_Timer
Pub Wkdy_Timer
WkdyT_status:= 1
If (Time_total => Wkdystrt_total) 'and (Time_total <= Wkdystp_total)
Control_logic '(go to control logic)
Else
cogstop(Relay_cog~ -1)
Relay_cog := cognew( Cooler_off,@ Relay_Stack)+1
Loop
Pub Wknd_Timer
WkndT_status:= 1
If (Time_total => Wkndstrt_total) and (Time_total <= Wkndstp_total)
Control_logic '(go to control logic)
Else
cogstop(Relay_cog~ -1)
Relay_cog := cognew( Cooler_off,@ Relay_Stack)+1
Loop

Comments
WkndT_status:= 1 If (Time_total => Wkndstrt_total) and (Time_total <= Wkndstp_total) Control_logic '(go to control logic)Should be:WkndT_status:= 1 If (Time_total => Wkndstrt_total) and (Time_total [COLOR="#FF0000"]=<[/COLOR] Wkndstp_total) Control_logic '(go to control logic)That's why nowdays I never use the "less/greater than or equal to" operator, I just use the "less/greater than" operator. It makes it easier on my head, and I don't have to worry about it.
If you must think about it, then the easiest way (for me) is to remember things like "+=" and "-=", where the operator is on the left side, and the assignment is on the right.
Pub Timer Lcd.init(Lcd_Pin, 19200,4) ' Lcd.backlight(true) 'turn backlight on Lcd.cursor(0) 'turn cursor off Lcd.cls 'Clear screen, move cursor to 0,0 Lcd.str(string("Timer test")) 'output a startup message waitcnt(clkfreq * 5 + cnt) WkdyT_status:= 0 WkndT_status:= 0 dow := 1 'day of week 1-7 Time_total := 631 '1031am '0-1440 ((hour*60)+minute) Wkdystrt_total := 630 '((Wkdy_hrstart*60)+Wkdy_minstart) Wkdystp_total := 635 '((Wkdy_hrstop*60)+Wkdy_minstop) Wkndstrt_total := 630 '((Wknd_hrstart*60)+Wknd_minstart) Wkndstp_total := 635 '((Wknd_hrstop*60)+Wknd_minstop) repeat Lcd.cls Lcd.gotoxy(0,0) Lcd.str(string("Wkdy Timer ")) Lcd.decx(WkdyT_status,2) Lcd.gotoxy(0,1) Lcd.str(string("Wknd Timer ")) Lcd.decx(WkndT_status,2) Lcd.gotoxy(0,2) Lcd.str(string("Timer Works ")) Lcd.decx(Timer_works,2) Lcd.gotoxy(0,3) Lcd.str(string("Timer Sucks ")) Lcd.decx(Timer_sucks,2) waitcnt(clkfreq*3 + cnt) Lcd.cls Lcd.gotoxy (0,0) Lcd.str(string("Time Total ")) Lcd.decx(Time_total,4) Lcd.gotoxy(0,1) Lcd.str(string("WkdyStart T ")) Lcd.decx(Wkdystrt_total,4) Lcd.gotoxy(0,2) Lcd.str(string("WkdyStop T ")) Lcd.decx(Wkdystp_total,4) waitcnt(clkfreq*3 + cnt) Lcd.cls Lcd.gotoxy (0,0) Lcd.str(string("Time Total ")) Lcd.decx(Time_total,4) Lcd.gotoxy(0,1) Lcd.str(string("WkndStart T ")) Lcd.decx(Wkndstrt_total,4) Lcd.gotoxy(0,2) Lcd.str(string("WkndStop T ")) Lcd.decx(Wkndstp_total,4) waitcnt(clkfreq*3 + cnt) case dow 1,7: Wknd_Timer 2,3,4,5,6: Wkdy_Timer Pub Wkdy_Timer WkdyT_status:= 1 If (Time_total => Wkdystrt_total)and (Time_total =< Wkdystp_total) Timer_works :=1 cogstop(Relay_cog~ -1) Relay_cog := cognew( Wet_high,@ Relay_Stack)+1 Else Timer_sucks :=1 cogstop(Relay_cog~ -1) Relay_cog := cognew( Dry_high,@ Relay_Stack)+1 Pub Wknd_Timer WkndT_status:= 1 If (Time_total => Wkndstrt_total) and (Time_total =< Wkndstp_total) Timer_works :=1 cogstop(Relay_cog~ -1) Relay_cog := cognew( Wet_low,@ Relay_Stack)+1 Else Timer_sucks :=1 cogstop(Relay_cog~ -1) Relay_cog := cognew( Dry_low,@ Relay_Stack)+1Anyway, it looks like you are stopping and starting the Wet/Dry_high/low cog every 9 seconds (every time through the loop)? Why the constant restarting and starting? There is also a bug: the first time through the loop, when Relay_cog = 0, it tries to stop cog -1.
For your stop time before start time issue, you would need to add another case (or condition) to your if statements. Something like:
if (wkdystrt_total > wkdystp_total AND (time_total >wkdystrt_total OR time_total<wkdystop_total) ) Timer_works = 1 ...