Post on 03-Jun-2018
8/12/2019 Motoare pas cu pas ,exemplu_1
1/28
Chapter 3
Camera Mount
8/12/2019 Motoare pas cu pas ,exemplu_1
2/28
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, thedesigners 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 steppermotors 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 arewithin the motor limits, a stepper motor may present a much more economical solutionthen 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 theamount 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 notthe 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 isnot 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. Thelarger 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 fullcurrent 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 thissome 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
8/12/2019 Motoare pas cu pas ,exemplu_1
3/28
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 magnetstepper 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 isattached 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
8/12/2019 Motoare pas cu pas ,exemplu_1
4/28
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. Thisswitching 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 thewire. 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 beincreased by the factor of 2 and this produces a direct proportional affect on the torque.
Figure 3.2
8/12/2019 Motoare pas cu pas ,exemplu_1
5/28
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 thetranslator 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 beinterfaced 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 protectionas to not damage the translator circuitry.
The designers of this project have decided to use the ULN2003 driver manufactured byAllegro 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.
8/12/2019 Motoare pas cu pas ,exemplu_1
6/28
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 stepsequence. 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 motorrotates 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 threedifferent 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
8/12/2019 Motoare pas cu pas ,exemplu_1
7/28
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
8/12/2019 Motoare pas cu pas ,exemplu_1
8/28
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 itsposition 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 takestwice 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 pulsethe 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 microprogrammable 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 ofthe 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 havebeen 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 thesoftware 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 AVRincorporates 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 andpower 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.
8/12/2019 Motoare pas cu pas ,exemplu_1
9/28
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 resistorsselected 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 conditionbecomes active, even if the clock is not active.
8/12/2019 Motoare pas cu pas ,exemplu_1
10/28
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 outputbuffers 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. ThePort 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 areexternally pulled low, they will source current if the internal pull-up resistors areactivated. 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.
XTAL2Output from the inverting oscillator amplifier.
ICPICP 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 thisproject 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 startoscillations. 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
8/12/2019 Motoare pas cu pas ,exemplu_1
11/28
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 executedevery 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 damagethe 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, andcan 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 steppingsequences of the motors. Knowing the clock frequency, and because the AVR assemblyinstruction 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.
8/12/2019 Motoare pas cu pas ,exemplu_1
12/28
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, AtmelsIntegrated 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 areconnected to the second driver IC. Each of the two drivers are connected to a separate
stepper motor as in Figure 3.10 (next page).
8/12/2019 Motoare pas cu pas ,exemplu_1
13/28
Chapter 3
33
Stepper Motor and Driver Interconnects
Figure 3.10
AVR Microcontroller and Driver IC
Figure 3.11
8/12/2019 Motoare pas cu pas ,exemplu_1
14/28
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 tohexadecimal 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 themicrocontroller 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 motormust 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
8/12/2019 Motoare pas cu pas ,exemplu_1
15/28
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 sectionthat 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 orby 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 issuesthat 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 motorand 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 mustsequence, these gear ratios must be known. Gear ratios become even more involved withthe 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
8/12/2019 Motoare pas cu pas ,exemplu_1
16/28
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 numberof 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 canmove. 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 intransition 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 belowthe 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. Onepossible solution to this problem is to send a step signal to the motor that will place therotor 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 offcompletely.
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 willbe 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 couldeither 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 motionwill 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.
8/12/2019 Motoare pas cu pas ,exemplu_1
17/28
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 motionthrough 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 desiredpoint 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, themaximum 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 toset 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 willgive 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. Onthe other hand, if the variable Temp1 is equal to zero, the second coordinate will havebeen 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 theDirection 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 theexternal 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 Bwill 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
8/12/2019 Motoare pas cu pas ,exemplu_1
18/28
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 beenabled. 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 byhardware 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 inorder 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 bitis 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 pinswill 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 havebeen 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, orright the camera must move in order to obtain the desired position. In this routine thevariable 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 setequal 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
8/12/2019 Motoare pas cu pas ,exemplu_1
19/28
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. Thesubroutine 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 iscompared 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 aconstant 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 onthe grid. Horizontal steps is divided by two to represent the number of horizontal steps toreach 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 thefollowing 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 thatmust 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 mainroutine.
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 cameracould 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
8/12/2019 Motoare pas cu pas ,exemplu_1
20/28
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 andlevels 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 greaterdisplacement. 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. Thevariable 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 steppingsequence 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 oforder 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 motorspreviously 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 number8. 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 thenassigned 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 arecalculated, 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 ofsteps 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
8/12/2019 Motoare pas cu pas ,exemplu_1
21/28
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 Temp1register 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 thesequence 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 stepsequence 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 isrepeated until the counter expires and the program returns control back to the main
routine to accept the next set of coordinates.
8/12/2019 Motoare pas cu pas ,exemplu_1
22/28
Chapter 3
42
Figure 3.15Step Size Flow Diagram
Pan = 0
StepX = (center - x) - ((horizontal steps per square)/2)
StepX = (x - center) + ((horizontal steps per square)/2)
FalseTrue
Tilt = 0
StepY = (y - center) - ((vertical steps per square)/2)
StepY = (center - y) - ((vertical steps per square)/2)
Return
False
True
8/12/2019 Motoare pas cu pas ,exemplu_1
23/28
Chapter 3
43
Figure 3.16Direction Subroutine Flow Diagram
X Coord. >
Center
Pan = 1
True
Y Coord. >
Center
True
Tilt = 1
Return
Pan = 0
Tilt = 0
8/12/2019 Motoare pas cu pas ,exemplu_1
24/28
Chapter 3
44
Figure 3.17Motion 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 = Temp3Call Vert Delay
Dec Y Step
Xste = 0
Tamp1 = port D
Call Seq. 2F T
Tamp1 = port D
Call Seq. 1
tilt = 0
TF
Call Seq. 2
Tamp1 = port C Tamp1 = port C
Call Seq. 1
an = 0
T
Yste = 0
T
F
Counter = 0
T
8/12/2019 Motoare pas cu pas ,exemplu_1
25/28
Chapter 3
45
Figure 3.18Step 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
8/12/2019 Motoare pas cu pas ,exemplu_1
26/28
Chapter 3
46
Figure 3.19Step 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
8/12/2019 Motoare pas cu pas ,exemplu_1
27/28
Chapter 3
47
Figure 3.20Step Ratio Subroutine Flow Diagram
Xstep > Ystep
True
False
Xratio = Xstep/Ystep
Yratio = 0
Yratio = Ystep/Xstep
Xratio = 0
Return
8/12/2019 Motoare pas cu pas ,exemplu_1
28/28
Chapter 3
Figure 3.21Interrupt Subroutine Flow Diagram
Comp Temp1 =
0
True
Read Port B pins
Store in X coordinate
Temp1 = 1
Fals
Read Port B pins
Store in y coordinate
Temp1 = 0
return