how faithful is this code to RTC?


i am making a master clock, and i am using the following code. if i am correct, in the void setup the code syncs the system with the RTC only on startup… however i believe i should be syncing to the RTC more frequently and/or using only the RTC time and not the system clock. is this possible? what would be the most accurate way to send a pulse every minute over a long period… any suggestions would be greatly appreciated :o

#include <DS1307RTC.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <Wire.h> 

int enA = 10;
int in1 = 9; 
int in2 = 8; 

void setup()
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
  Serial.println("In setup....");
  using rtc, sync system time to rtc
   setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011 //old way *****************

  // following lines added to set time from rtc, took from timeRtcSet example, added jim *****************
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if (timeStatus() != timeSet) 
    Serial.println("Unable to sync with the RTC");
    Serial.println("RTC has set the system time");
  // end of setting the time ******************************

Alarm.timerRepeat(60, Repeat);            // pulse every 60   seconds

  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  Serial.println("Ending setup....");

void digitalClockDisplay()
  // digital clock display of the time

void printDigits(int digits)
  if(digits < 10)

void Repeat() {
  digitalWrite(enA, HIGH);
  digitalWrite(9, !digitalRead(9));  // toggle state
  digitalWrite(8, !digitalRead(8));
  digitalWrite(enA, LOW);

void  loop(){  


The default sync interval is 300 seconds (5 minutes). You can change it with setSyncInterval().

hey john!

thanks for the reply. so as is, it syncs every 5 min? even though the sync with rtc is in the void setup? if so, thats perfect. thanks again

setSyncProvider just tells the Time library where to go to sync it's time. The Time library has the code that will go there and get the updated time every 5 mins (or whatever interval you select). So it only appears in setup because you only need to tell the Time library once where to go.

It's like if I gave you a job and told you to pick up your paychecks in the Secretary's office. I wouldn't have to tell you again every week on payday where to go. I just need to tell you once in the beginning and from then on you should know where to go to get it.