In most cases, the precision of the crystal oscillator in your Arduino will be sufficient for you. But there are cases, especially when using more than one, that speed does matter. If you have a good frequency counter you can compare it yourself. If you don't, you can use an Arduino MEGA to do the job.
To compare the real values of F_CPU of two Arduino UNOs we uploaded some code to send the millis() to their Serial outputs:
const long baud = 9600;
void setup() {
Serial.begin(baud);
}
void loop() {
Serial.print(millis());
Serial.print("\n");
}
Now the Arduino MEGA has to read those values using its Serial1 and Serial 2 inputs (pins 17 and 19):
const long baud = 9600;
void setup() {
Serial.begin(9600);
Serial.println(__FILE__);
Serial1.begin(baud);
Serial2.begin(baud);
}
long accumulating1, accumulating2;
long actual1, actual2;
void loop() {
if (nlDetected(accumulating1, actual1, Serial1) ||
nlDetected(accumulating2, actual2, Serial2)) {
#ifdef DIFF_ONLY
Serial.println(actual1 - actual2);
#else
Serial.print(actual1);
Serial.print("\t");
Serial.println(actual2);
#endif
}
}
bool nlDetected(long &accumulating, long &actual, Stream &serial) {
bool istZiffer;
// do not use if (
while (serial.available()) {
char ch = serial.read();
istZiffer = isDigit(ch);
if (istZiffer) accumulating = accumulating * 10 + (ch - '0');
else {
actual = accumulating;
accumulating = 0;
}
}
return !istZiffer;
}
Take care when you connect all three devices to the USB ports of your computer. I had to use cables of different colors and label the ports not to get mixed up.
You need just two jumper wires from TX of the UNOs to pins 17 and 19 of the MEGA
When you open the Serial Plotter on the MEGA you will see some diagram like this:
When you reset both UNOs at the same time, the difference of their millis values will be rather low. But as time goes by, that difference will increase more or less. If you observe it over a long period you can check how much the crystals are different.
Comments