ds1307 Day Light Saving Adjustment for Aust.

mushroom

New Member
I'm trying to change Hippy's excellent code to auto- adjust for day light saving, so it works in Australia. Has anyone already done this? My brain is turning to mush just trying. It it complicated by the fact our DLS time starts and ends in two different years and that it must include Feb 29 in leap years.
Hippy's code is written for British time where BST starts last Sunday of March and ends last Sunday of October, both change over at 2am. (BST time). In Australia our Day Light Saving, (DLS time), starts first Sunday of October and ends first Sunday of April the next year.
Hippy's code is in Code Snppets Page 8 thread 18468 from May 28 2011.
Hopefully someone has re-coded this for Australia and can save me form brain damage. If not I'll persevere and post a solution if I'm successful .
 

hippy

Technical Support
Staff member
Here's the link to the original -

https://picaxeforum.co.uk/threads/ds1307-rtc-with-gmt-bst-auto-adjustment.18468/

I haven't done Australian DST but should be easy enough. (1) Find the October date it starts on and April date it ends on, (2) Alter the 'Is it DST' code to be yes if up to the April date, or after the October date, no otherwise. For (1) set the day to 1, keep incrementing until that's a Sunday.

I'll take a look at the code later to see if I can see what to change. Others are welcome to have a go if they want.
 

marks

Senior Member
Hi mushroom,
I remember doing one for aus before but could not find it,which is a pity as I always like to try and improve .
the original used mixed AND and OR commands but it always takes me a while to relearn how to use this and test.
So I've just used lots of AND lines in my adjust code,which doesnt seem too add much extra code.
I think I've covered all bases but does need checking, just post if you find something .
Program DS1307 with standard time and date and it will correct in the dst period.
I will add to DS1307 code examples ,so I can find it in the future!
and add day correction mon tue ,etc which can be calculated from date, so no need to program day.
https://picaxeforum.co.uk/threads/ds1307-code-examples.18505/

Code:
#picaxe 18m2
#terminal 38400 'marks
  SYMBOL index    = b0 
  SYMBOL year     = b1
  SYMBOL month    = b2
  SYMBOL date     = b3
  SYMBOL hours    = b4
  SYMBOL mins     = b5
  SYMBOL secs     = b6  
  SYMBOL Day        = b7
  SYMBOL CommonYear = b8
  SYMBOL DayNumber  = W6 
  SYMBOL DSTend     = W7  
  SYMBOL DSTstart   = W8 : SYMBOL DayS = W8
 
    SETFREQ M32      
 InitialiseTime:
    HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte  ' Set  DS1307 to 100kbps 
      HI2Cout $0 , ( $30, $59, $01,day, $07 , $10 , $18) ' program DS1307 with GMT 
 Main: pause 8000
    HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte  ' Set  DS1307 to 100kbps 
      HI2Cin  $0 , (secs,mins,hours,date,date,month,year) ' Read DS1307 
        FOR bptr = 1 TO 6   
          @bptr = @bptr/$10*250+@bptr                     ' Convert BCD to Decimal  
        NEXT
 AustralianDST:
     CommonYear = year //4 +3 /4            'CommonYear =1 
     DayNumberOfTheYear:                 
      DayNumber = month +9 /12   
      DayNumber = CommonYear + DayNumber * DayNumber
      DayNumber = month *275 /9 +date -30 -DayNumber 
     
       DayS = year *512 **46752             'year01-99
     DayLightSavings:
      DSTend = Days +96 //7                 
      DSTend = 98 -CommonYear -DSTend     'First Sunday in April        
   DSTstart = Days +279 //7                 
        DSTstart = 281 -CommonYear -DSTstart  'First Sunday in October
          
 IF DayNumber > DSTend AND DayNumber < DSTstart THEN StandardTime 
 IF DayNumber = DSTstart AND hours <2 THEN StandardTime  'Australian DST starts at 0200 
 IF DayNumber = DSTend   AND hours >1 THEN StandardTime    'Australian DST ends at 0200
       IF hours =23 THEN 
         INC date
     IF date =32 THEN AdjustDate
               IF date =31 and month =11 THEN AdjustDate 
          IF date =30 and month =2  THEN AdjustDate
          IF date =29 and month =2  and CommonYear =1 THEN AdjustDate 
       ENDIF  
     GOTO AdjustHour
        AdjustDate:date =1 : month=month//12+1 :IF month=1 THEN INC year : ENDIF
          AdjustHour:hours =hours +1//24 : Sertxd ("DST  ")
     
 StandardTime: 
   sertxd ("20",#year,"/",#month,"/",#date,"    ")    ' Date 20yy/mm/dd 
         index = mins/10 :mins = mins//10                  
          sertxd (#hours,".",#index,#mins)                 ' 24hr time hh/mm/ss          
         index = secs/10 :secs = secs//10
          sertxd (".",#index,#secs,CR,LF)
   goto main
 

mushroom

New Member
Back to the computer after the weekend. Thanks Hippy and Marks. Marks, I'll look at your code later today and report my inevitable problems. (with my understanding, not your code).
Hippy, I'm most impressed with your code, as usual. I've started to alter it to suit Aust. Still need to sort out Feb 29, leap years. When I have code that works I'll post. We need a working code package for Aust and New Zealand .
 

mushroom

New Member
Thanks Marks. I'm yet to study your code in detail and try it. I can see gains in my knowledge as I investigate. Today I'm assembling blank boards that just arrived from China which will support this code. I expect to try it tomorrow. I'll report back.
 

inglewoodpete

Senior Member
@mushroom, If you're marketing to the whole of Australia, don't overlook that around 60% of the Australian continent does not have daylight saving. I'm so glad I live in WA :).
 

MurrayJ

Senior Member
For a very amusing look at programming time zones look up Toms Scott's video. It made me sympathise with what programmers have to put up with just to let us normal everyday folk get on with our "digital" lives. The video is called -

The Problem with Time & Timezones - Computerphile
 

mushroom

New Member
MurrayJ . I viewed that video. Thanks. My takeaway point. Just don't do it. Don't cover multiple countries time-zones unless you thrive on stress.

inglewoodpete . Yes. I believe the Republic of Queensland does not have daylight saving either. My current need is local, self need, South Australia. I can see the difficulty of country wide marketing. One would need to mark units for the proposed 'State' of use, else a branch in Qld might need a unit that NSW branch has on the shelf. etc.
 

mushroom

New Member
Praise to Marks for his Day Light Saving code. I recommend it, but I ask anyone who uses it to express any problems they find for the benefit of all. Have not faulted it, though I must admit to a lack of testing owing to the crazy onset of Xmas increasing both my work and domestic demands.
Now a boast from a proud Dad. (I'm a 60 yo). My oldest of 3 children is in year 7 at school and has just passed his year 11 math with an A+. Many parents help their children with Math. My son helps his Dad.
 

lbenson

Senior Member
Congrats on the smart son. Can't speak to the code, but the DS3231 has better accuracy than the DS1307.
 

tommo_NZ

New Member
Congrats on the smart son. Can't speak to the code, but the DS3231 has better accuracy than the DS1307.
Must agree with Ibenson especially with regard to accuracy of cheap chinese RTCs from EBay, I bought several DS1307 at a couple of dollars each and was disappointed with them, however you get what you pay for. Then I got several DS3231 modules and am very pleased with them. Accuracy is not perfect but seconds per week is OK for me at $2~$3 each.
 

inglewoodpete

Senior Member
My last PICAXE clock was based on a cheap GPS module. I'd recommend them to anyone: they never slip out of time. Due to the GPS, you could even code the PICAXE to determine when and where to apply DST!
 

tommo_NZ

New Member
Thanks guys, you have successfully used the GPS units, so do you have a make/model number so we don't have to try several to get it right.
 

mushroom

New Member
Agreed to the improved accuracy of DS3231 over DS1307. I won't use DS1307 again. My accuracy needs are covered by the DS3231 and the price is good, however I second tommo_NZ's request for detail as to a suitable GPS unit. I'd assume the increased accuracy would come at a significant price increase.
 

inglewoodpete

Senior Member
I bought a couple off an Ebay supplier in China back in 2012. The supplier is no longer listed on Ebay. From memory, they were around A$20 each.

Documentation for the GAM-2222 based module was pretty scant at the time but, thankfully, it just worked. 3.3v supply required and it output 9600 baud data packets.
GAM-2222-SKR GPS-Module.JPG
I documented the basics of a GPS data receiver using an X2 PICAXE here. However, I have seen simpler, perhaps less robust versions using M2 chips.
 

Pongo

Senior Member
I used a Ublox NEO-6M module (with the bigger square antenna), there are dozens of them for sale on ebay for < $10
 

hippy

Technical Support
Staff member
I believe most GPS modules should be capable of presenting time and date messages. It would likely have to be something designed for very specific purposes, and only that, which would not.

I would be tempted to risk an investment in a quite cheap serial output eBay / Chinese GPS module with included antenna just to see how well that does.

Cat-5 or 4-core alarm cable should be enough to get power, 0V, serial transmit and receive between a PICAXE and wherever the GPS needs to be put for good reception. If it sends appropriate messages at turn on you can probably use 3-core audio cable.
 
Last edited:
Top