Alarm clock using ds 1302
kodaleshen
Posts: 15
in Propeller 1
anyone have any sample code on how to get a RTC to do something at a certain time like lite a light or sound a alarm.
I am using a propeller board of education with propeller spin.
I am using a propeller board of education with propeller spin.
Comments
so how about something like:
im getting an error i have
if (heure = 11) AND (minutes = 18)
lcd.init( 2, 19_200, 4) ' start lcd
lcd.cls ' clear the lcd
LCD.str(String("alert")) ' First line
im getting the error at the = it says expected ")". not sure what that error is.
should be
Pardon me for being picky about how the problem is framed, but this RTC (DS1302) will not do something. Some RTCs have an alarm function that can set an output at a certain time, but this one will require the Propeller to "do something". I believe that you already know that, but stating a problem incorrectly can lead to crazy answers on a forum.
That said, the above post by Alexander points out a syntax issue. Within the conditional "IF" statement, using "==" will evaluate the equality of the two items (as opposed to "=" which is generally used to set one term equal to another).
Cheers!
As an aside, one of the RTCs with a built-in alarm is the DS3232. It has a register for day-of-week which I would have implemented differently from the way they did. They specify a value (1-7) to specify the day-of-week. I would have done a mask so that you could have an alarm on a number of day-of-weeks, say Mon-Fri.
I have been doing this in Forth on the Propeller and using Unix's UTC as my clock's underlying format. It happens to be one 32bit value. Anything is possible, daily alarms, one shot alarms, weekly alarms, DOW alarms, Monthly alarms, Annual calender alarms. But they all read one 32 bit code in UTC that ticks at one-second rate.
Of course, you can go either way. With using the RTC's alarm clock feature with independent power, it could actual turn on (and off) the Propeller when the alarm is triggered. That might be a very valid use.
Forth is interactive. So it allows you to change your alarms or to override your alarms at anytime from a serial terminal. You can also monitor what alarms are set or divert an alarm to do something different - like go from beeping to flashing a LED.
Coding daily alarms is much easier than longer periods as hours and minutes are regular cycle. DOW is also a regular cycle. But calendar events require something a bit more sophisticated as the months are different lengths, you have leap years, and the DOW relationship to calendar year has a 7 year cycle.
While it does add interactive programing and interactive control the "Propeller Alarm", this project can use the UTC form in any language: SPIN, PASM, C, PropBasic.
It just makes far more sense to me to read the RTC once, that to keep going back and forth over SPI or I2C (which can actually be a speed bottleneck).
It would be much easier to just read a 32bit counter that is running continously on its own backup power. And I am please to see that such a device does exist and will even take its own crystal to clock by.
The interface to the Propeller is I2C.
If you used this, you would look up the UTC value to today's time and day and set the device by sending one 32bit value to it. From then on, you just have to read one 32bit value to represent everything and decode the portion that applies to your alarm. The 32bit counter contiously counts seconds, so I am sure it is for UTC.
https://www.maximintegrated.com/en/products/digital/real-time-clocks/DS1672.html
I know the other RTC chips are easy to buy in ready to go fashion, but this seems a much more direct approach for the Propeller. You can even have it share the same I2c pins with the existing EEPROM.