I'm using an Arduino Mega to control motors via PWM and Adafruit DRV8871 motor drivers. I also use TIMER1 for a timed interrupt. After adding the TIMER1 interrupt I discovered I had problems with motor control, which I finally tracked down to using pins 11 & 12 for PWM simultaneously with using TIMER1 for timed interrupts.

My initial thought was to change the timer used for the ISR to avoid the pin 11/12 conflict, but now I'm uncertain as to what the restrictions are for using pins associated with timers. I now realize that pins associated with a timer interrupt can't be used for PWM using analogWrite(int val), but can they be used as general purpose digital outputs?

For instance, if I change from TIMER1 to TIMER0 for my timer interrupt, that appears to change the pin dependency from 11/12 to 4/13. I don't use pin 13, but I do use pin 4 as a digital output. Will using pin 4 as a digital output still work properly?



  • Are you sure you are using an Arduino Mega? pins 11 and 12 aren't PWM pins on the mega. Only on the UNO. The Mega has like 6 timers, so you'd have plenty to choose from, to avoid conflicts.
    – Gerben
    Sep 13, 2020 at 13:56

1 Answer 1


You can use them for any purpose other than PWM. You can even use them for PWM as long as the settings for the timer allow you to produce the waveform you want.

The reason PWM broke was that you had changed the settings for the timer. The timer is what controls the PWM. When you changed those settings you either turned the PWM function off or set some setting where it wouldn't work. Then the pins associated with that timer didn't get PWM anymore. You can do anything else you want that doesn't involve the timer including use the pin for input or output or any other special function it has not related to the timer.

If you change the timer interrupt to TIMER0, then you run the risk of delay, millis, and micros stop working right. They depend on the TIMER0 overflow interrupt running at a set interval to count time. It depends on how you set the timer up.

I would suggest you do some reading on how these timers work. The Datasheet for the ATMega328P chip is a great place to start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.