Go Down

Topic: Timer Interrupt Problem (Read 324 times) previous topic - next topic

nikolausi

Hey

The LED should toggel every second, but the LED needs 4s to switch.
Code: [Select]
unsigned int timerCounter = 0;
void setup() {
  //--------------------------------------- 
  //intialize Timer
  TIMSK0 = _BV(OCIE0A);  // Enable Interrupt TimerCounter0
  TCCR0A = _BV(WGM01);  // Mode = CTC
  TCCR0B = _BV(CS01)|_BV(CS00);   // 64 Prescaler
  OCR0A = 125;          // 0,0001s
  sei();
  //----------------------------------------
  pinMode(13, OUTPUT);     
}

void loop() {
 
}
ISR(SIG_OUTPUT_COMPARE0A)
{
 
  timerCounter++;
  if(timerCounter==10000)
  {
   
    digitalWrite(13, HIGH);   // set the LED on
  }
  if(timerCounter>=20000)
  {
    digitalWrite(13, LOW);    // set the LED off
    timerCounter=0;
  }
 
}


My Calculation is: 1/16000000*64*125=0,00001s
Where is the failure?

Thanks, Nikolausi

robtillaart


My calculation is 1/ 16.000.000 * 64 * 125 = 0.0005 so at least something in your math is incorrect.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up