Thanks Darrel,
I'll give it a try in the morning
Darrel,
Changed the code and it's still not functioning right.
If I set the on time as 15:00 and off time as 15:01 the led comes on at 15:01 and stays on... well past the programmed stop time... any ideas ?
Code:CheckTimes: TimeCmpFlags = 0 ; clear flags first ; if the Start and Stop times are the same, then Always OFF if (lightsetHR[fn]=timeH) AND _ (lightsetMN[fn]=timeM) then AlwaysOFF ; is it past the Start time? if (timeH>lightsetHR[fn]) OR _ (timeH=lightsetHR[fn] AND timeM >= lightsetMN[fn])then PastStart=1 ; is it past the Stop time? if (timeH>lightoffHR[fn]) OR _ (timeH=lightoffHR[fn] AND timeM >= lightoffMN[fn])then PastStop=1 ; does the period end the following day? if (lightoffHR[fn]< lightsetHR[fn]) OR _ (lightoffHR[fn]=lightsetHR[fn] AND lightoffMN[fn] < lightsetMN[fn]) then NextDay=1 if !NextDay then ; same day, use AND if PastStart AND !PastStop then ProgON = 1 else ; next day, use OR IF PastStart OR !PastStop then ProgON = 1 endif AlwaysOFF: return
Last edited by malc-c; - 27th July 2010 at 12:18. Reason: code added
OK something has really got screwed up....
Here's the menu routine which is used to set the times for the lighting
so I added the following lines to display the times on the LCD when the program is runningCode:Lighting: Lighton: Lcdout $FE,2 LCDOUT $FE,$80,"Set On Time For " IF H_butt = 0 THEN GOSUB IncHours IF M_butt = 0 THEN GOSUB IncMinutes lightsetHR[fn]=Hours lightsetMN[fn]=Minutes if viv >=2 then viv =2 LCDOUT $FE,$C0,"Light Circuit ",#viv lcdout $FE,$94,#lightsetHR[fn] DIG 1,#lightsetHR[fn] DIG 0,":",#lightsetMN[fn] DIG 1,#lightsetMN[fn] DIG 0 pause 200 If S_butt = 0 then pause 250 fn = fn +1 viv = viv+1 hours = 0 minutes = 0 endif If fn > 1 then LCDOUT $FE,1 viv=1 fn=0 goto lightoff endif goto lighton lightoff: Lcdout $FE,2 LCDOUT $FE,$80,"Set Off Time For " IF H_butt = 0 THEN GOSUB IncHours IF M_butt = 0 THEN GOSUB IncMinutes lightoffHR[fn] = Hours lightoffMN[fn] = Minutes if viv >=2 then viv =2 LCDOUT $FE,$C0,"Light Circuit ",#viv lcdout $FE,$94,#lightoffHR[fn] DIG 1,#lightoffHR[fn] DIG 0,":",#lightoffMN[fn] DIG 1,#lightoffMN[fn] DIG 0 pause 200 If !S_butt then pause 250 fn = fn +1 viv = viv +1 hours = 0 minutes = 0 endif If fn >=2 then LCDOUT $FE,1 goto mainmenu endif goto lightoff
setting the time on to 00:00 and the off time to 00:01 the LCD displays 00:50 and 01:00 respectively. So obviously DT's routine will never match the times set..... I don't know why this has happened because in the original code it matched perfectly....Code:lcdout $FE,$D4+8,#lightsetHR[fn] DIG 1,#lightsetHR[fn] DIG 0,":",#lightsetMN[fn] DIG 1,#lightsetMN[fn] DIG 0 lcdout $FE,$D4+14,#lightoffHR[fn] DIG 1,#lightoffHR[fn] DIG 0,":",#lightoffMN[fn] DIG 1,#lightoffMN[fn] DIG 0![]()
OK as I couldn't figure the above out I started from scratch (again) and tried this:
Which works, apart from the original problem, in that at midnight the lights come on and stay on, and the temperatures drop to the default drop temperature. My guess is that as both start times and stop times = 00:00 this is what's causing the issue.Code:For fn = 0 to 1 If lightsetHR[fn]<timeH or lightsetHR[fn]>timeH and lightsetMN[fn]<timeM or lightsetMN[fn]>timeM and lightoffHR[fn]<timeH OR lightoffHR[fn]>timeH and lightoffMN[fn]<timeM OR lightoffMN[fn]>timeM Then LCDOut $FE, $94+9," " if fn=0 then Lights1 = 0 if fn=1 then Lights2 = 0 endif If lightsetHR[fn]=timeH and lightsetMN[fn]=timeM then 'compare value of each set time to current time and if matches if fn=0 then Lights1 = 1 if fn=1 then Lights2 = 1 'turn on those light LCDOut $FE, $94+9,"Lights ON" endif next fOR fn=0 to 3 If StartHour[fn]<timeH or StartHour[fn]>timeH and StartMin[fn]<timeM or StartMin[fn]>timeM and StopHour[fn]<timeH OR StopHour[fn]>timeH and StopMin[fn]<timeM OR StopMin[fn]>timeM then 'compare value of each start time to current time and if matches LCDOut $FE, $94," " SetPoints[fn]=normtemp[fn] endif If StartHour[fn]=timeH and StartMin[fn]=timeM then 'compare value of each start time to current time and if matches SetPoints[fn]=Droptemp[fn] 'change the corresponding set point to the drop temperature LCDOut $FE, $94,"Night" endif if StopHour[fn]=timeH and StopMin[fn]=timeM then 'compare value of each stop time to current time and if matches LCDOut $FE, $94," " SetPoints[fn]=normtemp[fn] 'change value back to normal temperature Endif next fn
Anyone able to help come up with a suitable working snippet of code, or tell me why it doesn't work correctly when using DTs code ?
If everything is working except midnight add a
if midnight skip
this
that
and the other thing
Dave
Always wear safety glasses while programming.
Back to the drawing board??
I don't know Malc.
In post #14, you found out that the Start and Stop times were not being stored correctly from your button input routines, or they are getting changed somewhere else in the program.
And I agree, the routines I showed won't work if the preset times are wrong.
So why did you scrap the CheckTimes routine?
That isn't changing your start/stop times.
The latest code you showed would not compile.
Missing = signs for one (lightsetHR[fn]timeH).
DT
Guys,
Thanks for the replies... I should be resting (been unwell recently) and not really spending all day on this ! maybe that's why my brain hurts !! - but I think I've found what is causing the problem...
On the easyPIC5 board, I noticed that when the time reached 00:00, LEDs on B5 - B7 seemed to strobe, and then stop at 00:01 - this was also observed on the version in the prototype, as the lights flashed at midnight today ! - this seems to put the PIC in some limbo / reset state... ?
I've managed to get something working that sets the night time drops and turns on the lights if set before the activation time... I'm going to look at either Daves suggestion of a skip midnight routine, or take a fresh look at Darrel's routines and see if I can get that working... would love to know why the PIC is behaving so strange at midnight
Bookmarks