Shop OBEX P1 Docs P2 Docs Learn Events
Adj for Day Light Saving Time..........Is there any thing wrong with the way th — Parallax Forums

Adj for Day Light Saving Time..........Is there any thing wrong with the way th

sam_sam_samsam_sam_sam Posts: 2,286
edited 2008-03-28 16:10 in General Discussion
Hi Every One

I want to use the Month·Jan to Dec Date 1 to 31 and the day of the week
Sun to Sat

I know that with hrs = $00 and mins = $00 and secs = $00
are used to control any thing that you want

But what do you use for Month and Date and day of the Week
to control them

Do you need the $ before the # for this to work like you need for the
hrs , mins and the secs

And are they the # for Month or they the name of the month

I Goggle this before I ask this and could not find any thing on this can any one help or has any one done before

Thanks to any one that can help

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 3/25/2008 5:13:16 AM GMT

Comments

  • MSDTechMSDTech Posts: 342
    edited 2008-03-24 22:54
    You might read:
    http://www.parallax.com/Portals/0/Downloads/docs/prod/appkit/ds1302rtc.pdf
    The example code shows how to decode the Month, Day and Date capabilities. You have to translate the month (1-12) and the Date (1-7) into text strings in your code. The sample program in the document above also shows how to make the translations.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-25 05:02
    MSDTech

    Thank You for your reply

    Here is what i came up with

    Dose any one see any wrong with this routine I am using the DS1302 Demo Code to set the clock and took out the setting of the clock routine

    start:
    · GOSUB Get_Time
    ·· DEBUG HOME , HEX2 month, "/", HEX2 date, CR,
    ···· HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs, CR
    ···· LOOKUP (day - 1), [noparse][[/noparse]Sun, Mon, Tue, Wed, Thu, Fri, Sat], work
    ·· DO···················································································· · ' Display Day Abbreviation
    ··· READ work, ioByte······························································· · ' Read Each Character Into ioByte
    ··· IF (ioByte = 0) THEN EXIT······················································· ' If 0 then done
    ··· DEBUG ioByte········································································ ' Send Character To DEBUG Screen
    ··· work = work + 1·································································· · ' Increment Address
    ······························································································ ' Next Character, If 0 Then Done


    ·· 'This routine is for Day Light Saving adj Time

    · IF month = $03 AND·(date > $14) AND day = $01 AND hrs = $00 AND mins = $00 THEN GOSUB hrs_adj
    · IF month = $11 AND (date > $07) AND day = $01 AND hrs = $02 AND mins = $00 THEN GOSUB hrs_adj
    ········································ ( ^ I am not sure this part is right·the first week and the·second week of the month )

    · 'This routine is for turning Power ON and OFF every week day at the same time and On all weekend


    · IF day = $07 OR day = $01 THEN
    ·· HIGH 10
    ·· ELSE
    · IF day = $02 AND hrs = $07 AND mins = $30 THEN
    ·· LOW 10
    ·· ELSE
    · IF day > $02 AND day < $06 AND hrs = $17 AND mins = $00 THEN
    · HIGH 10
    · ELSE
    · IF day > $02 AND day < $06 AND hrs = $07 AND mins = $20 THEN
    ·· LOW 10
    · ENDIF
    · ENDIF
    · ENDIF
    · ENDIF
    · LOOP

    ·hrs_adj:
    ·hrs = $01
    ·GOSUB set_time
    ·RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 3/25/2008 5:27:44 AM GMT
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-25 11:27
    IF month = $03 AND (date > $14) AND day = $01 AND hrs = $00 AND mins = $00 THEN GOSUB hrs_adj
    IF month = $11 AND (date > $07) AND day = $01 AND hrs = $02 AND mins = $00 THEN GOSUB hrs_adj

    Your ">" should be an "=". The ">" will adjust the time every Sunday in March after the 14th at midnight and similarly for the second piece of code.

    Hope this helpssmile.gif
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-25 13:19
    MSDTech

    The problem is if you use = instead of >

    If Sunday dose not fall on the 7 or the 14 then it will not change the time
    I test this last night

    How you·would be able to have where it first·in week March ·and the·second week in Oct on Sunday

    I open to any idea.gifs that you may have

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • MSDTechMSDTech Posts: 342
    edited 2008-03-26 02:50
    One thing you might do is use one of the RAM memory locations in the DS1302 to flag that you have made the adjustment for DST. Test for the Date as you have it, but only reset the clock if the RAM variable has not been set. You use a similar routing in the fall to move the time back and clear the RAM variable so you only do the reset once.
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-03-26 05:28
    sam_sam_sam,

    Here is a snippet of code that might give you some ideas. In my neighborhood we have to watch out for the third Monday morning of every month, because we have to have the car off the street for street sweeping, otherwise we get a fat parking ticket. The cost of urban life. So this clock routine (abbreviated) gives a warning on the day before the third Monday and again on the day itself. You need a similar calculation to find the day for rollover of daylight savings.

    I don't use the "day" variable from the RTC. Instead, I calculate it from the Julian day number (JDN), which is simply a count of the number of days from 1/1/2001. (= day #1 in this scheme). You will see the calculation for JDN in the attached subroutine. It returns the JDN of any mm/dd/yy passed to it. It so happened that 1/1/2001 was a Monday, so it is then easy to calculate the day of the week,
    dow=JDN // 7.

    The routine below figures out the day of the week of the first of the current month, and from that, the date of the third Monday. Note the conversions from BCD time to binary time.


    ' snippet, Tracy Allen
    ' warn for third Monday each month
    ' enter with current date and time come from RTC, month, date, year, hour, etc. in BCD
    mm = 10 * month.nib1 +  month.nib0  ' convert BCD to binary, current month
    dd = 1  ' day one of current month
    yy = 10* year.nib1 + year.nib0   ' current year, BCD to binary
    GOSUB julian  ' returns julian day number JDN of first day of current month
    dow = JDN // 7   'dow:  what is day one of current month? 0=Sun, 1=Mon etc
    m3=(8-dow) //7+1+(3*7)  ' calculate date of third Monday of current month
    
    dd = 10 * date.nib1 + date.nib0  ' current date BCD to binary
    hh = 10 * hour.nib1 + hour.nib0  ' current hour BCD to binary
    IF dd=m3-1 THEN DEBUG "tomorrow is street sweeping!"
    IF dd=m3 AND hh<9 THEN DEBUG "third Monday -- move car!!!!",BELL,BELL,BELL
    IF dd=m3 AND hh>9 THEN DEBUG "check car for parking ticket:-("
    END
    
    ' return JD = number of days starting at 1/1 of current year as day #1
    ' return JND = number of days starting at 1/1/2001 as day #1 
    ' note mm/dd/yy are flat binary month, day and year.
    ' http://www.emesystems.com/BS2math4.htm#JulianDate
     julian: 
        JD = MM-1*30+(MM/9+MM/2)-(MM max 3/3*(YY//4 max 1 +1))+ DD
        JDN = JD+(YY-1*365)+(YY-1/4)
       RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-03-26 07:20
    sam_sam_sam,
    Here's yet another example...
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    [color=#000033]RefYear             CON 8 &#8217;Reference Year ... must be a Leap Year
    RefDay              CON 2 &#8217;First Sunday in March for Reference Year[/color]
     
    [color=#000033]CurrentYear         VAR Byte
    CurrentMonth        VAR Byte
    LeapYearIndex       VAR Byte
    NonLeapYearIndex    VAR Byte
    LeapIndex           VAR Byte
    RefDateIndex        VAR Byte[/color]
     
    [color=#000033]'Test Only , Normally you would retrieve the Current Year and Month from the DS1302
    CurrentYear = 8
    CurrentMonth = 3 'If Month is 3, then RefDateIndex returns the Date for the 2nd Sunday
                     'If Month is 11, then RefDateIndex returns the Date for the 1st Sunday[/color]
     
    [color=#000033]LeapYearIndex = (CurrentYear - RefYEAR) / 4
    NonLeapYearIndex = (CurrentYear - RefYEAR) - LeapYearIndex
    LeapIndex = (LeapYearIndex * 2) + NonLeapYearIndex
    RefDateIndex = RefDay + 127 'Add 127 to Temporarily handle negative numbers
    IF CurrentMonth = 3 OR CurrentMonth = 11 THEN RefDateIndex = RefDateIndex - LeapIndex
    DO WHILE RefDateIndex < 128 'Check if Result is Zero or Negative
       RefDateIndex = RefDateIndex + 7
    LOOP
    IF CurrentMonth = 3 THEN RefDateIndex = RefDateIndex + 7
    RefDateIndex = RefDateIndex - 127 'Subtract 127 to Resume using positive numbers[/color]
    [color=#000033]DEBUG DEC RefDateIndex[/color]
     
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 3/26/2008 7:26:34 AM GMT
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-26 10:56
    Okay, so if you want some certain day in a month, say the second Sunday in March.

    The day will always be 01 so that can be checked by day = 1
    The month and hour can be check in the same way.

    Now what we need to do is figure out the range of dates that will be the second Sunday.
    The earliest it would be is if a Sunday is the first day of the month. This would mean that the second Sunday would be the 8th day in the month.
    The latest it would be is if a Monday is the first day of the month. This would mean that the second Sunday would be the 14th day in the month.

    So you checking code would be
    IF month = $03 AND (date => $8) AND (date =< 14) AND day = $01 AND hrs = $00 AND mins = $00 THEN GOSUB hrs_adj

    You will of course have to adjust for which day you want.

    Hope this helpssmile.gif
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-26 16:40
    stevenmess2004, ·Beau Schwabe, Tracy Allen

    Thank You for all of your input·and ·idea.gifs·to this Problem that i was have trying to get this to
    Work

    I wanting to built a timer to control the TV, Cable Box·,·Speaker Amp CD· Changer
    Which all use Stand By Power when they are OFF

    In this Months Nuts and Volt there is story about how much it cost a year just for··Stand By Power useage The cost was about $200.00 year· WOW!!!!!!!

    So I thought it was time to put a STOP to Waste Full use of electircty when a Basic Stamp
    Board that you put together is $30.00 and a hand full of other·part that would not cost to much

    I still would save about $150.00 in the First Year
    I was Think about the fact if the price of OIL keep going UP then the price of KILWATT per
    Hour will go up agian we just had a rate hike last year· $0.03 per kilwatt hour

    This is the reason I have so·busy working on different types of·timers· that need to be controled and only run when need



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • MSDTechMSDTech Posts: 342
    edited 2008-03-26 21:42
    I think I may have an idea that would solve your daylight savings time problem (other then telling congress to go back to the drawing board). I'm making the following assumptions based on your description of what you are trying to accomplish, if they're wrong just tell me and I'll withdraw the idea:

    1. You have or will develop some method for killing the power to the devices you listed using the Basic Stamp.

    2. All of the devices have some type of infrared remote control. Its the device keeping the ir circuits active to watch for the power button that uses the standby power.

    3. You were planning to cycle the power to the devices off·/ on based on a schedule to cut energy usage. You also·didn't want the schedule to shift every spring and fall due to daylight savings time, or whenever congress gets the·urge to change it to.

    The idea is based on the fact that the Infrared sensors sold by Parallax can detect the signal from most remote controllers. The IR Remote for the Boe-Bot Parts Kit and Text explains how to decode Sony based controllers to control a Boe-Bot, but all that matters is that the ir sensor can detect the remote. You really don't care which remote or what button is being pressed, just that someone is using a remote. Set your system up to monitor the IR sensor to detect that a remote is being used. When it sees a remote, it turns on the power to the devices and reads the clock to get a time. You then add an hour to the time (or whatever interval you like) to act as the cut-off time. If the current time reaches the cut off time and it hasn't seen any more ir remote activity, turn the power off. I've included a pdf of the logic flow.

    In other words instead of a timer, you've got a dead man's switch. You only provide power to the devices when they are actually being used. You don't need to decode the ir remote signals - any button keeps it going. You also don't need to actually set the clock on the DS1302 since you are only using it to time an interval.



    attachment.php?attachmentid=73632
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-27 12:34
    MSDTech

    I like your· idea.gif·I am going to re think how I am going to set this up

    Thank you for your· idea.gif·s for this project

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-28 16:10
    MSDTech

    Set your system up to monitor the IR sensor to detect that a remote is being used. When it sees a remote, it turns on the power to the devices and reads the clock to get a time. You then add an hour to the time (or whatever interval you like) to act as the cut-off time. If the current time reaches the cut off time and it hasn't seen any more ir remote activity, turn the power off. I've included a pdf of the logic flow.

    In other words instead of a timer, you've got a dead man's switch. You only provide power to the devices when they are actually being used. You don't need to decode the ir remote signals - any button keeps it going. You also don't need to actually set the clock on the DS1302 since you are only using it to time an interval.


    · I just ordered this Today.....>>>>>> IR Remote for the Boe-Bot Parts Kit and Text

    http://www.parallax.com/Store/Education/KitsandBoards/tabid/182/ProductID/322/List/1/Default.aspx?SortField=ProductName,ProductName

    I am going to go through the Book until·I understand how to use this setup

    Then i am going to setup something that are along the same line that you have point
    ·and follow the outline that you have ·above

    But i will have work out the details how i want it work

    And I may update this as well


    I do not have a··Boe-Bot· at least not the new ones I have the one that you had to put this one together so there is no room to add this very easyly but we wiil see




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 3/28/2008 4:28:03 PM GMT
Sign In or Register to comment.