Multiple Servomotors

Using a modified version of the last program, we can control as many servomotors as we have I/O lines on port B. In the next listing, we will control two servos in the same manner as we controlled a single servo in the previous program. The circuit is shown in figure 4 (below).

The program uses two pulsewidth variables, pw1 and pw2; and two sets of routines, left1 and left2, right1 and right2; one for each motor. As you can see in the schematic, the first servo is wired as per the previous circuit. The second servo is now using B3 as it’s pulse out, and B4 and B5 for the SPDT switch.Multiple Servomotors

Listing 3

β€˜Manual control of two servomotors using 2 SPDT switches

β€˜Use B1 to hold pulsewidth variable for servo 1
β€˜Use B2 to hold pulsewidth variable for servo 2

β€˜Initialize Variables

B1 = 150
B2 = 150

β€˜start servo 1 at center position
β€˜start servo 2 at center position

 

start:
IF pin1 = 0 Then left1
IF pin2 = 0 Then right1
IF pin4 = 0 Then left2
IF pin5 = 0 Then right2
PulsOut 0, B1
PulsOut 3, B2
Pause 18
GoTo start

β€˜check for switch closures
β€˜is sw1 left active?
β€˜is sw1 right active?
β€˜is sw2 left active?
β€˜is sw2 right active?
β€˜send current servo 1 position out
β€˜send current servo 2 position out

 

β€˜Routines for Servomotor 1
left1:
B1 = B1 + 1
PulsOut 0, B1
PulsOut 3, B2
Pause 18
IF B1 > 225 Then max1
GoTo start
right1:
B1 = B1 – 1
PulsOut 0, B1
PulsOut 3, B2
Pause 18
IF B1 < 75 Then min1
GoTo start
max1:
B1 = 225
GoTo start
min1:
B1 = 75
GoTo start

β€˜increase the pulse width
β€˜send current B1
β€˜send current B2
β€˜set frequency update about 50 hz
β€˜maximum 2.25 millisecond

β€˜decrease the pulse width
β€˜send current B1
β€˜send current B2
β€˜set frequency update about 50 hz
β€˜minimum .75 millisecond

β€˜cap max B1 at 2.25 milliseconds

β€˜cap min B1 at .75 millisecond

 

β€˜Routines for Servomotor 2
left2:
B2 = B2 + 1
PulsOut 0, B1
PulsOut 3, B2
Pause 18
IF B2 > 225 Then max2
GoTo start
right2:
B2 = B2 – 1
PulsOut 0, B1
PulsOut 3, B2
Pause 18
IF B2 < 75 Then min2
GoTo start
max2:
B2 = 225
GoTo start
min2:
B2 = 75
GoTo start

Multiple Servomotors schematich

β€˜increase the pulse width
β€˜send current B1
β€˜send current B2
β€˜set frequency update about 50 hz
β€˜maximum 2.25 millisecond

β€˜decrease the pulse width
β€˜send current B1
β€˜send current B2
β€˜set frequency update about 50 hz
β€˜minimum .75 millisecond

β€˜cap max B2 at 2.25 milliseconds

β€˜cap min B2 at .75 millisecond

 

For more detail: Multiple Servomotors


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.