Time comparison


Closed Thread
Results 1 to 21 of 21

Thread: Time comparison

  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Time comparison

    Hi guys and gals,

    Can someone offer some suggestions as to how to determine if when setting the on / off times for some lights, the lights should be on at the time of applying the settings.

    I'm using a 1307 RTC and have the following within the code

    Code:
    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
    
    If lightoffHR[fn]=timeH and lightoffMN[fn]=timeM then         'compare value of each start time to current time and if matches
       if fn=0 then Lights1 = 0
       if fn=1 then Lights2 = 0                            'turn off the light
       if lights1 = 0 and lights2 = 0 then
       LCDOut $FE, $94+9,"          " 
    endif
    If the current time is say 12:15 and I set the lights to come on at say 12:20 and then go off at 12:25 it works perfectly, however, if the current time is 12:22 and I try to set the time the lights remain off... presumably until 12:20 the next day. I'm looking for a simple way for the code to work out if the time of setting the lighting period whether or not the lights should be on or not.

    Here is the section where the user sets the on/off times

    Code:
    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
    Last edited by malc-c; - 24th July 2010 at 13:22. Reason: added more code

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What about

    Code:
    If lightsetHR[fn] >= timeH and lightsetMN[fn] >= timeM then
    Or am I missing something??
    Dave
    Always wear safety glasses while programming.

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,

    That's what I thought.. but it doesn't work because of the checking of the minutes. For example, if the current time is 18:07 and I want to set the on time to 16:45 then I tried
    Code:
    If lightsetHR[fn] <= timeH and lightsetMN[fn] <= timeM then
    I used < because in this case lightsetHR = 16 and timeH=18. But as lightsetMN = 45 and timeM is 07 the condition is not matched. If used as per your example,
    Code:
    If lightsetHR[fn] >= timeH and lightsetMN[fn] >= timeM then
    lightsetHR =16 which isn't > than timeH which is 18 so again the condition would not be matched

    Does that make sense ?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I still think this rountine is your best bet.

    http://www.picbasic.co.uk/forum/show...8913#post58913

    It takes a Start Time (H:M:S) and End Time, then tells you if it's within that time period or not. Even if the period ends the following day.
    DT

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Thanks

    Hi Darrel,

    I've not had chance to test this yet, but here's how I've adapted the code

    Code:
    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
    ' endif   
      ;---------------
      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:
       Lights1 = 0
       Lights2 = 0                            'turn off the light
       if lights1 = 0 and lights2 = 0 then
       LCDOut $FE, $94+9,"          "   
       endif
    return
    The one thing I'm not too clear on, given that I have two sets of start times and end times for the two lighting circuits, do I need to change the PastStop and Paststart to something like PastStop[fn] and PastStart[fn] to match the same lightoff[nf] etc ?

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Not able to test -

    The following compiles, but I'm not able to test yet as I'm waiting for a 20 x 4 LCD

    Code:
    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[fn]=1
    
         ; is it past the Stop time?
      if (timeH>lightoffHR[fn]) OR _                
         (timeH=lightoffHR[fn] AND timeM>lightoffMN[fn])then PastStop[fn]=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[fn]=1
    ' endif   
      ;---------------
      if !NextDay then                               ; same day, use AND
          if PastStart[fn] AND !PastStop[fn] then ProgON = 1
      else                                           ; next day, use OR
          IF PastStart[fn] OR !PastStop[fn] then ProgON = 1
      endif
    
    if fn=0 and ProgON=1 then Lights1 = 1
    LCDOut $FE, $94+9,"Lights ON"
    
    if fn=1 and ProgOn=1 then Lights2 = 1                              'turn on those light
    LCDOut $FE, $94+9,"Lights ON"
        
    AlwaysOFF:
       Lights1 = 0
       Lights2 = 0                            'turn off the light
       if lights1 = 0 and lights2 = 0 then
       LCDOut $FE, $94+9,"          "   
       endif
    return

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I must be having one of those days...
    I still do not get why something like this will not work.

    If current time is equal to or greater than set start time then on.
    If current time is equal to or greater than set stop time then off.

    Add some vars here and there for two lights...

    Use if/then s. Case while/wend ....
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    That looks pretty good Malc.
    And nope, you don't need arrays for the flag bits.

    I don't think you should have anything in the AlwaysOFF section, since the CheckTimes routine just determines if it's inside the program period or not.
    With multiple time periods, whatever is in AlwaysOFF would happen to both periods if only triggered in one of them.
    Any actions can be done after returning from the subroutine.

    Something like this in the main loop maybe.
    Code:
        fn = 0                              ; select the first Lights
        GOSUB CheckTimes                    ; compare the programed period
        IF ProgON THEN                      ; If in the program period
            IF Lights1 = 0 THEN Lights1 = 1 ; Turn light on (if off)
        ELSE
            IF Lights1 = 1 THEN Lights1 = 0
        ENDIF
    ;   -----------------------------------
        fn = 1                              ; select the second Lights
        GOSUB CheckTimes                    ; compare the programed period
        IF ProgON THEN
            IF Lights2 = 0 THEN Lights2 = 1
        ELSE
            IF Lights2 = 1 THEN Lights2 = 0
        ENDIF
    DT

  9. #9
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,

    Hopefully the LCD will arrive soon and I'll be able to test this on the development board

  10. #10
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    That looks pretty good Malc.
    And nope, you don't need arrays for the flag bits.

    I don't think you should have anything in the AlwaysOFF section, since the CheckTimes routine just determines if it's inside the program period or not.
    With multiple time periods, whatever is in AlwaysOFF would happen to both periods if only triggered in one of them.
    Any actions can be done after returning from the subroutine.

    Something like this in the main loop maybe.
    Code:
        fn = 0                              ; select the first Lights
        GOSUB CheckTimes                    ; compare the programed period
        IF ProgON THEN                      ; If in the program period
            IF Lights1 = 0 THEN Lights1 = 1 ; Turn light on (if off)
        ELSE
            IF Lights1 = 1 THEN Lights1 = 0
        ENDIF
    ;   -----------------------------------
        fn = 1                              ; select the second Lights
        GOSUB CheckTimes                    ; compare the programed period
        IF ProgON THEN
            IF Lights2 = 0 THEN Lights2 = 1
        ELSE
            IF Lights2 = 1 THEN Lights2 = 0
        ENDIF

    Darrel,

    Just ripped the LCD out of the unit so I could test this. So far it seems to work apart from one strange thing, the timings are a minute out... If I set the lighting period to come on at 15:00 it comes on at 15:01, and set to off at 15:05 it goes of 15:06, and I don't get anything displayed on the LCD

    Here's the code that turns the lights on or off:

    Code:
        fn = 1                              ; select the second Lights
        GOSUB CheckTimes                    ; compare the programed period
        IF ProgON THEN
            IF Lights2 = 0 THEN Lights2 = 1
        LCDOut $FE, $94+9,"Light 2 ON"
        ELSE
            IF Lights2 = 1 THEN Lights2 = 0
         LCDOut $FE, $94+9,"          "
         ENDIF
        if Lights1 = 1 and Lights2 = 1 then 
        LCDOut $FE, $94+9,"Lights ON"
        ELSE
         LCDOut $FE, $94+9,"          "
         Endif
    then there's the checking routine:

    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[fn]=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
    And finally the section where the time is set:

    Code:
    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

    The subs for inc hrs or mins:
    Code:
    IncHours:
        Hours = Hours + 1
        IF Hours = 24 THEN Hours = 0
        
        pause 250
    RETURN
    
    IncMinutes:
        Minutes = Minutes + 1
        IF Minutes = 60 THEN Minutes = 0
        
        pause 250
    RETURN
    Any ideas....??

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Malcolm,

    In the original CheckTimes: routine, the Seconds test had a >=.
    That way it's TRUE when the exact second rolls around.

    Modified for Minutes as the smallest period, I think the Minutes test now needs the >=

    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[fn]=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
    P.S. There's still an Array index in your NextDay flag.
    Last edited by Darrel Taylor; - 26th July 2010 at 22:34. Reason: P.S.
    DT

  12. #12
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,

    I'll give it a try in the morning

  13. #13
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    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

  14. #14
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default back to the drawing board

    OK something has really got screwed up....

    Here's the menu routine which is used to set the times for the lighting

    Code:
    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
    so I added the following lines to display the times on the LCD when the program is running
    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
    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....

  15. #15
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default pulling my hair out

    OK as I couldn't figure the above out I started from scratch (again) and tried this:

    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
    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.

    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 ?

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    If everything is working except midnight add a

    if midnight skip
    this
    that
    and the other thing
    Dave
    Always wear safety glasses while programming.

  17. #17
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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

  18. #18
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default thanks

    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

  19. #19
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  20. #20
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Malcolm,

    I missed this part in your conversion last time.
    Code:
         ; if the Start and Stop times are the same, then Always OFF 
      if (lightsetHR[fn]=timeH) AND _       
         (lightsetMN[fn]=timeM) then AlwaysOFF
    It should be testing the Stop time instead of the Current time.

    Here's the updated code.
    Code:
    CheckTimes:
    TimeCmpFlags = 0  ; clear flags first
    
         ; if the Start and Stop times are the same, then Always OFF 
      if (lightsetHR[fn]=lightoffHR[fn]) AND _       
         (lightsetMN[fn]=lightoffMN[fn]) 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
    I've run it in the simulator and it works perfectly.

    Name:  TimeCompare.JPG
Views: 514
Size:  152.7 KB
    DT

  21. #21
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks guys,

    Darrel, I'll give that a whirl later this morning.... and will report back if I have any issues

    Love the look of that simulator.... nice layout

    Thanks for the support

    Edit - Just tried it by setting the current time to 8:15 and then setting the lighting to come on at 8:09 and off at 8:20 and when run it works fine - have also tried it with the clock set to 23:58 and a lighting period of 23:59 to 00:01 and that works too - Thanks DT

    However.....

    I can't get the display to show when the lights are on...

    Code:
    fn = 0                              ; select the first Lights
        GOSUB CheckTimes                    ; compare the programed period
        IF ProgON THEN                      ; If in the program period
           IF Lights1 = 0 THEN Lights1 = 1
           IF Lights1 = 1 LCDOut $FE, $94+9,"Light 1 ON"
        ELSE
           IF Lights1 = 1 THEN Lights1 = 0
           IF Lights1 = 0 LCDOut $FE, $94+9,"          " 
        ENDIF
    
        fn = 1                              ; select the second Lights
        GOSUB CheckTimes                    ; compare the programed period
        IF ProgON THEN
            IF Lights2 = 0 THEN Lights2 = 1
        LCDOut $FE, $94+9,"Light 2 ON"
        ELSE
            IF Lights2 = 1 THEN Lights2 = 0
         LCDOut $FE, $94+9,"          "
         ENDIF
        if Lights1 = 1 and Lights2 = 1 then 
        LCDOut $FE, $94+9,"Lights ON"
        ELSE
         LCDOut $FE, $94+9,"          "
         Endif
    The value for Lights1 or Lights2 changes from 0 to 1 as the corresponding LED on the development board lights up or turns off according to the value, but the IF Lights1 = 1 LCDOut $FE, $94+9,"Light 1 ON" or IF Lights1 = 1 THEN LCDOut $FE, $94+9,"Light 1 ON" seems to be ignored
    Last edited by malc-c; - 28th July 2010 at 09:17. Reason: update - feedback on performance

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts