OMG indeed. This is why my spaceships keeping flying into the Moon rather than flying on to Mars. Now I think about it, I've noticed this before but never given it much attention, assuming it was my imagination.
I wonder if this is why some Arduino hardware libraries fail to work when ported over to the Maple? Anything with delay(100)
etc in it for timing (say, clock pin toggling or waiting for hardware) would be out by 3/10 of a second?
I thought I understood assembly but that bit of code looks like nonsense to me? [us] "r" (us) ??! "r0" !?
Anyway, what's the fix? Changing that define from 12 to 15,16 produced 836, 1337 (!) - not much use.
I changed the delayMicroseconds(1000);
in wirish_time.cpp to delayMicroseconds(1496);
which is clearly a fudge, but a fudge that works is better than a 1 second delay that only last .7 seconds!
This still leaves delayMicroseconds as being very inaccurate - according to the Arduino docs it's meant to be very accurate above 3ms. Clearly the maple one isn't (?)
Test program used (I also used the visual of clock hand to led flash, which clearly showed how bad delay(1000) actually was.
//#include <Wire.h>
#define Serial SerialUSB
void setup()
{
pinMode(BOARD_LED_PIN, OUTPUT);
}
void loop()
{
int millitest;
int time;
togglePin(BOARD_LED_PIN);
time = millis();
delay(1000);
millitest=millis()-time;
Serial.print("millis = "); Serial.println( millitest);
}
I'm running on an Olimexino, which returned 669ms for 1 second. With code change above, returns 1000. Which'll do until a proper fix comes along.
Is the original delay_us() flawed because it does a multiplication which takes longer than 1us?