Go Down

Topic: Interrupts and timers (Read 242 times) previous topic - next topic

zopffa

Now I get it!

When I use

Code: [Select]
TIFR1 |= (1 << TOV1)

and let's say another Bit in TIFR1 is 1, so for example TIFR1 is 0b00000011 (TOV1 is Bit0). Then I create (1 << TOV1) which is the same as 0b00000001.

Now I use the or operator on both Bytes:

    0b00000011     TIFR1
   |0b00000001    (1 << TOV1)
  =0b00000011

so in fact I write Bit0 and Bit1 value = 1 to the register.

Is that what you mean?

Whandall

so in fact I write Bit0 and Bit1 value = 1 to the register.

Is that what you mean?
Yes.

It may not hurt in this case, because all the bits belong to the same timer,
but it is inefficient (one read and the or are superfluous) and incorrect.

There are some other similar behaving bits, for example the PINx registers,
where writing a 1 to a bit toggles the output state, where it is more critical to get it right.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

septillion

Using a timer for 20ms timing is borderline. I really hope your loop is faster than 20ms ;)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Go Up