Pages: [1] 2   Go Down
Author Topic: Chronodot - Sync 1hz square wave?  (Read 2614 times)
0 Members and 1 Guest are viewing this topic.
St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to sync the 1hz square wave of the Chronodot to an interrupt or button press?  So that the square wave is in exact sync.

I'm working on a clock project and would like to sync the Chronodot's RTC to the exact time an interrupt goes off or the exact time someone presses a button (after setting the time into some variables).
Logged

0
Offline Offline
Shannon Member
****
Karma: 220
Posts: 12700
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The squarewave comes from the RTC oscillator divide-chain and as I understand it is not resetable except by stopping
and restarting the oscillator - and since the oscillator takes a while to start up you can't define the timing very well.

Well that's my understanding at least.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Edison Member
*
Karma: 50
Posts: 1697
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try setting the seconds when the button is pressed. You could, for example, set up your code so that the user pushes the button at exactly the minute and the code then just sets the seconds to zero. I think that will do it.

Pete
Logged

St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm... ok.  I guess I'll have to rethink how I setup my project.  My goal was to sync the Chronodot's clock to an interrupt set off by the pulse from the PPS pin of the Ultimate GPS.

Right now I get the time from the GPS and set the time on the Arduino (using time.h library) and on the Chronodot (using DS1307RTC.h library) once the interrupt goes off.   The time on the Arduino seems to be in sync with the GPS, for a while anyway until it drifts.  But, it looks like the Chronodot and the GPS are not synced (to within less than a second)  My hope was to sync the Chronodot to less than 50 milliseconds of the GPS.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4094
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

From the datasheet, p12:

Quote
The countdown chain is reset whenever the seconds register
is written. Write transfers occur on the acknowledge
from the DS3231. Once the countdown chain is reset, to
avoid rollover issues the remaining time and date registers
must be written within 1 second. The 1Hz square-wave output,
if enabled, transitions high 500ms after the seconds
data transfer, provided the oscillator is already running.

What you're trying to do should certainly be possible to within 50ms.
« Last Edit: March 18, 2013, 10:09:26 pm by Jack Christensen » Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok,  so it seems like I need to keep track of the number of mills from when the PPS goes off and then count up 500 mills and then set the time.

I'll try and write up a simple sketch to test it out.  Thanks!
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4094
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok,  so it seems like I need to keep track of the number of mills from when the PPS goes off and then count up 500 mills and then set the time.

I'll try and write up a simple sketch to test it out.  Thanks!

It's simpler than that. When the pulse from the GPS occurs, get the time from the GPS, set the RTC with RTC.set() and the system time with setTime(). The falling edge of the 1Hz signal from the RTC should then be synchronized with the pulse from the GPS.

Be sure to call setSyncProvider() in setup() to keep the system time in sync with the RTC time.
« Last Edit: March 18, 2013, 10:34:12 pm by Jack Christensen » Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's simpler than that. When the pulse from the GPS occurs, get the time from the GPS, set the RTC with RTC.set() and the system time with setTime(). The falling edge of the 1Hz signal from the RTC should then be synchronized with the pulse from the GPS.

Be sure to call setSyncProvider() in setup() to keep the system time in sync with the RTC time.

Being naive here, Is the pulse width from the RTC 500ms?
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4094
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Being naive here, Is the pulse width from the RTC 500ms?

I assume so, or darn close to it. By definition if it's truly a "square wave" it should have a 50% duty cycle but that's a term that might be somewhat loosely applied.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Edison Member
*
Karma: 50
Posts: 1697
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes. If you set up an interrupt to occur on the falling edge of the Chronodot's 1Hz square wave, those edges occur one second apart.

Pete
Logged

St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is the falling edge of the Chronodot's 1hz square wave when the clock ticks over a new second?  or is that on the rising edge?
Logged

Offline Offline
Edison Member
*
Karma: 50
Posts: 1697
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, in a test that I did it turned out to be the falling edge when the second ticks over.

Pete
Logged

0
Offline Offline
Shannon Member
****
Karma: 220
Posts: 12700
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try setting the seconds when the button is pressed. You could, for example, set up your code so that the user pushes the button at exactly the minute and the code then just sets the seconds to zero. I think that will do it.

Pete

Ah yes, I recall now - the seconds field is specially rigged to reset the counter.

The output is a square wave, and can be set to one of four different frequencies which are taps
on a ripple counter.  The pin is called SQW/OUT (square wave out).

One thing I've noted is that the square wave out is open-drain - pull-up resistor needed (just in
case anyone's playing with an RTC and getting confused).
Logged

[ I won't respond to messages, use the forum please ]

St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe I'm not doing something right with my code.  Currently I have my Interrupt from the GPS PPS pulse trigger setting the Chronodot, but when I compare the time between the two after it is set, they are never synced.  If I reset the sketch multiple times, they time they are out of sync is never the same.  It seems like the 500ms delay that is listed in the datasheet is not consistent.
Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't used a chronodot, but I've used the DS1307 and it's really pretty easy to set.  Time begins when you write to the seconds register, assuming the oscillator is already running, that's why they say the SQW output will go HIGH 500mS later.  Going LOW is when seconds tick.  The oscillator could take a couple of seconds to get going if it is disabled, so I always have it going when I set the time.  You need to know which edge of the GPS matters so you can trigger your interrupt at the right time and not try to wait 500mS to accommodate triggering on the wrong edge.  I think many GPS modules only guarantee the one edge is accurate, I don't think many guarantee a 50% duty cycle.  What kind of interrupt are you using to sync this up?
Logged

Experience, it's what you get when you were expecting something else.

Pages: [1] 2   Go Up
Jump to: