Skip to content

PICAXE Clock Exercise: DST issues

It’s the second Sunday in March so a lot of folks have had to adjust their clock for daylight savings time. The clocks that pick up the WWVB radio signals often auto adjust but the manually set clocks like many alarm clocks and clocks in thermostats need to be reset manually.

Since the clock chip in this exercise does include a calendar, it seems it’d be a simple thing to provide for automatic daylight savings time adjustments. But that chip runs on its battery backup when you turn the PICAXE and display off and it doesn’t do automatic DST adjustments by itself. What happens if you turn your PICAXE clock off in the evening and then back on in the morning after the magic 2 a.m. DST adjustment time? What do you do if your area doesn’t do DST or your clock is showing UTC?

What that means is that you need to check the DST status when you start up your PICAXE clock to see if a DST adjustment needs to be made. You need to have at least two flags stored somewhere, like the clock SRAM, that you can use to enable DST adjustments and to note whether or not DST is in effect. Then you have to compare the clock data to the DST rules and manage these flags to make any adjustments necessary.

The rules seem simple. In the U.S. they are (at this time at least) to start DST at 2 a.m. on the second Sunday in March and the end it at the same time on the first Sunday in November. That means you need to know the day of week reliably, determine when the date for the proper Sunday in March or November in the current year falls and compare that to the current date and time. That’s for the start-up routines to see if the PICAXE was off when a changeover occurred.

If the PICAXE is on at changeover time, it needs to successively test for whether or not DST is enabled, whether the calendar is in March or November, whether the day is a Sunday or not, whether that Sunday is the second one in March or the first in November, whether it is 2 in the morning, and then whether the DST in effect flag is properly set for the time and date. That last condition is important so you don’t keep setting the clock back in the fall from 2 to 1 in a continuous loop.

A lot of decisions makes for code complexity. That means there is plenty of opportunity for error. It is a good chance to find out just how complicated seemingly simple things can be.

Post a Comment

You must be logged in to post a comment.