PWM for servo and motor speed
January 22, 2009
So I've looked around and see that Arduino motor shield board uses timer1 (pins 9 and 10) for hardware PWM control of motor speed. There are Arduino libraries that use timer1 for hardware PWM control of servos.
Timer1 gives you 16 bit resolution. The other timers (timer0 and timer2) have only 8 bit resolution.
I can see needing 16 bit resolution for the servo. The servo control pulse rate is 50 Hz or 20 ms period. To move the servo through its range you need to vary the pulse width from 1.0ms to 2.0ms. Dividing the 20ms period by 65536 increments (2^16) you get 3276 increments in 1ms. Doing the same thing with 8 bit resolution gets you 256 / 20 ms or 12.8 increments in that 1ms time. Since more is better (3276 vs 12.8) you'd control the servo with 16 bit resolution timer1 rather than 8 bit resolution timer0 or timer2.
You've also got the choice of 16-bit or 8-bit resolution for your motor speed control. That's 65536 speed settings versus 256 speed settings. I think the robot would be happy with just 256 speed settings.
I'm building a simple robot with a Sharp IR sensor mounted on a servo and a pair of Solarbotics GM9 motors. The Arduino Motor Shield uses timer1 for the motor control, leaving me with timer0 or timer0 for 8 bit servo positioning. I think I could live with the 12.8 increments in servo positioning since the robot just needs to look left, right, and forward for obstacles. Alternatively I could go with software PWM on the servo to get more resolution in positioning.
Maybe it's me but I think the Arduini motor shield designer is wasting 16-bit PWM on motor control. How would other Arduino users set up motor and servo control?