UCorrected timing OCR2A register.
authorJ. Hendrix <gitweb@localhost>
Sat, 14 Sep 2013 21:01:13 +0000 (23:01 +0200)
committerJ. Hendrix <gitweb@localhost>
Sat, 14 Sep 2013 21:01:13 +0000 (23:01 +0200)
millisecondInterrupt.ino

index c4c6427..250ad90 100644 (file)
@@ -34,7 +34,7 @@ void setup() {
            _BC( WGM22 )  |                              // Clear timer on compare match
            _BS( CS22 )   | _BC( CS21  )  | _BS( CS20 ); // prescaler f = clk2 / 128
   
-  OCR2A  = 125;                                         // 16MHz / 128 = 125kHz => 125kHz/125 = 1kHz
+  OCR2A  = 125 - 1;                                         // 16MHz / 128 = 125kHz => 125kHz/125 = 1kHz
   TCNT2  = 0; 
   TIMSK2 = _BC( OCIE2B ) | _BS( OCIE2A ) | _BC( TOIE2 );// Enable compare match A interrupts
   sei();                                                // Enable global interrupts