# How can the Arduino Uno support up to 12 servos if it only has 6 digital PWM pins?

According to this:

The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.

However, according to this:

Digital I/O Pins 14 (of which 6 provide PWM output)

So how can the Uno control more than 6 servos if it only has 6 digital I/O pins that can provide PWM output?

## 1 Answer

Although I haven't looked at the source myself, in these types of situations they usually use interrupt timer 1, which in PWM mode would have been associated with pins 9 and 10. This would explain why you can't use pulse width modulation on those pins. In fact, you can use any of the three timers for PWM on any digital pin, although it's not as good as the built in PWM options.

(source: bansky.net)

(Source)

The above image accurately describes how the signals are sent to the servo motor. Such a waveform is similar to a standard PWM. The servo library can translate a degree to a waveform that the servo's IC will be able to use to adjust the motor's position with it's motor and potentiometer.

• So it essentially simulates PWM? What is the point of the digital pins with PWM channels then? – user1265 Apr 30 '14 at 22:33
• @user1265 More or less... it's using the timers that drive PWM. As far as the point of PWM, IIRC the ATmega328 has circuitry to make PWM more efficient. – Anonymous Penguin Apr 30 '14 at 22:51
• @user1265, hardware PWM is "free", i.e. it does not affect the performance of the rest of your program at all (it just ties up a timer, or at least part thereof). Servicing interrupt routines for emulated PWM is comparatively costly. However, in this case, the PWM frequency is only about 50Hz, so this is not overly tragic (Standard Arduino PWM frequency is 31/62kHz, doing PWM for e.g. lighting applications at 50Hz would probably be rather flickery). – microtherion May 1 '14 at 0:38
• What is the point of the digital pins with PWM channels then? - you can get much higher frequencies (up to 8 MHz) and very precise duty cycles. This isn't possible when you are relying upon an interrupt to do this for you. – Nick Gammon Jan 19 '16 at 0:03