Shop OBEX P1 Docs P2 Docs Learn Events
Checking time — Parallax Forums

Checking time

ArchiverArchiver Posts: 46,084
edited 2001-04-19 23:46 in General Discussion
I think this will do what you're after:

task_done VAR BIT
task_time VAR BYTE
task_interval CON 30 ' or whatever

[noparse][[/noparse] get min ]
IF min >= task_time THEN checkTask
task_done = 0
GOTO continue

checkTask:
IF task_done = 1 THEN continue
[noparse][[/noparse] do task ]
task_done = 1
task_time = task_time + task_interval // 60

continue:


Regards,

Steve

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-04-19 19:21
    Im using a DS1302 RTC I have a program that does a number of things, I have
    one function that I need to do on an interval of 30 min or greater. In
    writing code to check the clock I find that I have a page of if then
    statements.

    I will need to check the minutes if the minutes are less than the last
    saved minutes,
    I will need to check the hours, if the hours are less than the last saved
    hours then
    I will need to check the days if the days are less than the saved day then
    I will need to check the months if the month is less than the last saved
    month
    I will need to check the year

    Does anyone have a quick and dirty way of doing this without using so many
    if then statements is there a way of adding all the values up
    and subtracting one time ?? something like below and also in a smaller
    size to fit the stamps 65535 limit

    old value

    min = 12
    hour = 24
    day = 6
    month = 11
    year = 01

    old value = 0111062412

    new value

    min = 04
    hour = 23
    day = 8
    month = 11
    year = 01

    new value = 0111082304
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-19 19:42
    maybe something like this Is this a good way of thinking or not

    year month\day hour\min

    new date 01 1108 2304

    last saved date 01 1106 2412
    ________________________________________________________________________________\
    _
    subtract 00 0002 -108

    so what would be the next step

    "L .Gaminde" wrote:
    >
    > Im using a DS1302 RTC I have a program that does a number of things, I have
    > one function that I need to do on an interval of 30 min or greater. In
    > writing code to check the clock I find that I have a page of if then
    > statements.
    >
    > I will need to check the minutes if the minutes are less than the last
    > saved minutes,
    > I will need to check the hours, if the hours are less than the last saved
    > hours then
    > I will need to check the days if the days are less than the saved day then
    > I will need to check the months if the month is less than the last saved
    > month
    > I will need to check the year
    >
    > Does anyone have a quick and dirty way of doing this without using so many
    > if then statements is there a way of adding all the values up
    > and subtracting one time ?? something like below and also in a smaller
    > size to fit the stamps 65535 limit
    >
    > old value
    >
    > min = 12
    > hour = 24
    > day = 6
    > month = 11
    > year = 01
    >
    > old value = 0111062412
    >
    > new value
    >
    > min = 04
    > hour = 23
    > day = 8
    > month = 11
    > year = 01
    >
    > new value = 0111082304
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-19 19:56
    Assuming that you need to do the function on a regular interval of any
    minutes between 1 and 59 minutes, you could ignore all the other pieces of
    the date-time and focus on the minutes byte only. For example,

    if oldMM > newMM
    then diffMM = newMM + 60 - oldMM
    else diffMM = newMM - oldMM
    endif
    if diffMM > intervalMM
    then do function
    endif


    Basically, the pseudocode checks if the minutes register experienced a
    wrap-around since the last time check, and calculates the difference between
    the old time and time new time.

    This technique requires that the interval AND the checks for the interval
    expiring be less than 60 minutes long. Also note that the resolution of
    this method will never be less than 1 minute.

    Regards,
    Daniel McGlothin

    Original Message
    From: L .Gaminde [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=8I9iqvI_cNICroJrOlS4XCET1Mz2uAaWH3TFQ-5uPmxGUuEPbAxfy83rVQv4QtYxsKNW9QFZPdm-KHC5EnDP]lgaminde@t...[/url
    Sent: Thursday, April 19, 2001 2:42 PM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] Checking time


    maybe something like this Is this a good way of thinking or not

    year month\day hour\min

    new date 01 1108 2304

    last saved date 01 1106 2412
    ____________________________________________________________________________
    _____
    subtract 00 0002 -108

    so what would be the next step

    "L .Gaminde" wrote:
    >
    > Im using a DS1302 RTC I have a program that does a number of things, I
    have
    > one function that I need to do on an interval of 30 min or greater. In
    > writing code to check the clock I find that I have a page of if then
    > statements.
    >
    > I will need to check the minutes if the minutes are less than the last
    > saved minutes,
    > I will need to check the hours, if the hours are less than the last saved
    > hours then
    > I will need to check the days if the days are less than the saved day then
    > I will need to check the months if the month is less than the last saved
    > month
    > I will need to check the year
    >
    > Does anyone have a quick and dirty way of doing this without using so many
    > if then statements is there a way of adding all the values up
    > and subtracting one time ?? something like below and also in a smaller
    > size to fit the stamps 65535 limit
    >
    > old value
    >
    > min = 12
    > hour = 24
    > day = 6
    > month = 11
    > year = 01
    >
    > old value = 0111062412
    >
    > new value
    >
    > min = 04
    > hour = 23
    > day = 8
    > month = 11
    > year = 01
    >
    > new value = 0111082304
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/



    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-19 20:42
    Daniel not sure if this would work, it would be 30 minutes or greater, so
    the next time could be the next day or one month from the last sense, not
    likely but possible, Im trying to think of the worst case. Now I could do
    this for all the values start with year,month,day,hour,min. If I would do
    it like I had it laid out in year, month\day, and hour\min, I would take
    the 0002 value and multiply by 24 for hours times 100 plus the 2304
    hours\minutes then subtract the 2412 hours \ minutes of the last saved date
    Im really not sure if im on tract here of If im going to see some major
    screw up later in the coding. like below to keep carry over the month to
    days I will need to know the number of days in each month, am I making this
    harder than it really is ????


    something like this

    last saved time 24:59 12-31-01
    new time read 01:01 01-01-02




    "D. Daniel McGlothin" wrote:
    >
    > Assuming that you need to do the function on a regular interval of any
    > minutes between 1 and 59 minutes, you could ignore all the other pieces of
    > the date-time and focus on the minutes byte only. For example,
    >
    > if oldMM > newMM
    > then diffMM = newMM + 60 - oldMM
    > else diffMM = newMM - oldMM
    > endif
    > if diffMM > intervalMM
    > then do function
    > endif
    >
    > Basically, the pseudocode checks if the minutes register experienced a
    > wrap-around since the last time check, and calculates the difference between
    > the old time and time new time.
    >
    > This technique requires that the interval AND the checks for the interval
    > expiring be less than 60 minutes long. Also note that the resolution of
    > this method will never be less than 1 minute.
    >
    > Regards,
    > Daniel McGlothin
    >
    >
    Original Message
    > From: L .Gaminde [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=-sI39hgDS0hd5GrDakRpSF_Y_3MmBb4S9bl89_4creAw6EMLwheRKceoaLRho8Znc2-9fCopOlw73OkKNw]lgaminde@t...[/url
    > Sent: Thursday, April 19, 2001 2:42 PM
    > To: basicstamps@yahoogroups.com
    > Subject: Re: [noparse][[/noparse]basicstamps] Checking time
    >
    > maybe something like this Is this a good way of thinking or not
    >
    > year month\day hour\min
    >
    > new date 01 1108 2304
    >
    > last saved date 01 1106 2412
    > ____________________________________________________________________________
    > _____
    > subtract 00 0002 -108
    >
    > so what would be the next step
    >
    > "L .Gaminde" wrote:
    > >
    > > Im using a DS1302 RTC I have a program that does a number of things, I
    > have
    > > one function that I need to do on an interval of 30 min or greater. In
    > > writing code to check the clock I find that I have a page of if then
    > > statements.
    > >
    > > I will need to check the minutes if the minutes are less than the last
    > > saved minutes,
    > > I will need to check the hours, if the hours are less than the last saved
    > > hours then
    > > I will need to check the days if the days are less than the saved day then
    > > I will need to check the months if the month is less than the last saved
    > > month
    > > I will need to check the year
    > >
    > > Does anyone have a quick and dirty way of doing this without using so many
    > > if then statements is there a way of adding all the values up
    > > and subtracting one time ?? something like below and also in a smaller
    > > size to fit the stamps 65535 limit
    > >
    > > old value
    > >
    > > min = 12
    > > hour = 24
    > > day = 6
    > > month = 11
    > > year = 01
    > >
    > > old value = 0111062412
    > >
    > > new value
    > >
    > > min = 04
    > > hour = 23
    > > day = 8
    > > month = 11
    > > year = 01
    > >
    > > new value = 0111082304
    > >
    > >
    > >
    > > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-19 23:00
    >Im using a DS1302 RTC I have a program that does a number of things, I have
    >one function that I need to do on an interval of 30 min or greater. In
    >writing code to check the clock I find that I have a page of if then
    >statements.

    Hi Larry,

    I like to make a conversion to Julian date/time in the subroutine
    that reads the real time clock. That gives a single monotonically
    increasing number to deal with in the rest of the program. The
    action at intervals is then simply a question of divisibility.
    if timenumber//interval=0 then its_time_now

    In data loggers, I am using intervals that can range from 1 minute to
    6 hours, so I use the code:
    julian1 = hour*60+minute
    where hour is from 0 to 23 and minute is from 0-59, so Julian goes
    from 0 to 1439, from midnight to 11:59pm (Be sure to use standard
    values in the calculation, not bcd coded values.) Then you have a
    choice of a lot of intervals that divide 1440 evenly:
    1,2,3,4,5,6,10,15,20,,30,60,120,180,240,360 minutes and some others.
    Then:
    if julian10//30=0 then do30minutestuff

    If you need seconds, you can get down to 2 second intervals, and
    still fit it into one 16 bit word. (43200 2-second intervals in a
    day) 10 minute intervals will carry you for a year in one 16 bit
    word. (52560 10 minute intervals in a leap year).

    A BASIC Stamp formula for day of year (0 to 364 or 365) given YY
    (year) MM (month) and DD (day) is:
    JD=MM-1*30+(MM/9+MM/2)-(MM max 3/3*(YY//4 max 1 +1))+ DD
    For explanation see,
    http://www.emesys.com/BS2math4.htm#JulianDate

    Then to resolve to 10 minute intervals, take the above JD value and
    roll in the time:
    julian10 = (JD * 144) + (hour*6) + (minute/10)
    This julian10 value should be updated every time the program reads
    the clock, and it has a new value for every 10 minutes in the current
    year.

    If you need to set an alarm for a specific time in the future, run
    the future date/time through the above formula to get one number,
    then check for equality.
    if alarm=julian10 then doAlarm

    I hope that helps,

    -- best regards
    Thomas Tracy Allen PhD
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-19 23:46
    Tracy ! thank you, I was hoping you would come up with something, Now I
    will look this all over for a few days ( few meaning anything from 10 to
    300 Julian days ) and probably have some more questions.

    thanks again
    Larry Gaminde

    Tracy Allen wrote:
    >
    > >Im using a DS1302 RTC I have a program that does a number of things, I have
    > >one function that I need to do on an interval of 30 min or greater. In
    > >writing code to check the clock I find that I have a page of if then
    > >statements.
    >
    > Hi Larry,
    >
    > I like to make a conversion to Julian date/time in the subroutine
    > that reads the real time clock. That gives a single monotonically
    > increasing number to deal with in the rest of the program. The
    > action at intervals is then simply a question of divisibility.
    > if timenumber//interval=0 then its_time_now
    >
    > In data loggers, I am using intervals that can range from 1 minute to
    > 6 hours, so I use the code:
    > julian1 = hour*60+minute
    > where hour is from 0 to 23 and minute is from 0-59, so Julian goes
    > from 0 to 1439, from midnight to 11:59pm (Be sure to use standard
    > values in the calculation, not bcd coded values.) Then you have a
    > choice of a lot of intervals that divide 1440 evenly:
    > 1,2,3,4,5,6,10,15,20,,30,60,120,180,240,360 minutes and some others.
    > Then:
    > if julian10//30=0 then do30minutestuff
    >
    > If you need seconds, you can get down to 2 second intervals, and
    > still fit it into one 16 bit word. (43200 2-second intervals in a
    > day) 10 minute intervals will carry you for a year in one 16 bit
    > word. (52560 10 minute intervals in a leap year).
    >
    > A BASIC Stamp formula for day of year (0 to 364 or 365) given YY
    > (year) MM (month) and DD (day) is:
    > JD=MM-1*30+(MM/9+MM/2)-(MM max 3/3*(YY//4 max 1 +1))+ DD
    > For explanation see,
    > http://www.emesys.com/BS2math4.htm#JulianDate
    >
    > Then to resolve to 10 minute intervals, take the above JD value and
    > roll in the time:
    > julian10 = (JD * 144) + (hour*6) + (minute/10)
    > This julian10 value should be updated every time the program reads
    > the clock, and it has a new value for every 10 minutes in the current
    > year.
    >
    > If you need to set an alarm for a specific time in the future, run
    > the future date/time through the above formula to get one number,
    > then check for equality.
    > if alarm=julian10 then doAlarm
    >
    > I hope that helps,
    >
    > -- best regards
    > Thomas Tracy Allen PhD
    > electronically monitored ecosystems
    > http://www.emesystems.com
    > mailto:tracy@e...
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.