Fixed race condition. Because the (milli)secondCounter is being updated in ISR as...
authorJ. Hendrix <gitweb@localhost>
Wed, 12 Mar 2014 19:14:46 +0000 (20:14 +0100)
committerJ. Hendrix <gitweb@localhost>
Wed, 12 Mar 2014 19:14:46 +0000 (20:14 +0100)
millisecondInterrupt.ino

index 250ad90..d957eea 100644 (file)
@@ -32,7 +32,7 @@ void setup() {
            
   TCCR2B = _BC( FOC2A )  | _BC( FOC2B )  |
            _BC( WGM22 )  |                              // Clear timer on compare match
-           _BS( CS22 )   | _BC( CS21  )  | _BS( CS20 ); // prescaler f = clk2 / 128
+           _BS( CS22 )   | _BC( CS21  )  | _BS( CS20 ); // prescaler f = clk2 / 128:
   
   OCR2A  = 125 - 1;                                         // 16MHz / 128 = 125kHz => 125kHz/125 = 1kHz
   TCNT2  = 0; 
@@ -50,5 +50,7 @@ ISR( TIMER2_COMPA_vect ) {
 };
 
 void loop() {
+    noInterrupts();
     digitalWrite( led , secondCounter & 1 );
+    interrupts();
 }