PDA

View Full Version : My Teensy alarm clock



bigpilot
10-08-2013, 01:42 PM
1003

It has one feature which I'm still missing on most if not all stand alone clocks and alarm clocks: automatic daylight savings time adjustment. I'm doing this without radio-adjustment or a connection to the Internet.

There's currently no 'snooze' function implemented, but I've got a big red button somewhere if I feel the need in the future ;)

I wrote the C code all by myself, including the HD44780 device driver.

I can post the code and schematics if people are interested.

t3andy
10-08-2013, 02:05 PM
I can post C code and schematics if people are interested

Sure ... post it.:D


automatic daylight savings time adjustment

What you need to do is collect, from the internet, the projected bi-yearly dates for the daylight
savings time adjustment. (10 years worth) Install these date values in a table and read it to see if
you need to add 1 hour or substract 1 hour to the RTC. (Spring forward or fall back) :cool:

bigpilot
10-08-2013, 05:10 PM
1004

Here's the schematic.

bigpilot
10-08-2013, 05:31 PM
1057

Here's the source code, including the Make file.

NOTE: updated the zip file to fix some bugs. The alarm wouldn't sound if the alarm time was exactly on the hour. Also I fixed the bugs with the leap year and the days in the month as discussed in the posts below.

NOTE: Updated the source code again to fix the DST because when the clock is set backwards the routine keeps being called so it gets stuck between 01:00 and 02:00. I made the check daily to resolve this issue.

bigpilot
10-08-2013, 05:35 PM
What you need to do is collect, from the internet, the projected bi-yearly dates for the daylight
savings time adjustment. (10 years worth) Install these date values in a table and read it to see if
you need to add 1 hour or substract 1 hour to the RTC. (Spring forward or fall back) :cool:

No, I'm computing it from rules. Look at the function CompensateForDaylightSavingsTime() in my code.

t3andy
10-08-2013, 08:13 PM
No, I'm computing it from rules. Look at the function CompensateForDaylightSavingsTime() in my code. .

Cool, shorter way of doing it. You show October in your rules? You must not be in the USA?


void CompensateForDaylightSavingsTime( void )
{
if ( timedate.month == MARCH && timedate.date == GetDateOfLastSundayOfTheMonth( MARCH ) && timedate.hour == 2 )
{
timedate.hour = 3;
}

if ( timedate.month == OCTOBER && timedate.date == GetDateOfLastSundayOfTheMonth( OCTOBER ) && timedate.hour == 2 )
{
timedate.hour = 1;
}
}


DST Rule <----- For US citizens
Starts: Second Sunday in March
Ends: First Sunday in November
Time: 2 am local time

BTW ... not to nick-pick but just being helpful ...

Thirty days hath September,
April, June, and November;
Thirty-one the others date,
Except in February, twenty-eight;
But in leap year we assign
February, twenty-nine.

Jan should be 31 ?


const char days_in_month[] = {30, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bigpilot
10-09-2013, 09:52 AM
You're right. The days_in_months array should be:


const char days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

and the leap year compensation should be:



if ( IsLeapYear() && month == FEBRUARY )
{
return 29;
}


Thanks for your observation.

t3andy
10-09-2013, 06:28 PM
So you are saying that your auto DST algorithm will not work for US citizens because it is made for a different country DST?

bigpilot
10-10-2013, 06:54 AM
So you are saying that your auto DST algorithm will not work for US citizens because it is made for a different country DST?

That is correct. I originally wanted to make it a menu option so you could select between different countries, but haven't implemented it (yet).

Nantonos
10-10-2013, 10:30 AM
So you are saying that your auto DST algorithm will not work for US citizens because it is made for a different country DST?
Or to put it another way, most European countries and the USA changed on the same dates for a few years, then the US went its own way with a different formula.

t3andy
10-10-2013, 11:55 AM
then the US went its own way with a different formula.
They did to "save more energy" and to prevent school children from being run over, due to darkness, going to school as the story goes.

BTW ... cool "Teensy 2" project.

Below ... Untested auto DST code patch for Yankees - US citizens.


Untested auto DST code patch for Yankees - US citizens.


/*
DST Rule <----- For US citizens
Starts: Second Sunday in March
Ends: First Sunday in November
Time: 2 am local time
*/




void CompensateForDaylightSavingsTime( void ) // patch for Yankees

{
if ( timedate.month == MARCH && timedate.date == GetDateOfSecondSundayOfTheMonth( MARCH ) && timedate.hour == 2 ) // spring forward
{
timedate.hour = 3; //
}

if ( timedate.month == NOVEMBER && timedate.date == GetDateOfFirstSundayOfTheMonth( NOVEMBER ) && timedate.hour == 2 ) // fall back
{
timedate.hour = 1; // <------<<<< needs lockout flag to prevent multiple updates
}

}


int GetDateOfSecondSundayOfTheMonth( int month ) // spring forward - 2nd sunday
{
int date = 1;

while ( DayOfWeek( timedate.year, month, date ) != SUNDAY )
{
date++;
}

date++;

while ( DayOfWeek( timedate.year, month, date ) != SUNDAY )
{
date++;
}

return date;
}


int GetDateOfFirstSundayOfTheMonth( int month ) // fall back - 1st sunday
{

int date = 1;

while ( DayOfWeek( timedate.year, month, date ) != SUNDAY )
{
date++;
}

return date;
}

bigpilot
10-13-2013, 01:36 PM
I've used a power measuring wall wart to test the power consumption and it uses 4W continuously. That's probably because I'm not using interrupts for the keys or sleep mode.

I'm keeping the power consumption down by keeping the input voltage at the lowest possible level (7.5V) to minimize the voltage drop across the voltage regulator.