About Time

The Arduino millis counter is a little bit to slow.

So every approx 41 tick the interrutp routine adds a leap milliscond

Here is a simple test program that shows it.

/*
* Simple test program that show Arduino UNO (328P cpu) approx every 40 millisecond
* add a leap millisec to the millis counter !!!
* /JENS
*/
/*
* Simple test program that show Arduino UNO (328P cpu) approx every 40 millisecond
* add a leap millisec to the millis counter !!!
* /JENS
*/
unsigned long m, mOld, oneCount;


void setup() {
  Serial.begin(115200);
  m = mOld = millis();
  oneCount = 0;
}

void loop() {
  m = millis();

  switch (m - mOld) {
    case 0:
      break;
    case 1:
      oneCount++;
      break;
    case 2:
      oneCount++;
      Serial.print('2');
      Serial.print(" ");
      Serial.println(oneCount);
      oneCount = 0;
      break;
    default:
      Serial.println("larger than 2");
  }
  mOld = m;
}