Hello everyone, I currently own an Arduino Duemilanove and have enjoyed using it. However, I have had one issue with it and that is getting accurate timing from it. I've visited the IRC channel and asked about this but never got much response so I thought I'd try and ask here.
Basically, I need to fire off a commands within 16.6667ms intervals (1/60th of a second). I found using various timing techniques with the Arduino (using loops with millis(), micros(), delay(), delayMicroseconds(), and even using hardware interrupts) and none ever give me precise timing. The Arduino will usually end up being too fast or too slow by 1ms and sometimes right on the money. I need something more accurate and consistent.
So, that leads me to my questions, I recently ordered an Arduino Mega (I really love these things so I wanted to give this a shot as well) and a Chronodot RTC module. I plan to make a loop that checks the time on the Chronodot and to fire off the commands when 1/60th of a second has passed.
I've seen examples of the Chronodot on their website:
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
// send request to receive data starting at register 0
Wire.beginTransmission(104); // 104 is DS3231 device address
Wire.send(0); // start at register 0
Wire.endTransmission();
Wire.requestFrom(104, 3); // request three bytes (seconds, minutes, hours)
while(Wire.available())
{
int seconds = Wire.receive(); // get seconds
int minutes = Wire.receive(); // get minutes
int hours = Wire.receive(); // get hours
seconds = (((seconds & 0b11110000)>>4)*10 + (seconds & 0b00001111)); // convert BCD to decimal
minutes = (((minutes & 0b11110000)>>4)*10 + (minutes & 0b00001111)); // convert BCD to decimal
hours = (((hours & 0b00110000)>>4)*10 + (hours & 0b00001111)); // convert BCD to decimal (assume 24 hour mode)
Serial.print(hours); Serial.print(":"); Serial.print(minutes); Serial.print(":"); Serial.println(seconds);
}
delay(1000);
}
So my questions are:
- Why is the calculation to get the seconds the exact same calculation as getting the minutes?
- How can I convert the data received from the Chronodot into even smaller increments than seconds, for instance, milliseconds, microseconds, nanoseconds, ETC....
- Will using a Chronodot as my timing mechanism give me the consistent results that I am looking for?
Thank you for any help you can provide!