alarm output

davidwf

Senior Member
I am using a 18M2 with a DS3231 real time clock module... with the help of the frum I have worked out how to set the time....... but how do I set an alarm time and how do I set a pin on the Picaxe to respond when that happens ?

cct & code attached for my curtains and lights controller.... I need PIC pin 8 (B.2) to go high for about one second

Thanks in advance.... I know someone will impart that information :)
 

Attachments

hippy

Ex-Staff (retired)
The DS3231 datasheet describes the use of the alarms and the conditions which can be alarmed on. You can program the INT/SQW pin to activate on an alarm and also check the status register over I2C to see if any alarms have been activated.
 

davidwf

Senior Member
Thanks hippy but that's waaaaay over my head :(
I was thinking more along the lines of something simple like this

' Setting the Time / Date
' To set the correct time after the circuit is first powered up, the current time must be
' written to the registers. The following example PICAXE program will setup the time
' to 11:59:00 on Thursday 25/12/03.
' This is carried out by loading the registers in order from address 00 upwards i.e.
' seconds then minutes then hours etc.

i2cslave %11010000, i2cslow, i2cbyte
writei2c 0, ($00, $59, $11, $03, $25, $12, $03, $10)




' Reading the Time / Date
' To read the current time you can use the following program to load variables within
' the PICAXE with the various register values from the DS1307. Calculations can then
' be carried out to see, for instance, if a particular alarm point has been reached. This
' example program acts as an alarm clock, checking the time every 30 seconds. If the
' time is exactly 07:00 then a buzzer, connected to output 7, will sound for 20
' seconds.

i2cslave %11010000, i2cslow, i2cbyte ' set slave parameter
do
pause 3000 ' wait 30 sec (set to 30000 in use, 3000 for simulation)
readi2c 0, (b0, b1, b2) ' read sec, min, hour
sertxd (#b0, #b1, #b2 , cr,lf)
' if b2 <> $07 then loop ' if hour not 7 loop
'if b1 <> $00 then loop ' if min not 00 loop
'high 7 ' switch on buzzer
'pause 2000 ' wait 20 sec 20000
'low 7 ' switch off buzzer
'pause 6000 ' wait 60 sec to prevent repeat

loop ' loop


but when I tried it all I get on the terminal screen is the attached
 

Attachments

westaust55

Moderator
Last edited:

hippy

Ex-Staff (retired)
but when I tried it all I get on the terminal screen is the attached
The data looks reasonably correct to me.

The main problem is that your SERTXD is not very well chosen. You would be better off changing that so that hours are displayed first and seconds last, with separators between the fields -

Code:
readi2c 0, (b0, b1, b2) ' read sec, min, hour
sertxd( #b2, ":", #b1, ":", #b0, cr, lf )
The RTC data is in BCD while the PICAXE outputs numbers as binary decimals so that can add to the confusion. It is probably worth converting those BCD values to binary decimal before display -

Code:
readi2c 0, (b0, b1, b2) ' read sec, min, hour
b10 = b0 / 16 * $FA + b0
b11 = b1 / 16 * $FA + b1
b12 = b2 / 16 * $FA + b2
sertxd( #b12, ":", #b11, ":", #b10, cr, lf )
 

davidwf

Senior Member
Westaust55.........File Type: bas DS3232 RTC demonstration code.bas.....

Yes, and that displays the time as it should.... but it is way too complex for my relatively simple task - to action an alarm on PIC pin 18 (C.1) for a few seconds every day
 

hippy

Ex-Staff (retired)
...but it is way too complex for my relatively simple task - to action an alarm on PIC pin 18 (C.1) for a few seconds every day
Your code in post #4 should be all you need. Just make the changes suggested in post #6 and see if that produces a more understandable display.

If it's showing what would be expected you can then add the alarm comparison code. If not post the results and that may show what's not working or why it looks different to what you were expecting.

One trick with clocks, timers and alarms is to use SOUND ... (100,100) to a piezo which can be on the same pin as the LED. It's much easier to not miss the beep than a LED flash when you get distracted. You don't have to sit their watching it intently, imagining it has flashed and then missing it when it eventually does :)
 

marks

Senior Member
Hi davidwf,
Alarms come up from time to time lol!
I sometimes find it simpler to stick with $bcd for time
but dates I nearly always convert to binary...

hope you don't mind I've added the example to post#16 so its easier for me to find.
http://www.picaxeforum.co.uk/showthread.php?18694-DS3231-Code-examples/page2

its a warm 37.9 C so it not going to be a white Christmas here!
Santa's lucky he delivers late cause he's gonna really need that coldie this year!!!
 

davidwf

Senior Member
The ds1307/ds1338 and the ds3231/ds3232 families have different register usage.

Have you looked at the DS3232 example I provided here:
http://www.picaxeforum.co.uk/showthread.php?23739-Getting-Started-with-the-DS3232-RTC-and-a-brief-comparison-of-some-other-RTC-chips


hmmm.... your code refers to pin C.7 but the DS3232 only has serial out not a direct connection so I don't think it will be possible to do that as there is no direct connection to pin C.7.... could be wrong of course
 

westaust55

Moderator
The DS3232 and ds3231 communicate using the i2c bus (serial comms protocol).

The PICAXE pin C.7 is used as an interrupt input in my code example to which the ds3232 RTC interrupt pin is connected. The PICAXE SetInt command is set to monitor C.7 and then output some text plus every 2 seconds pulse output C.6.
 
Top