Hi,
I've just "compared" two Mega 2560 Rev3 boards and measured 189ms "drift/innaccuracy/[?]" difference between the 2 boards in 9 minutes !
Setup is as follow :
- Same power supply
- Trigger is set on Pin 20 of each board, in common
- I randomly trig by putting low level on the two pins at the same time
- See simple code below
Difference of micros() last line is 189144, so 189ms!
Do I have bad/damaged boards? (as far as I know they are genuine, I ordered them from RS Components, Belgium) or am I completely missing the point here...
?
As far as I've read on the forum, with +/- 50 ppm, I should not get more than a few µs difference in a few minutes testing!?
Kind regards and thank you in advance for your help!
Here is log from Board #1:
11:43:15.528 [RX] - Booting testDetection...
11:43:18.841 [RX] - Detection @ 3312;3313124
11:43:19.877 [RX] - Detection @ 1033;1033164
11:43:28.806 [RX] - Detection @ 8929;8928532
11:44:06.843 [RX] - Detection @ 38029;38029612
11:44:09.157 [RX] - Detection @ 2313;2312280
11:46:01.712 [RX] - Detection @ 112529;112528740
11:54:59.926 [RX] - Detection @ 538098;538098940
Here is log from Board #2:
11:43:15.861 [RX] - Booting testDetection...
11:43:18.842 [RX] - Detection @ 2978;2979636
11:43:19.874 [RX] - Detection @ 1034;1032792
11:43:28.808 [RX] - Detection @ 8925;8925300
11:44:06.846 [RX] - Detection @ 38016;38015892
11:44:09.156 [RX] - Detection @ 2311;2311448
11:46:01.710 [RX] - Detection @ 112488;112488460
11:54:59.926 [RX] - Detection @ 537911;537909796
Sketch code:
volatile bool triggered = false;
volatile unsigned long lastBarrierCrossedTimeStampMillis = 0;
volatile unsigned long lastTimeStampMillis = 0;
volatile unsigned long lastTimeStampMicros = 0;
volatile unsigned long deltaMillis = 0;
volatile unsigned long deltaMicros = 0;
void setup()
{
pinMode(20, INPUT_PULLUP); //DETECT
attachInterrupt(3, detection, FALLING);
Serial.begin(115200);
Serial.println("Booting testDetection...");
}
void loop()
{
while (true)
{
if (triggered)
{
String s = "Detection @ "; s = String(s + deltaMillis + ";"); s = String(s + deltaMicros);
Serial.println(s);
triggered = false;
}
}
}
void detection ()
{
unsigned long nowMicros = micros();
unsigned long nowMillis = millis();
if (!triggered)
{
deltaMillis = nowMillis - lastTimeStampMillis;
deltaMicros = nowMicros - lastTimeStampMicros;
triggered = true;
lastTimeStampMillis = nowMillis;
lastTimeStampMicros = nowMicros;
}
}