Wingmax
New Member
In this post I will demonstrate how to connect and drive a servo motor.
The brain of the servo motor is the input pulse width. The pulse width determines the servo motor's drive position.
A servo motor only has 3 wires, usually red, black and white. Red and black are +ve and ground connections, and white
is the drive connection. Usually a pulse width of 1 mS will make the servo motor to drive from one far end, and 2 mS
to the other end (180 degree). A 1.5 mS will be for middle position. However, bear in mind that every servo motor is different. You have to adjust the pulse
width accordingly.

So, all we need to do to drive the servo motor is to generate a pulse train with pulse width (PWM) of 1 mS to 2mS.
There are many ways to generate Pulse Width Modulation (PWM). We can use 555 or 556 chip, or use software with microcontroller. I like to use micro because it's versatile and it can be used as a central system.
It can be used to detect input signal and outputs waveforms to drive a motor.
There are different ways to generate PWM by sofware. We can use delay routine, Timer0, Timer0 and Timer1,
interrupt, or PWM in CCP module in some PIC micro.
I will start with the easiest method, ie, by delay routine. Please refer to block diagram and program code.
View attachment serveDelay_C.txt
Program code is for Hitec C compiler, and the delay routine can be downloaded from Hitec site. This motor drives more
than 180 degree.
The micro used is 16f84A.
To produce the pulse width:
PortB.1 is set high, delay for the required time duration then set low,and delay for 15 mS.
This process is repeated for 50 times. This method of producing PWM is not very accurate, but the pulse period for
the motor is not that critical, so this method works.
The program will make the servo motor to go to the far right, back to the middle and to the far left.
Because it takes bit longer to go to the far right when first starts, so it takes 50 pulses.
Next time I will use Timer0 method........
The brain of the servo motor is the input pulse width. The pulse width determines the servo motor's drive position.
A servo motor only has 3 wires, usually red, black and white. Red and black are +ve and ground connections, and white
is the drive connection. Usually a pulse width of 1 mS will make the servo motor to drive from one far end, and 2 mS
to the other end (180 degree). A 1.5 mS will be for middle position. However, bear in mind that every servo motor is different. You have to adjust the pulse
width accordingly.

So, all we need to do to drive the servo motor is to generate a pulse train with pulse width (PWM) of 1 mS to 2mS.
There are many ways to generate Pulse Width Modulation (PWM). We can use 555 or 556 chip, or use software with microcontroller. I like to use micro because it's versatile and it can be used as a central system.
It can be used to detect input signal and outputs waveforms to drive a motor.
There are different ways to generate PWM by sofware. We can use delay routine, Timer0, Timer0 and Timer1,
interrupt, or PWM in CCP module in some PIC micro.
I will start with the easiest method, ie, by delay routine. Please refer to block diagram and program code.
View attachment serveDelay_C.txt
Program code is for Hitec C compiler, and the delay routine can be downloaded from Hitec site. This motor drives more
than 180 degree.
The micro used is 16f84A.
To produce the pulse width:
PortB.1 is set high, delay for the required time duration then set low,and delay for 15 mS.
This process is repeated for 50 times. This method of producing PWM is not very accurate, but the pulse period for
the motor is not that critical, so this method works.
The program will make the servo motor to go to the far right, back to the middle and to the far left.
Because it takes bit longer to go to the far right when first starts, so it takes 50 pulses.
Next time I will use Timer0 method........
Last edited: