Arduino keeps time like a Dali clock- help?

Hiya,

I'm using the Arduino Decimila, not exactly sure which hardware rev but it's pretty new. I'm using it to control an old-fashioned split-flap clock from the 70's, which needs a pulse to tell it to switch to the next minute.

I tried doing it with both delay()'s and millis(), but either way the result is the same: Over the course of an hour, the Decimila gains about 5-8 seconds of time, so that after a day, the clock is running several minutes fast. This happens gradually, and not all at once -- At first I thought it might be the overflow on millis(), but it's not.

A Casio watch from the 70's keeps time better than the Decimila -- why?

Do I really need to hook this thing up to a computer and have the computer control the time? That seems like a bit much just for a simple clock.

Any ideas? Is there something wrong with my hardware maybe?

Thanks, Av

The dalay and millis functions are really not ment to do accurate timing over extended periods of time.

There are some examples of people useng a real time clock Ic to give accurate time and date info with the arduino.

Check this forum thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191209057/15

MikMo http://www.mikmo.dk

Alternatively you can calculate exactly how much the drift is and compensate. I believe those functions are accurate but dont take in to account the amount of time the instructions themselves take.

Thanks for the advice, guys.

The solution I ended up going with… I bought the following additional components:

  • DS1307 Real-Time Clock chip with i2c interface
  • 32.768khz crystal

I connected like so:
On the DS1307
Pin 1: Crystal (no capacitor)
Pin 2: Crystal (no capacitor)
Pin 3: Ground
Pin 4: Ground
Pin 5: Analog Input 4 on Arduino
Pin 6: Analog Input 5 on Arduino
Pin 7: Digital Pin 8 on Arduino
Pin 8: 5V Power from Arduino

The RTC chip won’t run until you initialize it. Here’s my code:

#include <Wire.h>

int ledPin = 13;                // LED connected to digital pin 13
int timepin  = 8;                // Time input connected to pin 8
int lastReading = 0;            // Last reading from the second pin

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  pinMode(timepin, INPUT);      
  
  Wire.begin(); // join i2c bus (address optional for master)
  delay(100); // Make sure the clock chip has time to get going

  Wire.beginTransmission(104); // transmit to device #104, the ID of the DS1307 chip
  Wire.send(0x00); // Register 0 (seconds and clock enable)
  Wire.send(0x08); // 00001000, last bit is "enable" on CH, we dont' care about the rest
  Wire.endTransmission();    // stop transmitting

  // Enable the 1hz counter.
  Wire.beginTransmission(104);
  Wire.send(0x07); // Register 7 (CONTROL)
  Wire.send(0x10); // 00010000, square wave output on and set to 1hz (pin 7 on DS1307)
  Wire.endTransmission();    // stop transmitting

  delay(200); // Give it time to start counting.
}


void loop()
{
    //  Read the Time pin.
    int rd = digitalRead(timepin);
    
    if (rd != lastReading) // See if it has changed since last read.
    {
       // THE CODE HERE WILL RUN ONCE A SECOND, and will be a lot more accurate than the arduino is on it's own.


       lastReading = rd; 
    }
    
}

Cool.

Did that make the old shool clock tick correctly ? I would love to find one of them - a BIG one like the old signs on the train stations

It did, but I'm now retooling my efforts to make it even cooler -- by having the Arduino and the RTC chip keep track of daylight savings and things like that.

Here's a video of it from before, it's pretty big: http://youtube.com/watch?v=2IRkG5m9b_Y

Thanks for all your help.