You are on page 1of 28

Chapter 3

Camera Mount
Chapter 3
22

Section 1: Stepper Motors

Two stepper motors working consecutively implement the pan and tilt function of the
camera mount. Stepper motors fall into the class of brush less DC motors. Stepper
motors are most commonly found in printers, small-scale equipment, and other
applications requiring accurate positioning and also speed control. For this project, the
designers have chosen to use stepper motors instead of standard DC motors for many
reasons. However, both types have their advantages and disadvantages over one another.
For applications not requiring speed or positional control, a DC brush motor has clear
advantages. The advantages of a stepper motor are more apparent when some form of
speed or positional control is necessary. With the assumption that the stepper motor does
not slip between steps, one can accurately control both speed and positioning of stepper
motors without a feedback mechanism. This is a significant feature because the feedback
mechanism may cost as much or more than the motor to be controlled and could add
much more complexity to the controller circuitry.

When positioning or speed control is necessary and the required torque and speed are
within the motor limits, a stepper motor may present a much more economical solution
then a closed loop DC motor. This gives insight as to why the common use of stepper
motors in positioning applications in virtually every printer and scanner currently made.
One of the disadvantages of stepper motors is torque. Stepper motors are limited in the
amount of torque they can produce in comparison with DC brush motors. Stepper motors
are typically rated with a holding torque, which is the amount of torque they can hold
without slipping with the coils energized at the rated voltage. A misconception of
holding torque is that it is the amount of torque they can actually turn, however this is not
the case. Stepper turning torque is a fraction of the rated holding torque and unfortunately
it is not always specified in the motor data sheets. This has been one of the problems
encountered in this project.

As with a DC motor, the procedure for increasing torque is to gear down the motors
output. It might seem that this would also be an effective method for steppers but this is
not always the case. Unlike brush motors, whose torque increases with speed, steppers
have more torque at lower speeds. Steppers also have a much lower maximum speed
then a brush motor.

Stepper motor coils are typically rated for a particular voltage. The coils act as inductors
when voltage is supplied to them. As such they dont instantly draw their full current and
in fact may never reach full current at high stepping frequencies. The electromagnetic
field produced by the coils is directly related to the amount of current they draw. The
larger the electromagnetic field, the more torque the motors have the potential of
producing. The solution to increasing the torque is to ensure that the coils reach full
current draw during each step. This is accomplished by increasing the voltage that the
coil is excited with but also within the manufactures current ratings. To accomplish this
some kind of current limiting scheme is necessary. A series resistor between the higher
then rated power supply and the coil is an inexpensive solution. This type of
Chapter 3
23
configuration is referred to as a L/2R scheme. Where as omitting the series resistor is
referred to as a L/R scheme.

Stepper motors come in two varieties, permanent magnet and variable reluctance.
Variable reluctance motors usually have three windings while permanent magnet motors
usually have two independent windings, with or without center taps. Permanent magnet
stepper motors are again separated into two subclasses, unipolar and bipolar. The most
common stepper is the four- coil unipolar variety as shown in Figure 3.1.










This type of stepper is called unipolar because it requires only that their coils be driven
on and off. The direction of current flow through the coils does not change. Unipolar
motors have four coils and are likely to have five or six wires attached. One wire is
attached to each coil and one or two wires center taped referred to as the common.
Figure 3.2 shows wiring connections of both five and six wire stepper motors.






Unipolar Stepper Motor
Figure 3.1
Chapter 3
24






The four coils are actually arranged as two coils with center taps as shown in Figure 3.3.
In use, the center taps of the windings are typically wired to the positive supply and the
two ends are alternately grounded dependent on the step sequence.




Figure 3.3




Bipolar motors require that the polarity of the power to the coils be reversed. This
switching of polarity causes the need for more complicated circuitry to drive the motor.
Bipolars have only half of the copper resistance because of the double cross section of the
wire. The effect of this smaller resistance is that bipolars have less torque because they
have less power loss. An important aspect to consider is the maximum temperature rise
of the motor, due to the power loss in the windings. The winding current may be
increased by the factor of 2 and this produces a direct proportional affect on the torque.
Figure 3.2
Chapter 3
25
At their power loss limit bipolars can deliver about 40 percent more torque than
unipolars.

The designers of this project have chosen to use unipolar stepper motors for the camera
mount for several reasons. First they are the most widely available and can be found at
most surplus electronic stores. Another reason is that they are easily compatible with the
translator being used in the controller, and they require less complicated driver circuitry
than bipolar motors.


Section 2: Driver

A Stepper motor, like any other DC motor, requires a fair amount of current to operate.
This amount of current is much more than a translator, such as a microcontroller, can
deliver. For this reason, a driver circuit is needed to produce the current needed and be
interfaced between the translator and motor. The driver circuitry also provides safety to
the translator circuitry from the high back voltage produced by the electromagnetic force.
As noted by Allegro Microsystems, It is also a good design precaution, to use a separate
power supply for the motor from the translator. This provides another layer of protection
as to not damage the translator circuitry.

The designers of this project have decided to use the ULN2003 driver manufactured by
Allegro Micro Systems. The ULN2003 is a 7-bit, 50V, 500mA TTL-input, NPN
Darlington driver. This driver is more than adequate to control a four coil unipolar
motor.



Figure 3.4



As a precaution it is recommended, by Allegro micro Systems, to include a 12V Zener
diode between the power supply and Vdd, pin 9, on the chip to absorb the back emf.
Connection of a zener diode is shown in Figure 3.4.

Chapter 3
26
The function of the driver IC is to supply and adequate amount of current by providing
pulses of power to each individual motor winding to be energized depending on the step
sequence. Rather than sourcing the current to the windings, instead the driver sinks the
current providing a path to ground and completing the circuit for each individual winding
that is being energized.










Section 3: Drive Sequences

Unlike ordinary DC motors, steppers require that their power source be continuously
pulsed in specific patterns called step sequences. These step sequences determine the
speed and direction of a steppers motion. For each pulse, or step input, the stepper motor
rotates a fixed increment called its step angle. This fixed step angle gives steppers their
precision. A main feature of using a stepper motor is that the controlling program can
know the exact position of the motor at any given time. There are basically three
different stepping sequences used to drive four coil unipolar stepper motors, full step,
half step and wave drive.




Figure 3.5


Figure 3.5 shows the full step stepping sequence. This sequence requires that only one
winding be pulsed at a time and uses less power than the other two sequences








Chapter 3
27






Figure 3.6


Figure 3.6 shows the wave drive stepping sequence. This sequence involves powering
two windings at the same time. This sequence generally produces more torque than the
other sequence but uses twice as much power.




Figure 3.7



Figure 3.7 shows the half step stepping sequence. This sequence is a combination of the
other two and allows half stepping. The direction of the motor is determined by the
Chapter 3
28
sequence. Reversing the order of any of the three possible step sequences can change the
direction of the motor.

Advantages of half step

An essential advantage of stepper motors being operated in the half step sequence is its
position resolution increased by a factor of 2. It cuts the step angle in half and takes
double the amount of steps per revolution. The disadvantages are that the system takes
twice as many pulses to turn the rotor one complete revolution. The clock frequency is
twice as high and also in the half step sequence the motor has about half the torque of a
full step sequence.


Section 4: Translator

The function of the translator is to control the speed and direction of the motor. This is
done by sending the correct sequence of signals to the driver circuitry in order to pulse
the motor with the specified step sequence. For this project the designers will be using an
AVR 8-bit, flash programmable microcontroller. The designers decided to use a micro
programmable device instead of a hard-wired approach for several reasons. Most
importantly, the logic can be implemented for the stepping sequence through software
instead of logic gates. There are a lot of issues involved in the controlled movement of
the camera to a specified position. The motors will both need to rotate clockwise and
counterclockwise to bring the camera to the desired point of view. Using the
microcontroller approach, this can all be done through software.

Microcontroller vs. dedicated digital circuit

The translator that provides the logic to sequence the stepper motors may very well have
been designed using a dedicated digital circuit or PLD. However we have chosen to use
a microcontroller, specifically the AVR AT90S8515 microcontroller manufactured by
ATMEL corp. We chose a microcontroller because of the flexibility in writing the
software for the logic, which could easily be modified or revised. On the other hand a
dedicated digital circuit would have to be redesigned and re wired.


AVR Microcontroller

The AVR processor utilizes high performance, low-power RISK architecture. The AVR
incorporates 118 powerful instructions, most with a single clock execution cycle. The
processors register file contains 32 x 8 general-purpose registers. Other features this
project will make use of are external and internal interrupt sources, low-power idle and
power down modes, and 32 programmable I/O lines. The AVR memory includes 4K/8K
Bytes of in system programmable Flash and 256/512 bytes of in-system programmable
EEPROM.

Chapter 3
29



AT908515
Figure 3.8


AT908515 Pin descriptions

Vcc
Supply voltage

GND
Ground

Port A (PA7-PA0)
Port A is an 8-bit bi-directional I/O port. Port pins can provide internal pull-up resistors
selected for each bit. The Port A output buffers can sink 20mA. When pins PA0 to PA7
are used as inputs and are externally pulled low, they will source current if the internal
pull-up resistors are activated. The Port A pins are tri-stated when a reset condition
becomes active, even if the clock is not active.






Chapter 3
30
Port B (PB7-PB0)
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors. The Port B output
buffers can sink 20mA. When pins PB0 to PB7 are used as inputs and are externally
pulled low, they will source current if the internal pull-up resistors are activated. The
Port B pins are tri-stated when a reset condition becomes active, even if the clock is not
active.

Port C (PC7-PC0)
Port C is an 8-bit bi-directional I/O port with internal pull-up resistors. The Port C output
buffers can sink 20mA. When pins PC0 to PC7 are used as inputs and are externally
pulled low, they will source current if the internal pull-up resistors are activated. The
Port C pins are tri-stated when a reset condition becomes active, even if the clock is not
active.

Port D (PD7-PD0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors. The Port D
output buffers can sink 20mA. When pins PD0 to PD7 are used as inputs and are
externally pulled low, they will source current if the internal pull-up resistors are
activated. The Port D pins are tri-stated when a reset condition becomes active, even if
the clock is not active.

RESET(bar)
Reset input. A low level on this pin for more than 50ns will generate a reset, even if the
clock is not running. Shorter pulses are not guaranteed to generate a reset.

XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
XTAL2
Output from the inverting oscillator amplifier.

ICP
ICP is the input pin for the Timer/Counter1 Input Capture function.

OC1B
OC1B is the output pin for the Timer/Counter1 Output CompareB function.

ALE
ALE is the Address Latch Enable used with the External Memory is enabled.

Providing a clock source to the AVR processor is another important design process. The
AT908515 microcontroller has a maximum clock frequency of up to 8MHz. For this
project a quartz crystal oscillator will be used to provide a clock signal with a frequency
of 4MHz. These are widely available and work without any problems. They require two
additional capacitors and recommended values are between 22pf and 33pf to help start
oscillations. The quartz crystals have a high Q factor and it takes some time for the
oscillations to build up. This time is called the start-up time and is of the order of 5ms to
Chapter 3
31
20ms. Most of the instructions of the AVR processor take only one clock cycle. For a
clock frequency of 4MHz, this is the equivalent of four million instructions executed
every second.

The AVR microcontroller requires a supply voltage between 2.7V and 6.6V. This supply
voltage must be well regulated since a voltage above the maximum 6.6V could damage
the processor. This is achieved by using a LM7805 Voltage regulator. The 7805 is a
very common type of three-terminal regulator. It can provide up to 1A output current, and
can be fed a DC input voltage between 9Vto 20V, to provide a regulated 5 volts output to
power the AVR processor.

AVR Programming

The AVR microcontroller can be programmed by either of two different methods, the
AVR assembly language or C high level programming language. To control the motors,
the 8515 chip will be programmed in assembly. This method of programming was
chosen because of the critical timing issues involved with controlling the stepping
sequences of the motors. Knowing the clock frequency, and because the AVR assembly
instruction cycles can be accurately determined, timing issues through out the program
can be calculated. By using a high level language, such as C, these calculations can be
made considerably more difficult if not impossible.






Chapter 3
32

Atmel AVR STK500
Figure 3.9


The Atmel AVR STK500 (shown in Figure 3.9) is a starter kit and development system
for Atmels AVR flash microcontrollers. The STK500 gives designers a quick start to
develop code on the AVR combined with features for using the starter kit to develop
prototypes and test new designs. The STK500 interfaces with AVR Studio, Atmels
Integrated Development Invirement (IDE) for code writing and debugging.

The AVR microcontroller has many I/O ports that are well suited for control of stepper
motors. We will be using eight ports total for the output control signals to the driver
circuitry. Ports C0-C3 are connected to the first ULN2003 driver IC and Ports D4-D7 are
connected to the second driver IC. Each of the two drivers are connected to a separate
stepper motor as in Figure 3.10 (next page).











Chapter 3
33


Stepper Motor and Driver Interconnects
Figure 3.10



AVR Microcontroller and Driver IC
Figure 3.11
Chapter 3
34


Section 5: Coordinate Scheme

The processor will receive as input two separate hexadecimal numbers, one for each line
of direction, horizontal and vertical. The numbers will range from hexadecimal 00 to
hexadecimal FF. The hex value 00 will represent the upper, left most position of the
LCD screen and hex FF will represent the lower, right most position. Using this
approach the screen can be divided into a grid of 16 x 16 different quadrants. Once the
microcontroller receives the two hexadecimal coordinates it must calculate the direction
in which to move the camera and also the distance the camera must move to reach the
desired field of view. This process involves calculating the number of steps the motor
must turn for each new set of coordinates. Because the step size of the motors compared
to the displacement of the camera will not be a one to one correspondence, some
calibration will be required.




Coordinate Plane
Figure 3.12


Chapter 3
35

Camera Mount
Figure 3.13



Section 6: Camera mount

The construction of the mount will be broken down into basically two parts. The section
that moves in the horizontal direction and the section that moves in the vertical direction.
The two motors which are providing the motion to the two separate movable sections of
the mount can be interfaced in two ways. The motion can be translated either by gears or
by using belts with pulleys. The designers have chosen to use gears because they are
widely available in many different shapes and sizes.

The use of gears for translation of motion from the motor to the mount has some issues
that must be resolved for the accuracy this project must achieve. With the introduction of
gears there is also the introduction of the gear ratios between the motor and the mount.
There may no longer be a one to one correspondence between the step size of the motor
and the angle of movement of the camera. This issue will add complexity to the software
program of the translator circuit. Since the amount of distance the camera will move for
each given set of coordinates will correspond to the number of steps the motor must
sequence, these gear ratios must be known. Gear ratios become even more involved with
the camera mount moving in two directions, horizontal and vertical. Each line of motion
is controlled by a separate motor interfaced to separate gears. If each line of motion has
Chapter 3
36
different gear ratios, then the number of steps for one motor will differ from the umber of
steps for the other motor to achieve the same displacement. For this reason the number
of steps for every square covered in the grid will differ depending on the line of motion.
This will add complexity to the controlling program because the number of steps for each
motor must be computed separately.

One issue with the design of the pan and tilt camera mount is the effect of the load of the
camera. These loading effects could limit the range of vertical motion the camera can
move. The physical capabilities of stepper motors provide a breaking mechanism to hold
the rotor in position. However, if the toque of the motor is unable to sustain the weight of
the camera, slipping will occur. Another aspect of this problem is when the motor is in
transition from one step to another or when not powered at all. When between steps, for
a small delay, no current is supplied to the coils of the motor. This can drastically reduce
the amount of holding torque the motor can sustain. This becomes a problem when the
camera is moved in a vertical line of motion. Once the camera viewing angle goes below
the horizontal axis, parallel to the base of the mount, being able to produce enough
holding torque to overcome the weight of the camera may become a problem. One
possible solution to this problem is to send a step signal to the motor that will place the
rotor in between steps. This will cause no movement but will continuously supply
current to the windings. This approach will obtain the maximum amount of torque from
the motor. This solution, however, does not apply when the power to the motor is off
completely.




Motion of the Camera

In order to construct a pan and tilt functional mount for the camera it will have to move
both up, down, left, and right. There are basically two options for implementing this
horizontal and vertical motion. The camera could move in one direction, say horizontal,
until it reached its desired horizontal displacement then move in the other direction, say
vertical, until it reached its desired vertical displacement. The other option is have the
mount move in a sort of diagonal motion. This would involve the mount moving
horizontal then vertical then horizontal then vertical until the desired position is achieved.
This method would produce a saw tooth diagonal motion. For this project the designers
have decided to go with the diagonal method of movement. There is really no advantage
of one method over the other because with stepper motors, the same number of steps will
be sequenced either way leading to no gain in speed or distance of movement.

There are two different methods of diagonal movement to consider. The camera could
either more vertical then horizontal in a one to one ratio or in a ratio that is not one to
one. The situation arises that the coordinates received cause a camera displacement that
is more horizontal than vertical. Using the one to one ratio approach, the vertical motion
will have stopped while the horizontal motion continues, causing discrepancies in the
diagonal motion. This can be addressed with the method that is not a one to one ratio.
Chapter 3
37
The ratio of horizontal to vertical steps is calculated and the movement of the camera will
be a ratio of n * horizontal steps to ever one vertical step causing a diagonal motion
through out the duration of the displacement.


Speed of Motion

One of the specifications, or goals of this project is to move the camera to the desired
point of view in a certain amount of time. As a preliminary requirement we hope to
attain a time lapse of no more than two seconds for the maximum displacement of the
camera. Since the coordinate system will consist of a grid with 16 x 16 squares, the
maximum displacement is eight squares horizontal and eight squares vertical. To achieve
the desired time to be able to move this displacement, the speed to the motors will have to
be calibrated correctly. This is done by increasing or decreasing the counters in the
horizontal and vertical delay routines


Section 7: Controller Program Methodology

Main routine

The Main routine of the program starts out by calling an initialize subroutine in order to
set up all parameters of the program. The program then enables global interrupts then set
variable Temp1 equal to zero. The program will then go into its sleep state and wake up
upon an active low level on the external interrupt. Once interrupted the program will
give control to the interrupt routine. Upon returning from the interrupt routine the
variable Temp1 is compared to one. If equal then only the first coordinate has been
received and the program goes back into sleep state and waits for another interrupt. On
the other hand, if the variable Temp1 is equal to zero, the second coordinate will have
been received. Once the second interrupt has been received the global interrupts a
disabled so that the program will not accept any other coordinates until the camera has
reached the position of the received set of coordinates. The program then calls the
Direction subroutine followed by the Step size subroutine, Step ratio subroutine, and
Motion subroutine. Upon completion of the Motion subroutine the program will loop
back to enable global interrupts and complete another loop.

Initialize Subroutine

In the initialization sub routine the interrupt vector of the microcontroller is up so that the
external interrupt will be in use. The external interrupt flag is set to one for enable and
the mode of the external interrupt is set for active on low level. The port data direction
bits are set so that port B is set up as input and port C and D is set up as output. Port B
will receive the coordinate data from the RF encoder chip and Port C and D will output
the step sequence to a separate motor each. The ports C, D and B are all initialized to a
value of zero. Memory is reserved for the storage of constants, and certain registers are
Chapter 3
38
set to dedicated function registers. The AVR microcontroller has a total of 32 general-
purpose registers. This program will make use of 13 registers in total.


Enabling External Interrupts


Status Register SREG
Figure 3.14


The global interrupt enable bit (SREG - I, bit 7) must be set (one) for the interrupts to be
enabled. The individual interrupt enable control is then performed in separate control
registers. If the global interrupt enable bit is cleared (zero), none of the interrupts are
enabled independent of the individual interrupt enable settings. The I-bit is cleared by
hardware after an interrupt has occurred, and is set by the RETI instruction to enable
subsequent interrupts. The RETI instruction returns program control from the interrupt
routine.

Interrupt Sub Routine

During the main routine of the program, the microcontroller will go into a sleep mode in
order to conserve power. The microcontroller will awake from its sleep mode provided
that activity occurs on the external interrupt pin, which is connected to the RF encoder
chip. The encoder chip is interfaced to the controller with five pins transferring five bits
in parallel. Four of the bits are data bits, which contain the coordinates, and the fifth bit
is a valid data bit. This valid data bit is wired to the interrupt pin on the controller. When
active, the valid data bit will interrupt the controller and the data on the input port B pins
will be read. The four-bit number will be stored as a variable X_coordinate in data
memory. The program will then return to the main program and wait for the next
interrupt. Once the second interrupt is received the four data bits are valid with new data
and are stored in a variable Y_coordinate in data memory. Once both coordinates have
been received then the program returns back to the main program.

Direction subroutine

The purpose of the Direction subroutine is to determine the directions up, down, left, or
right the camera must move in order to obtain the desired position. In this routine the
variable X_coordinate is the horizontal coordinate received from the RF encoder chip.
X_coordinate is compared to the variable center, which represents the center position of
the LCD screen. If greater than or equal to center the variable Pan is set equal to 1,
representing a displacement to the right. If X_coordinate is less than center, Pan is set
equal to zero representing a displacement to the left. Next the variable Y_coordinate is
compared to the variable Center. If greater than or equal to center the variable Tilt is
Chapter 3
39
equal to 1, representing a displacement downwards. If Y_coordinate is less than center
then the variable Tilt is set equal to zero, representing a displacement upwards. The
subroutine then returns control back to the main routine.

Step size subroutine

The function of the Step size subroutine is to compute the number of steps each motor
must step in order to move the camera to the desired coordinates. First the variable Pan is
compared to zero. If Pan is equal to zero (displacement is to the left) the variable Xstep
is set equal to the following equation.

Xstep = (Center X_coordinate) (Horizontal_ steps / 2)

The value computed in this equation represents the number of horizontal steps taken to
reach the center of the square for which the transmitted coordinates represent. Center is a
constant that represents the center of the LCD screen. Horizontal steps is a constant that
represents the number of horizontal steps that must be completed to cover one square on
the grid. Horizontal steps is divided by two to represent the number of horizontal steps to
reach the center of an individual square on the grid.

If Pan is equal to one, (displacement is to the right) the variable Xstep is set equal to the
following equation.

Xstep = (X_coordinate Center) + (Horizontal_ steps / 2)

After Xstep has been calculated, the variable Tilt is compared to zero. If Tilt is equal to
zero (displacement is upward) the variable Ystep is set equal to the following equation.

Ystep = (Center Y_coordinate) ( Vertical_steps / 2)

The constant Verticalsteps represents the number of steps in the vertical direction that
must be completed to cover one square.

If Tilt is equal to one, the variable Ystep is set equal to the following equation:

Ystep = (Y_coordinate Center) + (Vertica_lsteps / 2)

After the variable Ystep has been computed the program returns control to the main
routine.

Step Ratio Subroutine

One objective of this project is to move the camera mount in a diagonal direction when
moving from one position to the next. This can be done two different ways. The camera
could move one step horizontal for every one step vertical. The problem with this
method is that if there is more displacement in one line of direction than the other, the
Chapter 3
40
camera will continue stepping in the direction of greater displacement while motion has
ceased in the other direction. This results in a motion that starts out as diagonal and
levels of to either a horizontal or vertical motion only. The other method of
implementing a diagonal motion is to calculate which direction has a greater
displacement and then calculate the ratio of steps needed to maintain a diagonal direction
throughout the duration of motion.

The function of the Step ratio subroutine is to first calculate which direction has a greater
displacement. This is done by comparing the variables Xstep with Ystep which are the
number of steps in the horizontal and vertical directions respectively. If Xstep is larger
the variable Xratio is set equal to the ratio Xstep/ Ystep or horizontal/ vertical. The
variable Yratio is set equal to 0. If Ystep is greater than Xstep the variable Yratio is set
equal to Ystep/Xstep or vertical/ horizontal. The variable Xratio is set equal to 0. The
program then returns control back to the main routine.

Sequence 1 subroutine

The function of the sequence one subroutine is to find which step in the stepping
sequence the motors previously stepped. Because of the physical properties of a stepper
motor, it must be stepped in a certain sequence to obtain clockwise motion and another
specific sequence to obtain counter clockwise motion. If the sequence is becomes out of
order then the motion will be discontinuous. The motor may even move in the reverse
direction in order to line the coils up for the given step in the sequence. This becomes an
important issue in the project. Making the camera move from one set of coordinates to
another requires remembering the order of the step in the sequence that the motors
previously stepped. If this is not done then there is the possibility of moving in the
reverse direction for a step or two before continuing in the correct direction. This will
result in a loss of accuracy.

In the sequence1 subroutine the variable Temp1, which is a temporary register that
contains the data on the port that was last output to the motor, is compared to the number
8. If they are equal then Temp1 will be set to the value 4, which is the next step in the
sequence. If Temp1 is not equal to 8, it is then compared with the value 4. If Temp1 is
equal to 4 then it will be set to the value 2 which is the next step in the sequence. This
continues for every possible step in the sequence until a match is made. It is then
assigned the next step in the step sequence to be output to the motor. The program then
returns control to the calling routine.

Motion subroutine

Once the direction the camera is intended to move and the number of steps needed are
calculated, the motion subroutine is called to provide the stepping sequence to the
motors. At the start of the motion subroutine the variable Xratio is compared to zero.
This is done as a test to determine which line of direction requires the greatest number of
steps so that a counter can be initialized. If Xratio is equal to zero, the vertical direction
has the greatest displacement, and the variable Counter is set equal to Yratio. The
Chapter 3
41
Counter variable is set up so that the number of loops in the routine can be controlled.
Once the counter has been set the variable Pan is compared to zero. If equal, the Temp1
register is set equal to the value of the portD pins and the Sequence1 subroutine is called.
If the Pan variable is not equal to zero, the Sequence2 subroutine is called. After
returning from whichever sequence routine was called, the value in Temp1 now holds the
value of the next step in the sequence for horizontal motion. The next step in the
sequence for vertical motion is calculated in the same way. Next, the routine determines
weather or not any vertical direction needs to be taken. If so, the value of the next step
sequence in line is sent out of portC. If no vertical steps need to be taken, the program
determines if any horizontal steps need to be taken. If there is a horizontal displacement,
the value of the next step in the sequence is sent out through portD. This process is
repeated until the counter expires and the program returns control back to the main
routine to accept the next set of coordinates.
Chapter 3
42
Figure 3.15
Step Size Flow Diagram
Pan = 0

StepX = (center - x) - ((horizontal steps per square)/2)

StepX = (x - center) + ((horizontal steps per square)/2)
False True
Tilt = 0

StepY = (y - center) - ((vertical steps per square)/2)

StepY = (center - y) - ((vertical steps per square)/2)
Return
False
True
Chapter 3
43
Figure 3.16
Direction Subroutine Flow Diagram

X Coord. >
Center
Pan = 1
True
Y Coord. >
Center
True
Tilt = 1
Return
Pan = 0
Tilt = 0
Chapter 3
44
Figure 3.17
Motion Subroutine Flow Diagram

Xratio > 0
Counter = Xratio
Temp2 = Temp1
Temp3 = Temp1
Dec X Step & Counter
Load PortD = Temp2
Call Horizontal Delay
Counter = xRatio
Return from
subroutine

PortC = Temp3
Call Vert Delay
Dec Y Step
Xstep = 0
Tamp1 = port D
Call Seq. 2
F T
Tamp1 = port D
Call Seq. 1
tilt = 0
T
F
Call Seq. 2
Tamp1 = port C Tamp1 = port C
Call Seq. 1
pan = 0
T
Ystep = 0
T
F
Counter = 0
T
Chapter 3
45
Figure 3.18
Step Sequence 1 Flow Diagram

Temp1 = 2
Temp1 = 4
Temp1 = 1
Temp1 = 8
Temp1 = 8
Temp1 = 4
Temp1 = 2
Return
True
True
True
False
False
False
Chapter 3
46
Figure 3.19
Step Sequence 2 Flow Diagram





Temp1 = 4
Temp1 = 2
Temp1 = 8
Temp1 = 1
Temp1 = 1
Temp1 = 2
Temp1 = 4
Return
True
True
True
False
False
False
Chapter 3
47
Figure 3.20
Step Ratio Subroutine Flow Diagram


Xstep > Ystep
True
False
Xratio = Xstep/Ystep
Yratio = 0
Yratio = Ystep/Xstep
Xratio = 0
Return
Chapter 3
48
Figure 3.21
Interrupt Subroutine Flow Diagram

Comp Temp1 =
0
True
Read Port B pins
Store in X coordinate
Temp1 = 1
Fals
e
Read Port B pins
Store in y coordinate
Temp1 = 0
return

You might also like