Melanies RTC code has broken


Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Feb 2003
    Posts
    432

    Unhappy Melanies RTC code has broken

    Hi All,

    This is aimed at anyone using Melanies RTC code in a project particularly if you use the Calculate Day of Week & Save part of the code which includes the following warning....

    Melanie's fudge for calculating Days of Week using PBP's integer math...
    by the time someone's clock displays the wrong Day of Week, I'll hopefully have long retired and be past caring...
    I wouldn't however go stick this routine in a Nuclear Power Station to purge the reactor every Monday morning without checking how far it will work before the integer math overflows...
    In my routine RTCWDay=1 is a Tuesday (the start of my week) and continues sequentially until RTCWDay=7 which is a Monday


    It seems the end may have come earlier than anticipated

    Melanies original code is as follows...

    Code:
    CounterA=SetYear+4
    CounterB=SetMonth
    If SetMonth<3 then
    	CounterA=CounterA-1
    	CounterB=CounterB+12
    	endif
    CounterD=(SetDay+(153*CounterB-457)/5+365*CounterA+CounterA/4-CounterA/100+CounterA/400+2) MOD 7
    RTCWDay=CounterD+1
    My 9 year old daughter took great delight in informing me that the LCD on my current project was displaying
    FRI 04 OCT 2006

    I knew the code had been working fine so I set about investigating when it went wrong and was using http://www.timeanddate.com/calendar/ as a reference calendar. Listed below is the point where it breaks this year. The problem only occurs when actually setting the RTC so provided you set it early enough in the year you will be fine !!!

    SEPTEMBER 2006
    03 SUN
    04 MON
    05 TUE
    06 WED
    07 THU
    08 FRI
    09 SAT
    10 SUN SAT -1 Day

    11 MON SUN -1 Day
    12 TUE MON -1 Day
    13 WED TUE -1 Day
    14 THU WED -1 Day
    15 FRI THU -1 Day
    16 SAT FRI -1 Day
    17 SUN SAT -1 Day
    18 MON SUN -1 Day
    19 TUE MON -1 Day
    20 WED MON -2 Days

    21 THU TUE -2 Days
    22 FRI WED -2 Days
    23 SAT THU -2 Days
    24 SUN FRI -2 Days
    25 MON SAT -2 Days
    26 TUE SUN -2 Days
    27 WED MON -2 Days
    28 THU TUE -2 Days
    29 FRI WED -2 Days
    30 SAT WED -3 Days


    OCTOBER 2006
    01 SUN TUE +2 Days
    02 MON WED +2 Days
    03 TUE THU +2 Days
    04 WED FRI +2 Days
    05 THU SAT +2 Days
    06 FRI SUN +2 Days

    I tried the first of November and December this year and they also came out wrong.

    I was surprised find that 01 JAN 2007 came out with the correct day so I tried the first of the month for each month of 2007 and 2008 and in each case OCT, NOV, DEC were wrong. 01 SEP 2007 came out correctly but several random dates tried for Aug 2007 were broken.

    I tried "01 JAN 20xx" which failed when I got to 2011

    Is this something that is fixable by breaking the calculation into smaller chunks rather than attemting everything in a single calculation?

    Its way too late for me to try and manually work out a calculation with that many parts but if someone wants to try with the numbers above then feel free

    I hope this can be fixed because the DayOfWeek is more important in my application than the actual date!

    I would be grateful if others who may be using this code can check if theirs is broken as well.
    Last edited by keithdoxey; - 6th October 2006 at 01:09.
    Keith

    www.diyha.co.uk
    www.kat5.tv

Similar Threads

  1. Broken code
    By sinoteq in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 2nd December 2014, 13:17
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. X1226 RTC - Help
    By charudatt in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th August 2006, 17:54

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