Skip to main content
2 of 5
Improved the formatting.
sa_leinad
  • 3.2k
  • 2
  • 24
  • 53

Cons of using timer0 with external input?

I'm working on a project of differential drive control in which I use speed encoders for the odometry.

I count the number of rising edges using counter0 and counter5 (on Arduino Mega 2560), which works fine by itself, but when I combine that code with other parts of my code, many things stop working and I can't figure out why. My current guess is that it is related to timer0.

So my question is: what can go wrong when we modify the registers for timer0? I know that delay(), millis(), micros(), and PWM on pins 4 and 13 won't be available anymore, but are there other things that I should be aware of? Are there some libraries that stop working?

If that is the case, I'm thinking of using hardware interrupts for the odometry.

Thanks in advance.