Timer Interrupts and PWM Pins

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?

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.

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.

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?

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

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.