Documente Academic
Documente Profesional
Documente Cultură
Introduction to Servos
The servo motor is a specialized motor that may be commanded to turn to a specific position. The servo motor consists of a DC motor, a gear reduction unit, a shaft position sensor, and an electronic circuit that controls the motors operation. The next figure shows a typical servo motor used or RC cars or small mobile robots.
Pulses that are far too slow may cause your robot to seem awkward and jerky. Rotation position of the servo depends on the pulse with (time the pulse is high or near +5V). This is called Pulse Coded Modulation (PCM) or Servo Pulse Width Modulation (Servo PWM). The following figure shows how the closed-loop servos work.
Depending on the manufacturer, the range of the pulse width to drive the servo varies. In general, typical values are in the ranges: 0.9 ms to 1.5 ms to move to the left, 1.5 ms in the center, 1.5 ms to 2.1 ms to move to the right.
If a servo is driving the wheel of a mobile robot, you can measure the rotational speed or get the manufacturer rated rotational speed. Using this rotational speed and the diameter of the wheel, you can calculate the distance the robot travels Distance S = D
where
S is the distance traveled in one minute (cm) D is diameter of the wheel (cm) is the angular velocity of the servo measured in Revolutions Per Minute (RPM)
To generate the waveforms required to control the servo motor using the 68HC11, the Output Compare Register and the Free Running Counter (TCNT) available in the 68HC11 can be used. The following programs show how to control a servo motor using the 68HC11. Program 1. Driving the servo motor in clockwise direction.
; Using the OC2 (PA6) to generate a train of pulses to drive a servomotor clockwise (CW) ; The period of the signal is around 17 msec ; The length of the positive-going control pulse is around 2msec (2000us) TCTL1 EQU $1020 TFLG1 EQU $1023 TOC2 EQU $1018 ORG $2000 LDS $3000 LDX #TFLG1 AGAIN LDAA #%10000000 ; Set OM2=1 and 0L2=0 in TCTL1 to clear OC2(PA6) on successful compare STAA TCTL1 LDAA #%01000000 ; Reset OC2F in TFLG1 STAA 0,X LOOP1 BRCLR 0,X $40 LOOP1 ; Wait until OC2F sets and toggle the output ; BRCLR performs a logical AND of the memory location specified ; and the mask supplied with the instruction, and branches if ; the result is zero ; Set the lenght of the zero level control pulse to 15 msec LDD TOC2 ; Get present TOC2 value ADDD #30000 ; Add 300000 and store it back (30000 x 0.5 us = 15 msec) STD TOC2 LDAA #%11000000 ; Set OM2=1 and 0L2=1 in TCTL1 to set OC2(PA6) on successful compare STAA TCTL1 LDAA #%01000000 ; Reset OC2F in TFLG1 STAA 0,X LOOP2 BRCLR 0,X $40 LOOP2 ; Wait until OC2F sets and toggle the output ; Set the lenght of the positive-going control pulse to 2 msec LDD TOC2 ; Get present TOC2 value ADDD #4000 ; Add 4000 and store it back (4000 X 0.5 us = 2 ms) STD TOC2 ; The total duration of the signal is: Duration in zero level + Positive-going ("1")=15ms+2ms=17ms BRA AGAIN
; Wait until OC2F sets and toggle the output ; BRCLR performs a logical AND of the memory location specified ; and the mask supplied with the instruction, and branches if ; the result is zero ; Set the lenght of the zero level control pulse to 15 msec LDD TOC2 ; Get present TOC2 value ADDD #30000 ; Add 300000 and store it back (30000 x 0.5 us = 15 msec) STD TOC2 LDAA #%11000000 ; Set OM2=1 and 0L2=1 in TCTL1 to set OC2(PA6) on successful compare STAA TCTL1 LDAA #%01000000 ; Reset OC2F in TFLG1 STAA 0,X LOOP2 BRCLR 0,X $40 LOOP2 ; Wait until OC2F sets and toggle the output ; Set the lenght of the positive-going control pulse to 1 msec LDD TOC2 ; Get present TOC2 value ADDD #2000 ; Add 2000 and store it back (2000 X 0.5 us = 1 ms) STD TOC2 ; The total duration of the signal is: Duration in zero level + Positive-going ("1")=15ms+1ms=16ms BRA AGAIN
Using the OC2 (PA6) ; The period of the ; The length of the TCTL1 EQU TFLG1 EQU TOC2 EQU ORG LDS LDX AGAIN LDAA compare STAA LDAA STAA LOOP1 BRCLR
to generate a train of pulses to drive a servomotor counterclockwise (CCW) signal is around 16 msec positive-going control pulse is around 1 msec (1000us) $1020 $1023 $1018 $2000 $3000 #TFLG1 #%10000000 ; Set OM2=1 and 0L2=0 in TCTL1 to clear OC2(PA6) on successful TCTL1 #%01000000 0,X 0,X $40 LOOP1 ; Reset OC2F in TFLG1