Go Down

Topic: ISR(TIMER1_COMPA_vect) (Read 3797 times) previous topic - next topic

Manuel Silva

I am learning C and have the following problem:

I want to use timer interrupt routine. The routine works, the LED switch ON and OFF. In side of the routine I want decrement a counter. The routine is below:

(I declare the count variable as "volatile uint16_t count=0;").

Code: [Select]

ISR(TIMER1_COMPA_vect)          // timer compare interrupt service routine
{
 
  digitalWrite(ledPin, digitalRead(ledPin) ^ 1);   // toggle LED pin
  count--;
   if (count=0)
  {
    TCCR1B =0;
  } 
}   



I want decrement a counter (count) and stop the timer when it reaches zero, but, the counter doesn't decrement.

Can you please help on solving this problem?

Thanks,
Manuel

Nick Gammon

Code: [Select]
if (count=0)

To compare you need to use ==, like this:


Code: [Select]
if (count == 0)
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

bubulindo


Code: [Select]

   if (count=0)



Ahhh, thanks for this. :)

I have some fun memories from a friend of mine that never managed to get this right. And he knew how to program, and yet never came to memorize the difference between "=" and "==". LOLOL
This... is a hobby.

Manuel Silva

Thanks for your help. It was really a crazy question. It was lat in the night, so, I may was sleeping.

regards,
Manuel

Go Up