■ FIGURE 5. Motor
drive four servos. The Experimenter can drive up to five
servos but the demo uses only four (since it fit nicely with
the use of the four pushbuttons for servo selection). To
select a servo, use a pushbutton (SW1 = servo1; SW2 =
servo2; SW3 = servo3; SW4 = servo4). The selected servo
and its current setting are displayed on the Experimenter
To change the selected servo positions, just turn the
potentiometer. Turning pot CWW adjusts the servo
position to the left. Turning pot CW adjusts the servo
position to the right. The servo is slaved to the
potentiometer position. The pot value (pin 10 of the
Experimenter I/O expansion bus) is digitized by the PIC24F
ADC and this value is used to set the OCXR register of the
OCX to drive the selected servo. The code sets up the
timer 2 periods for 100 Hz.
■ FIGURE 6.
• servo_init () — Initializes OC1, OC2, OC3, OC4 for
PWM operation using timer 2 as the common
timing source. All the OCx are enabled for 1.5 msec
or center position of the servos.
• Servo1_on (), Servo1_off(), Servo2_on (),
Servo2_off(), Servo3_on (), Servo3_off(),
Servo4_on (), Servo4_off() — individual functions
per servo to turn them on or off.
• Set_Servo1 (setting), Set_Servo2 (setting),
Set_Servo3 (setting), Set_Servo4 (setting) — Sets
the PWM duty cycle of the designated servo.
Designated servo is selected via pushbutton by user.
Current selected servo is stored as number 1 to 4 in
This experiment can work with a reduced number of
servos, as well. Again, we used the LCD, ADC, and
pushbutton C libraries.
Please review the PWM profile (Figure 6) to
understand PWM requirements for servo control.
No PWM discussion is complete without considering
motor control. In this experiment, we will be