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.
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
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
'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
Related projects
Real-Time CAN-Based Vehicle Monitoring System with PIC MCU
INTRODUCTION The Controller Area Network (CAN) is a robust vehicle communication bus standard that was primarily developed for automobile applications but has...
Motors & RoboticsEasy Way to Learn Robotics Using Microcontrollers: A Beginner’s Guide
The title, "Easy Way to Learn Robotics Using Microcontrollers," promises an accessible entry point for those curious about the exciting world of...
Motors & Robotics · PIC16F877AEfficient Sun-Following Robot: A Solar Tracker with Microcontroller Control
Abstract The impending global challenge of dwindling non-renewable fuel resources underscores the urgency of transitioning towards renewable energy alternatives like solar power....
Motors & RoboticsInnovative Robotics: A Comprehensive Project Exploration
A DC motor functions as an electromechanical device, translating electrical signals into mechanical movements. The rotation of the motor correlates directly with...
Motors & RoboticsAdvanced Techniques for Fault Detection, Indication, and Protection in Induction Motors
1. INTRODUCTION The impact of microcontroller usage on our daily lives is remarkable. This versatile device is now prevalent in various control...
Motors & RoboticsExploring Versatility: GSM-Based Robotic Vehicle Technology
Introduction To Robotics The term 'Robot' remains elusive, defying a precise definition due to its evolving usage. Initially, it referred to humanoid...

