WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Servo Driver (multiplexed)

This is a servo driver for controlling servos that are plugged directly into your board and uses hardware PWM via a multiplexer to send commands to each servo.
Although this requires additional hardware it brings the accuracy benefits of hardware PWM but requires less timers when you have a number of servos to control.
This driver only uses only one 16 bit hardware PWM pin to drive up to 8 different servo - but it does require an extra hardware chip the 74HC238:-
The hardware PWM pin from your controller is connected to pin 6 of the device. Pins 1,2 and 3 of the device are used to control which of the output servo pins receives each PWM pulse. By attaching pins 1, 2 and 3 to digital output pins on your micro-controller then WebbotLib automatically sets these pins to make sure that the PWM signal is sent to the correct servo.
The number of digital pins required depends on how many servos you want to control:-
1 servo - then MUX1, MUX2, MUX3 are not used
2 servos - connect MUX1 to a digital I/O pin on your micro-controller, MUX2 and MUX3 are not used
3 to 4 servos - connect MUX1 and MUX2 to digital I/O pins on your micro-controller, MUX3 is not used
5 to 8 servos - connect MUX1, MUX2 and MUX3 to digital I/O pins on your micro-controller
If any of the MUX pins aren't required then they should be made 'low' either by connecting them to ground or by using a pull-down resistor( say 100k but any value would do).
Note that if you have a lot of servos then you can break them down into separate lists, or 'banks', each with their own driver, timer and 74HC238 chip.
Just use the generic example in Actuators
Function Summary

Valid XHTML 1.0 Transitional