Shop OBEX P1 Docs P2 Docs Learn Events
Daylight Saving Time — Parallax Forums

Daylight Saving Time

Hi guys! does anyone here has an experience on making a daylight saving time using basic stamp 2?

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Hello,

    If I may ask for a better explanation of what you're trying to do since you can't really "make" a daylight savings time. Daylight Savings Time is the practice of advancing clocks during summer months by one hour so that evening daylight lasts an hour longer, while sacrificing normal sunrise times.

    You must be looking for something more specific to an application?
  • This are my codes for getting the time on gps and I need to add daylight saving time on it. Can you help me on this?

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    time VAR Byte (6)


    n4800 CON 188
    n9600 CON 84

    MAIN:



    SERIN 0, n4800,[WAIT("GGA,"),STR time\6]

    DEBUG CR
    time(2) = time(2) + 3
    IF time(2) > "5" THEN
    time(2) = time(2) - 6
    time(1)= time(1) + 1
    ENDIF

    SEROUT 1, n4800, ["$GNGGA,",time(0),time(1), time(2),time(3),time(4),time(5)]



    GOTO MAIN
  • kwinnkwinn Posts: 8,697
    Basically (no pun intended) you add one hour to the time starting in spring and stop adding it in autumn. Exact timing and rules vary by country/region (March 13 / Nov 6 for Ontario Canada). Since the GPS serial data presents GMT time a time zone correction is needed, so I add the DST correction to that in the spring and remove it in the fall.

    Sorry, don't use a basic stamp so I cannot post any code for you.
  • I've attached the code I used with two different real-time clock modules. Originally, I modified the DS1302 code adapted from sample code developed by Chris Savage. Thanks, Chris!

    When the DS1302 was replaced with the DS3231 for better temperature stability, the code was updated.

    This code controls the operation of an automated truck dumper and the main program is reasonably complicated. However, if you look at the code in the Slot 1, all the clock routines are there, including automatic changeover for DST.

    Good luck!

    Tom
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Thanks for sharing your updated code Tom. :nerd:
  • tomcrawfordtomcrawford Posts: 1,129
    edited 2016-05-11 21:15
    Here is an approach that doesn't require the software to know whether it is currently Summer or Winter Time (which means you don't have to ask an operator):
       if DSTEnabled=1 AND Day = Sunday AND Month = March AND Date > 7 AND Date < 15  'day we spring forward?
           if Hours = 1 AND Minutes = 59 AND Seconds = 59       'and it is time?
               Zone = Zone + 1             'adjust the time.  I receive UTC, so just fiddle the time zone
    

    In the fall, it is more complicated because the magic second happens twice:
      if DSTEnabled AND Day= Sunday and Month = October AND Date < 8       'day we fall back?
              if Hours = 1 AND Minutes = 59 AND Seconds = 59       'and it is time?
                   if DSTFlag = 0              'is it first pass through?
                       Zone = Zone - 1        'adjust the time
                       DSTFlag = 1              'and set a flag
                    else
                       DSTFlag = 0               'second time through we reset the flag for next October
    
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    I've done time zone and DST adjustments from a GPS system before, but then I had the benefit of knowing which time zone I was in. As for DST a flag was set when IN DST mode and cleared when the roll back date was reached.
  • thanks for the reply guys. ive seen a sample code for DST and I think Mr. Savage is the one who wrote it. can you check on it guys? Thanks!

  • Hello,
    I would like to post some code that is Built around the (BS2e/BS2 48/40), DS1302, Tracy Allen's (Day of Week DOW) code and my own code. I was wanting Tracy to go over my logic before I posted anything, but now is as good a ever.
    Note: some insight. The code always passed the bench test (100%) of the times after I got my part of the code figured out (testing within 30 min. window of the DLST). The first 4 times (Mar/Nov. twice) the code failed during normal operations. Reason: The DS1302 DOW format is (1 - 7) for Days Of the Week. Tracy's Julian Day Of the Week is (0 - 6) and I caught it at first but some how some way remove the (+1) at the end of his code. I promised my wife for 2 years the code was correct. The true "test" came when I let it run for 8 days, during normal operation. From Sunday to (DLST) Sunday. That's when the code and DS1302 became out of sync without the added (+1) at the end of the calculation. Lesson learned, normal operation is more then just a bench mock up.
    Like I said, it worked year ago Mar. (spring forward) last Nov. (fall backward) and this Mar. (spring forward).

    My overall code continuously monitors the DLST code (same code 3 slots) during normal operation and its during one of the delays if DLST happens, then other Alarm Times are adjusted forward/backwards to stay in sync. Bench test pass and failed when suppose to (all variables changed), have not done the real world test yet.
    Also within my 'Main Menu' code there is a toggle ON/OFF selection because not everyone lives in a DLST area.

    PS: don't know how ya'll get your PBASIC code within the yellow scrolling block???
    can not get it to work in preview to attach code...help
  • Howard,
    Wow that is from a few years ago and I'm glad to hear you got it worked out. Happy to look at it. You can post code by using the "Attach a file" link below the comment box. Or, hit the "C" icon that resides at the top of the comment box and then paste your code snippet in between the code tags that appear in line with your text.

    @Cydelcamat,
    If using GPS for this project, the GGA sentence has only the time, but RMC is better for your purpose because it gives you both time and date. Convert the date to an ordinal form, then calculate the day of week so you can find the two Sundays that mark the transitions.
  • WhitWhit Posts: 4,191
    edited 2016-05-12 19:30
    hmlittle59 wrote: »
    PS: don't know how ya'll get your PBASIC code within the yellow scrolling block???
    can not get it to work in preview to attach code...help

    Use the "C" button above in you text input window. Inserting code that way keeps its formatting and is much easier to read and check! Good luck!

    Like this...
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
Sign In or Register to comment.