Time comparison


Closed Thread
Results 1 to 21 of 21

Thread: Time comparison

Hybrid View

  1. #1
    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 ?

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

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

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

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

  6. #6
    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: 566
Size:  152.7 KB
    DT

  7. #7
    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 10: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