Lab
4 Suggested Breadboard Layout
Background:
Microcomputers are sometimes used to control rotating mechanisms, such as
shafts and axles as well as attached pulleys, gears and/or wheels. A stepper
motor is a motor whose rotor position can be controlled precisely by
switching direct current (DC) voltages to two or more stator windings.
Each winding can be energized in the forward direction, energized
in the reverse direction, or not energized at all.
Such a motor is convenient to control using a microcomputer since only
buffered digital H-bridge input signals are required.
Motorola's Time Processor Unit (TPU) is a programmable sub-system
in the MC68332 microcontroller that has built-in functions that greatly simplify
the generation of the digital waveforms that are required to control a stepper
motor.
The stator windings in a stepper motor must be energized in the correct
direction and in the correct sequence in order to produce controlled rotation of
the rotor. The first six steps in the full-step sequence are given in the
table below, which assumes the use of the L298 dual H-bridge driver IC.
Note that the provided TPU driver controls the L298 enable inputs EnA and EnB using
TPU timer channel 12 and 13 , and drives L298
inputs IN1, IN2, IN3 and IN4 using TPU timer channels 8, 9, 10 and 11,
respectively, with the built-in stepper motor function.
Each step in the
full-step sequence advances the rotor of the Jameco motor by 3.6 degrees; thus
100 steps advance the rotor through one full revolution.
| Full-Step Sequence |
| Step |
Winding A Current Direction |
Winding B Current Direction |
L298 EnA = EnB = 1 |
| L298 Outputs |
L298 Inputs |
| OUT1 |
OUT2 |
OUT3 |
OUT4 |
IN1 |
IN2 |
IN3 |
IN4 |
| #1 |
forward |
forward |
source |
sink |
source |
sink |
1 |
0 |
1 |
0 |
| #2 |
forward |
reverse |
source |
sink |
sink |
source |
1 |
0 |
0 |
1 |
| #3 |
reverse |
reverse |
sink |
source |
sink |
source |
0 |
1 |
0 |
1 |
| #4 |
reverse |
forward |
sink |
source |
source |
sink |
0 |
1 |
1 |
0 |
| #1 |
forward |
forward |
source |
sink |
source |
sink |
1 |
0 |
1 |
0 |
| #2 |
forward |
reverse |
source |
sink |
sink |
source |
1 |
0 |
0 |
1 |
Note that in the full-step sequence, the total current drawn by the motor
from the DC power supply is roughly the same in every step position.
If one relaxes this constant-current restriction, then one can double the
resolution of the rotor positioning by using the half-step sequence,
which is shown in the table below.
The additional cost of the half-step sequence is that the control
waveforms are slightly more complicated and the total drawn current
becomes position-dependant.
In the case of the laboratory set-up, the two L298 enable inputs (EnA
and EnB) are controlled separately using two different TPU timing channels.
Thus the recommended hardware configuration assumes that EnA and EnB channels
are properly disabled whenever the winding current is supposed to be off.
| Half-Step Sequence |
| Step |
Winding A Current |
Winding B Current |
L298 Outputs |
L298 Inputs |
| OUT1 |
OUT2 |
OUT3 |
OUT4 |
EnA |
EnB |
IN1 |
IN2 |
IN3 |
IN4 |
| #1 |
forward |
forward |
source |
sink |
source |
sink |
1 |
1 |
1 |
0 |
1 |
0 |
| #2 |
forward |
off |
source |
sink |
off |
off |
1 |
0 |
1 |
0 |
X |
X |
| #3 |
forward |
reverse |
source |
sink |
sink |
source |
1 |
1 |
1 |
0 |
0 |
1 |
| #4 |
off |
reverse |
off |
off |
sink |
source |
0 |
1 |
X |
X |
0 |
1 |
| #5 |
reverse |
reverse |
sink |
source |
sink |
source |
1 |
1 |
0 |
1 |
0 |
1 |
| #6 |
reverse |
off |
sink |
source |
off |
off |
1 |
0 |
0 |
1 |
X |
X |
| #7 |
reverse |
forward |
sink |
source |
source |
sink |
1 |
1 |
0 |
1 |
1 |
0 |
| #8 |
off |
forward |
off |
off |
source |
sink |
0 |
1 |
X |
X |
1 |
0 |
| #1 |
forward |
forward |
source |
sink |
source |
sink |
1 |
1 |
1 |
0 |
1 |
0 |
| #2 |
forward |
off |
source |
sink |
off |
off |
1 |
0 |
1 |
0 |
X |
X |
The stepper motor that you will be controlling in this set of laboratory
exercises will be operated in open loop mode.
By this we mean that the microcomputer sends out digital signals to the
stepper motor and assumes that the rotor will always rotate through
precisely the correct number of steps.
The microcomputer lacks the feedback means to verify the actual position of
the rotor before and after each step command.
Open loop operation is more risky in the sense that the microcomputer
cannot verify that it does indeed have accurate control over the
rotor's position.
The rotor position may in fact deviate from the
expected position if, for example, the limited torque of the motor is unable to
rotate the loaded shaft fast enough to keep up with the stepping commands. A
better alternative to open loop operation would be to operate in closed
loop mode.
To do this one would need to provide feedback through a shaft encoder sensor that
would allow the microcomputer to independently verify the actual position of
the rotor. But we will not be using feedback in this lab. Instead you will
initially set the rotor pointer to the "12 o'clock" position, which the TPU
driver software will then associate with step number $7FFF, which is
the middle position in the full range of 16-bit unsigned positions.
Pre-lab Work:
-
You are to arrive at the lab with the circuit pre-wired according to the schematic diagram. This will be checked at the beginning of the lab by the lab instructor and TA. (10 Points)
-
To get the pin layout for the L298 correct, make sure you orient the H-bridge with the 45 degree corners to the left and the metal up. Pin 1 is the top pin. View the L298 Dual
Full-Bridge Driver Datasheet for confirmation.
-
Please note that you should power your H-Bridge (L298) from the provided power supplies only. You will blow up the boards if you use the 5 V supply off the board.
-
If the space on your board is at a premium, feel free to remove the latch and LEDs from lab #1. They won't be used in this lab. The DUART and MAX232 will be used, so don't remove either of those ICs or supporting components and circuitry.
-
A diagram of the J1 header and all other pins on the 68332 board is available.
Exercise #1: Verify Initial Build and Hardware Setup
-
Download the lab4 tar file and place it into your cmpe401 directory. Untar it by typing
tar xvf lab4.tar
-
Change into the newly untarred lab4 directory and type
make
-
Use the normal download procedure to download the lab4.s19 to the board and run it by typing
go 10000
-
This initial build will test your hardware setup. The specifications for this initial build is as follows:
- Stepping the stepper motor using polling
- Full-Step Mode
- 14 Step Rates
- Min 25 steps/sec, Max 200 steps/sec
-
Grasp the spindle of the motor and orient the shaft so that the dot is placed in the 12 o'clock position. Originally all of the motors had pointers connected to the spindles but many of them have fallen off. Don't be concerned by that.
-
The PollingMotorTask will rotate the motor continually using a consistently repeating pattern of one rotation clockwise, a pause for one second, and one rotation counterclockwise.
-
If the motor is not rotating or the red light indicating power-supply overload is illuminated on the Instek power supplies, turn the power to the motor off immediately. Damage to the power supplies or the 68332-based boards may result if you don't take prompt action to turn off the power to the motor during improper operation.
Exercise #2: Motor Control using Interrupts
-
Comment out the line of code that creates the PollingMotorTask and uncomment the line that creates the InterruptMotorTask. Note the similarities and differences between the PollingMotorTask and the InterruptMotorTask.
-
Uncomment the line of code that turns interrupts on for the primary channel (TPU8) of the stepper motor.
-
Create the code in the TPUISR that posts to the InterruptSem semaphore to signal to the InterruptMotorTask that the previously requested step request has completed.
-
Modify the TPUInit code to run the stepper motor with the following specifications:
- Stepping the stepper motor using interrupts
- Half-Step Mode with EnA controlled by TPU channel 12 and EnB controlled by channel 13
- 10 Step Rates
- Min step rate 18 steps/sec; maximum step rate 300 steps/sec
Explain how you obtained the correct STEP_CNTL0 and STEP_CNTL1 values to achieve the desired minimum and maximum stepping rates.
Exercise #3: Motor Control over a TCP/IP SLIP Interface.
-
Modify your stats server code from lab #3 to operate as a motor controller. Use the same port as your stats server did (ie. port 8). The PositionDataQueue message queue should contain a sequence of stepper motor position readings taken 32 times per second from the CURRENT_POSITION parameter (ie. the third word in the primary channel's parameter RAM area). The readings are to be made by a high priority MicroC/OS-II task that is dedicated for the purpose. The sequence of position readings should be started immediately before the next CURRENT_POSITION is loaded, and should end with the first scheduled reading made right after the TPU interrupt when the new position has been reached. The message queue should be large enough to hold up to five seconds of motor movement.
-
Your stepper motor driver must operate using interrupts, as in the previous exercise.
-
Your motor controller must support 5 commands (with all alternative forms):
-
"rot X" and "cw X"
This command will rotate the motor X number of steps clockwise. You must verify that X is an integer. You are not required to support floating-point numbers!
-
"rot -X" and "ccw X"
This command will rotate the motor X number of steps counterclockwise. You must verify that X is an integer. You are not required to support floating-point numbers!
-
"getdata" and "gd"
This command will retrieve position data from the PositionDataQueue and display it to the user in the terminal window over a TCP/IP connection. Hint: it will be convenient to produce a neatly formatted table in the terminal window that can be stored in a text file that can then be input into a plotting utility, such as gnuplot, Matlab, or Excel.
-
"cleardata" or "cd"
This command will empty the PositionDataQueue
-
"bye" or "quit"
This command will terminate the connection.
-
You are to collect and graph out (in plots of rotor position versus time) the behaviour of at least four different stepping profiles. The first profile should be the same as in Exercise #2, but using full stepping instead of half stepping. Be sure that the movement command that you issue allows the stepper motor to reach its maximum stepping rate before it starts to slow down again. The second profile should have 10 different stepping rates (the same as in the first profile) but the maximum stepping rate should now be only 150 steps per second. The minimum stepping rate should remain 18 steps per second. The third profile should have five different stepping rates with a minimum stepping rate of nine steps per second and a maximum stepping rate of 150 steps per second. Include at least one additional stepping rate experiment of your own design.
Report Requirements:
-
Briefly describe the L298 hardware and its interface to the NMIX 332. Explain how your TPUISR gets called.
-
Include neat graphs (hand-drawn graphs are acceptable if drawn with a straight edge) of the stepping profiles measured in Exercise #3. Include a brief explanation of the rotor's movements. Clearly show how STEP_CNTL0 and STEP_CNTL1 were computed in each case.
-
Your typed report is to briefly describe your design solution for the
last two laboratory exercises.
-
Be sure to provide neatly formatted and well commented code for the two
exercises. Include any code that you inserted or modified. Do not include the code you were explicitly instructed to modify unless you modified it in a different way.
-
Briefly describe your test cases for verifying that each of your solutions
was working properly. How did you verify that the motor could be
half-stepped as well as full-stepped in Exercise #2? Describe which cases were tested, as well as the
anticipated and actual results for each test case.
Consult the Report Marking Guidelines
if you have any questions regarding the report format.
Marking Scheme:
Lab #4 is worth 25% of the final lab mark.
Please view the Marking Sheet
to ensure that you have completed all of the requirements of the lab.
The Marking Sheet also contains a limited test suite
in the demo section. Please make use of it.
Last modified November 24, 2004