Vous êtes sur la page 1sur 2

Driving the Servo Motor

Driving the servo motor using a function generator

A three-wire DC has three input wires: the red wire is usually connected to the power supply, the black wire is
usually connected to the ground and the white/yellow wire is usually connected to the controlling signal. One of the
simplest ways to test/drive a servo motor is to generate pulse using a function generator. The pulse can be generated
using the square wave function of the function generator. For the servo motor that we are using, Tower Hobbies STD
BB TS-69., the power supply is about 4.8 volts and so we can generate a square wave using the TTL output of the
function generator. You should adjust the amplitude of the square wave such that it matches the power supply of the
servo motor.

Once you have adjusted the amplitude of the square wave pulse, you can adjust the width of the pulse train by
adjusting the frequency of the signal. For the servo motor that we are using, the neutral point (the pulse width at
which the servo stays at 90 degrees) is about 1520 microseconds (us) or 1.52ms. Any pulse width narrower than 1.52
ms will cause the servo to move to a position less than 90 degrees and vice versa. Note that servo only turns between
0 and 180 degrees if it is not modified. This corresponds to about 0.8ms to 2.5ms of pulse width. Make ensure the
pulse width that you use is in within this range.

For a servo motor modified to rotate continuously, the servo will not turn at the neutral pulse width but it will turn
clockwise continuously if the pulse width is less than the neutral pulse width and anticlockwise if the pulse width is
larger than the neutral pulse width. (The pulse width has to be within the range mentioned above).

Driving the servo motor using the Handy Board

For most applications, it is impossible to drive the servo motor using the function generator. One of the most
convenient ways to drive the servo motors is to use the Handy Board. The Interactive C has a library routine that
allows control of a single servo motor, using digital input 9, which is actually the 68HC11's Port A bit 7 (PA7), a
bidirectional control pin. This library routine can be loaded onto the Handy Board by loading the binary file,
servo.icb, first and then the file servo.c (this means the file where you write your own C program cannot be named as
servo.c!).

Here is the library functions used to control the servo motor:

Void servo_on ( ): Enables PA7 servo output waveform.

void servo_off( ) : Disables PA7 servo output waveform.

Int servo (int period): Sets length of servo control pulse. Value is the time in half-microseconds of the positive
portion of a rectangular wave that is generated on the PA7 pin for use in controlling a servo motor. Minimum
allowable value is 1400(i.e. 0.7ms); maximum is 4860 (2.43ms). The return value of the the function is the actual
period set by the driver software. When the servo motor is not modified, the value of period is about 2950 at the
neutral point. When the servo motor is modified, the value of period is about 2570 at the neutral point.

int servo_rad (float angle): Sets servo angle in radians.

int servo_deg (float angle): Sets servo angle in degrees.

Sample programs

The following code fragments illustrate how to use the above library functions to drive the servo motor:

float period=70.0;
int k;
servo_on();
While (1) {
k = servo_deg (period);
Printf ("angle is %d\n", k);
}

The above code fragment sets the servo motor into 70 degrees and display the current position on the LCD display
(in terms of microseconds of the pulse).If the servo motor is modified to rotate continuously, the above code
fragment cause the servo to rotate in clockwise direction continuously.

int period=1400.0;
int k; servo_on ();
while (1) {
k = servo(period);
printf("period is %d\n", k);
period = period + 100;
}

The above code fragment will cause an unmodified servo motor to turn in small increments until the mechanical stop
is reached. The motor should start again from the 0 degree position sometime after the maximum allowable value of
the 'period' is exceeded. The code will cause a modified motor to turn clockwise and anticlockwise alternatively. The
value of the period is less than the neutral value at first, so the motor will turn in the clockwise direction. After the
neutral value is exceeded, the motor will turn anticlockwise. After the maximum allowable value of the period is
exceeded, the value of the period will start from 1400 again and thus it will turn clockwise once again. This can be
observed by looking at the LCD display.

Vous aimerez peut-être aussi