Home Resources

 

HowTo: Interface to a Servo Motor

 

Servo Motor Connection

 

 You will need:

  • Servo Motor (In this tutorial, I’m using a Hitec HS322HD Servo Motor)
  • FI40/28 Board
  • 6V DC Power Supply
  • FI Comm.Key Set
  • PC running FIDE

Introduction
There are a few important points to take note before we start.
  1. Power Supply: Please use a 6V DC Power Supply. 6V is the minimum voltage required to power up the Board and is also the maximum voltage allowed to power the servo motor.
  2. All Hitec Servo Motors have an operating range of 4.8V to 6V, with the exception of HS-50, which is powered at 4.8V.
  3. The Servo Motor connection is to a PWM port, in which the power supplied is the same as what you pump in to power up the board (Vin). So if you supply a 6V, the voltage supplied to the servo motor is also 6V, regardless of whether the FI Board is a 3.3V or 5V system.


Now, on to the tutorial!

Make sure that you already have the Servo Motors connected as above. You can connect up to a maximum of 4 servo motors at pins 13-16 (for the FI40 Board).  The FI28 Board can take up to a maximum of 2 Servo Motors at pins 7 and 8.


The FIDE has a built in system library for controlling servo motors. This can be illustrated with the help of syntax helper available within the IDE.

PWM Servo LibraryPWM Servo Library Detail

A onetime initializing of the PWM ports is required before setting the positions of the servo motors.

To do this, we type the following 2 lines of code.

Within the Main Module under Public Sub Main();

 

 FI code boxFI CODE:

'Module1
'Servo Connected to Pin 13
Public Const Servo_Pin As Integer = 13

Public Sub Main()

'Init Servo Motors
OS.PWMServo.Init(Servo_Pin)
'Turn on PWM
OS.PWMServo.State(1)

End Sub
NOTE: If you’re using more than 1 servo motor, you will have to initialize each Servo to set it to PWM mode specifically for servo motor usage. You will only need to set the state once. (1 to turn the PWM ‘ON’, 0 to turn the PWM ‘OFF’) Unless your servo motor has been modified to do continuous rotation, a standard servo motor is capable of sweep movements of about 180 degrees.

Neutral State or “Middle Position” for all Hitec Servo Motors is at a pulse width of 1500usec.

The standard sweep range for 0 to 180 degrees is about 500usec to 2500usec.

The following program first sets the servo to its neutral position. If any jamming occurs at any position, check your servo horn position and affix it properly.

 FI code boxFI CODE:
'Neutral/Middle Position
OS.PWMServo.Position(Servo_Pin, 1500)

 To make the servo motor sweep the entire 0 to 180 degrees and back, continuously, we do the following in a do loop structure.

 

  FI code boxFI CODE:

'Module1
'Servo Connected to Pin 13
Public Const Servo_Pin As Integer = 13

Public Sub Main()

'Init Servo Motors
OS.PWMServo.Init(Servo_Pin)

'Turn on PWM
OS.PWMServo.State(1)

'Neutral/Middle Position
OS.PWMServo.Position(Servo_Pin, 1500)

'Continuous Sweep Movement
Do
OS.PWMServo.Position(Servo_Pin, 2500)
Delay(1000)
OS.PWMServo.Position(Servo_Pin, 1500)
Delay(1000)
OS.PWMServo.Position(Servo_Pin, 500)
Delay(1000)
OS.PWMServo.Position(Servo_Pin, 1500)
Delay(1000)
Loop


End Sub

 

Note: A minimum delay of 10ms (including the pulse instruction) is required between consecutive movements of the same servo to prevent jamming.

 


download source code