Timer Interrupts And PWM Pins - Arduino Forum

Timer Interrupts and PWM Pins Projects Programming June 6, 2015, 9:43am 1

I just started reading about Timers and Interrupts.

From what I understand the 328 has 3 timers (TIMER0, TIMER1, TIMER2), which is used in Arduino (UNO, etc.) to control the PWM pins:

  • Pins 5 and 6: controlled by Timer 0
  • Pins 9 and 10: controlled by timer 1
  • Pins 11 and 3: controlled by timer 2

I always thought those PWM pins are different from the other I/O pins - but it seems they are not, no?

Furthermore, if I write my own routine using TIMER0, PWM Pins5 and 6 - and the delay() function! - will not work any more, correct?

Arduino uno counter 0 and 2 with external pulses June 6, 2015, 10:16am 2

Correct.

Those pins are normal digital pins. The timer input and outputs connected to those pins are something extra. The Timers will only use the pins if that is programmed in the registers. Even the A0...A5 are normal digital pins, The analog section is an extra. The interrupt pins, the I2C bus, the SPI bus are all something extra for normal digital pins..

The pinmapping drawing is very useful. Google for : arduino pinmapping

Arduino uses TIMER0 for the timing. You should not change that. You can do whatever you want with TIMER1 and TIMER2. Some functions or libraries use those timers (pwm, tone(), and many more), so you have to be careful how they are used.

June 6, 2015, 11:21am 3

Thanks, I understand.

Do you know why they used all 3 timers to provide PWM functionality? I mean they could have used only one timer.

And why exactly those 6 pins? And not 4 pins. Or 8 pins.

June 6, 2015, 11:49am 5

OK, so lets make an example:

  • I want to use delay() in my code -> I can't use TIMER0 for my project any more.
  • I also want to use TMRpcm library (for PCM/WAV sound) -> I can't use TIMER1 for my project any more and PWM Pins 9 and 10 are also gone.

All that's left is TIMER2. But if I use that, I lose PWM Pins 3 and 11.

So finally I end up with only two available PWM Pins (Pins 5 and 6, controlled by TIMER0)

Is that correct?

June 6, 2015, 12:05pm 6

Yes, the Arduino timing and pwm can both use TIMER0, that is why the PWM for TIMER0 has a different frequency.

analogWrite() - Arduino Reference

The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

The pins are not gone for normal use (output or input pin), but they are gone for PWM.

Delta_G mentioned the software PWM. Such things are often used for Servo motors, frequency outputs, and so on. It uses a single timer with interrupt. Inside that interrupt the pins are set high and low. That way every pin can have a 'software' pwm.

Topic Replies Views Activity
What doc shows which hardware Timer(0,1,2) controls which Nano PWM pin? Classic Nano 3 92 September 12, 2025
Arduino uno counter 0 and 2 with external pulses General Guidance 6 690 June 20, 2024
Nano: Setting timer 0 for PWM on pin 5 slows down the system Programming 10 206 January 17, 2025
Timers (interrupts) Programming 5 889 May 5, 2021
PWM free pins on Arduino UNO/ATmega328 LEDs and Multiplexing 4 675 May 6, 2021
Unfortunately, your browser is unsupported. Please switch to a supported browser to view rich content, log in and reply.

Tag » Arduino Timer1 Pwm Pins