[Icc-avr] RTC - how to compute the difference in minutes

Rick Drolet rick.drolet at gmail.com
Thu Nov 15 12:00:51 PST 2007


Sorry about breaking in here, but I can't seem to send a message to
Icc-avr at imagecraft.com
When sent, got a response from icc-avr-bounces

Can you possibly tell me why?
Rick




On 11/15/07, Robert Rademacher <robertrade at yahoo.com> wrote:
>
> Hi Paul,
>
> Thanks for your response. Based on the "validation test" done on Excel
> worksheet, these RTC test "equations" will not work if the year is rolled
> over to 2008. It's OK...as we can improve on that. :)
>
> Here's the link to Excel file for "testing" the RTC calculations (keep in
> mind it's not yet perfect).
>
> http://rademacher.org/ElapsedTimeCalculation.xls
>
> The revised RTC_Time would be:
> RTC_TEST_TIME = (hour * 60) + minutes
> RTC_TEST_DATE = (year * 10000) + (months * 100) + day (this one needs bit
> more work)
>
> Example #1 (from Excel worksheet)
>
> Session    Year    Month    Day    Hour    Minute    CalTime    CalDate
> Start    2007    11    14    9    30    570    20071114
> End    2007    11    14    21    30    1290    20071114
>
>                     TotalTime    720
>                     TotalDays        0
>                     Total Minutes    720    (correct)
>
> To compute for the total elapsed minutes, these above equations will work,
> only if both start and end of month and year are same.
>
> Let's look at Example #2:
> Session    Year    Month    Day    Hour    Minute    CalTime    CalDate
> Start    2007    11    14    10    30    630    20071114
> End    2007    11    15    9    30    570    20071115
>
>                     TotalTime    -60
>                     TotalDays        1
>                     Total Minutes    1380    (correct)
>
> Example #3
> Session    Year    Month    Day    Hour    Minute    CalTime    CalDate
> Start    2007    11    14    9    30    570    20071114
> End    2007    11    20    12    45    765    20071120
>
>                     TotalTime    195
>                     TotalDays        6
>                     Total Minutes    8835    (correct)
>
> The total elapsed minutes calculations based on hours/minutes/days are
> correct, as long as the month/year of both start/end session are same.
>
> Here's the small problem when computing the elapsed days when the
> month/year are different for both start/end session.
>
> Example #4
> Session    Year    Month    Day    Hour    Minute    CalTime    CalDate
> Start    2007    12    31    9    30    570    20071231
> End    2008    1    1    9    30    570    20080101
>
>                     TotalTime    0
>                     TotalDays        8870 (incorrect)
>                     Total Minutes    12772800 (incorrect)
>
> You will notice that the year has changed to 2008, as well as changing
> from December to January (month). The correct elapsed minutes would be 1440
> minutes (24 hours).
>
> I think we are getting there. Once we have the "magic" equation to handle
> the month/year, I will write a pretty difftime routine that would be very
> handy for all of us who use RTC for time/date services.
>
> Thanks,
>
> Robert J. Rademacher
>
> ================================================
>
> Maybe if you convert the
>  date to Julian Days that would help.  If
> possible maybe the RTC could trigger an interrupt to so you could
> count days since event#1.  I built a "TAB" timer not to long ago, but
> did the date compare as yy.mm.dd
>
>   TEST_RTC_TIME = (fix_hr * 100) + fix_min;
>   TEST_RTC_DATE = ((unsigned long)fix_rtc_yr * 10000)+((unsigned
> long)fix_rtc_month *100)+(unsigned long)fix_rtc_date;
>
>
> On Nov 14, 2007 11:42 PM, Robert Rademacher <robertrade at yahoo.com <http://dragonsgate.net/mailman/listinfo/icc-avr>> wrote:
> >* Hi all,
> *>*
> *>* I'm wondering if anyone has done the difftime routine for ICCAVR that would
> *>* compute the difference in minutes, using PCF8563 RTC. I know ICCAVR does not
> *>* have time.h library.
> *>*
> *>* Here is the elapsed minutes calculation:
> *>*
> *>* To compute for elapsed minutes (format: dd.mm.yy
>  hh.mm)
> *>*
> *>* Start date-time: 14.11.2007 10.15
> *>* Final date-time 15.11.2007 8.15
> *>*
> *>* Calculated for elapsed time: 22 hours or 1,320 minutes.
> *>*
> *>* This may look easy, but remember, we are dealing with leap year, specific
> *>* number of days/month, etc that need to be factored in when calculating the
> *>* difference between the start and end time-date stamps. It would be nice if
> *>* there is a RTC IC that has the mktime/gmtime I can read off instead of
> *>* individual numbers from date/time sections.
> *>*
> *>* I search everywhere for the code snippet designed for AVR and did not find
> *>* what I'm looking for as described above.
> *>*
> *>* Any good suggestions, as I'm bit pressed for deadline. I am sure everyone
> *>* may be interested in this potential
>  solution.
> *>*
> *>* Robert
> *>*
> *>*
> *>*  ________________________________
> *>* Get easy, one-click access to your favorites. Make Yahoo! your homepage.
> *>* _______________________________________________
> *>* Icc-avr mailing list
> *>* Icc-avr at imagecraft.com <http://dragonsgate.net/mailman/listinfo/icc-avr>
> *>* http://dragonsgate.net/mailman/listinfo/icc-avr
> *>*
> *>
> --
> Paul Mateer, AA9GG
> Elan Engineering Corp.
> www.elanengr.com
>
>
>  ------------------------------
> Never miss a thing. Make Yahoo your homepage.<http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>
>
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20071115/a9c32e8a/attachment.html


More information about the Icc-avr mailing list