Timer/PWM Issues

Hello everyone! I have recently started using buttons in one of my projects, and I found a nice way to poll the buttons to make sure I always catch the keypress (I got the code from adafruit) Anyway, the code involves using timer2 to poll the buttons every 15 millis. To do that it uses the following bit of code to trigger interrupts:

TCCR2A = 0;
TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;
//Timer2 Overflow Interrupt Enable
TIMSK2 |= 1<<TOIE2;

It works extremely well, but now none of my PWM outputs are working. I tried pins on and off of timer2 to no avail. Is it not possible to use this type of interrupt and pwm in the same program?

Polling the button from loop is all you need, assuming you don’t use delay().


Unfortunately my code loop takes anywhere from 300 - 1200 ms to complete, so it seems I need some kind of interrupt driven button detection to reliably grab button presses. Anyone know why PWM stops working when I set the overflow interrupt?

Timer 2 is only used for PWM pins 3 and 11, at least it is on the UNO

I had a problem today when I added an interrupt driven library to a program using PWM on pin 3 and PWM on that pin stopped. Changing to using PWM on pin 9 solved my problem.

I dont know if my uno is just messed up or something, but I was using pin 10 when that code killed it. I also tried 9 6 and 3, and it is all the same for me. Can anyone verify? Just use the fade example, paste in those lines, and try it on the different pins (change the default to another timer like pin 10). I just cant figure out whats going on.