CMPE 401 - Laboratory #4

Stepper Motor Control Using the Motorola Time Processor Unit (TPU)


Lab Dates:

Please refer to the Lab Web Page and Lab Schedule for lab dates.

Report and Demo Due Dates:

Please refer to the Lab Web Page and Lab Schedule for all due dates.

Objectives:

Equipment, Parts and Provided Software:

PC host running Linux, with two serial ports (/dev/ttyS0 and ttyS1)
New Micros NMIX-0332-OEM 68332-based microcomputer
Memory module ver. 1.1 containing MicroC/OS-II and lwip TCP/IP Stack in ROM
Stepper motor module ver. 1.0 for driving the Jameco stepper motor.
One Jameco 12-VDC, 480-mA, 2-phase bipolar stepper motor, 3.6 degrees per step in full step mode.
One clock face and pointer, already attached to the axle of the stepper motor
The cmpe401 tar file from lab 1.
The hardware setup for lab #3.
The lab 4 tar file

Documentation:

Course Notes (chapter 10 especially)
The M68000 Programming Reference Card
MicroC/OS-II Function Summary
L298 Dual Full-Bridge Driver Datasheet
Jameco Part No. 105881 Stepper Motor Datasheet
Motorola TPU Reference Manual
Motorola Application Note on the TPU Stepper Motor Function
Freescale Application Note on the TPU Discrete IO Function
Freescale Engineering Bulletin On Generating Interrupts On the TPU
Lab 4 Schematic Diagram

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. Each step in the half-step sequence advances the rotor by 1.8 degrees. 200 steps are required for a complete revolution in half-step mode.

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.

The stepper motor module also contains three buttons and three LEDS. The three LEDS have been included to provided status information about the motor. The buttons will act as inputs and can control the rotation of the motor.

Debouncing switches and buttons, while conceptually simple, is typically a non-trivial problem. Switches and buttons do not act in an ideal way. Overshooot and undershoot result from pressing on the switch or button. This non-ideal behaviour makes it more difficult to process button presses in digital systems.

Pre-lab Work:

  1. Outline the requirements for initializing the TPU channels with LEDS (channels 0-2) to output mode and the method used to set the value on the pin to high or low. The LEDS should operate in Discrete IO mode with no interrupts. Consult the references above for information on the Discrete IO function of the TPU.(5 pts)
  2. Provide a flowchart (or pseudocode) for your solution to exercise 3. Include the web portion, the StepCommandTask portion and the LED portion.(5 pts)

Exercise #1: Verify Initial Build and Hardware Setup

Exercise #2: Motor Control Using Interrupts

In this exercise, you will be coding an ISR on TPU channel 8. The interrupt on TPU channel 8 will signal that the motor has finished rotating. You will also be inserting a small amount of initialization code into the TPUInit function to initialize some of the registers required for proper operation of TPU channels 0-2 which drive the LEDS. Consult the tpu.s file for the notes from the lab instructor for guidance.

Exercise #3: Motor Control Using Input From a Web-based Form

In this exercise, a web-based form using the web-server from lab #3 will provide the user input that determines the rotation of the motor. The initial connection will request the index.html page or / using a GET request. Next, the POST request type will provide you with the entered data in the form steps=XXXXX&direction=Clockwise or direction=CounterClockwise. The two fields filled in by the user will determine the number of steps and the direction to turn the motor. Feel free to modify any of the given code to suit your needs.

To see the TCP/IP traffic going over the sl0 interface, use the capture_serial script from lab #3 and Wireshark.

In addition to the rotation of the motor, the red LED should be lit up when the motor is off. The yellow LED should be lit up during the rotation of the motor in the counterclockwise direction.The green LED should be lit up during the rotation of the motor in the clockwise direction.

Report Requirements:

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 16, 2007