Lab 4Stepper Motor ControlSpring 2001

______

Purpose

In this lab you will do the following tasks:

  • Learn how to use a R/C servo
  • Learn how to use a stepper motor

Discussions

RC - Servos

In control terms, a servo implies a “smart” plant, i.e. one that measures it’s own feedback and controls itself. Instead of sending an open-loop voltage, the signal into a servo is a setpoint for the servo to go to (often referred to as “servoing” to a position). All servos have built-in controllers that move a motor or other device to a given setpoint.

R/C servos are use by hobbyists to fly scale aircraft, cars, boats, etc. Each servo has 3 lines. The signal line (usually white or yellow) receives a setpoint via a pulse. Two other lines (red and black) are used for power (one at 5-10 volts, and one at ground). The signal pulse is sent every 20 ms, and the duration of the pulse high (called the duty cycle) sets the position of the servo. Read you STAMP book if you want to know more on the signal and how a servo works.

A pulse of approximately 2 ms moves the servo full counterclockwise (about 90 degrees), and a pulse of approx. 1 ms moves the servo full clockwise (about –90 degrees). The servo range of motion is usually around 180 – 270 degrees.

Stepper Motors

Stepper motors are motors that have a fixed number of positions that they can move to, and these position correspond to coils and teeth within the motor. Energizing a coil holds a stepper motor fixed at a given position. A stepper motor moves by continuously activating adjacent stator coils. When the coils are energized in a programmed manner, a stepper motor moves between these positions. We can count the number of positions (called steps) that the motor needs to take to move a set distance. The rate of the input pulses determines the velocity of the motor. The inputs to the driver circuit are typically digital pulses, with each pulse corresponding to one step of incremental motion. Another input to the driver is the direction of the stepping motion. Each pulse input to the driver advances the rotor shaft one step toward the commanded direction, at which point the motor latches to the new equilibrium position. If properly controlled, the number of steps that the motor moves is equal to the number of input command pulses. Thus, no angular position feedback is needed for many stepper motor applications; stepper motors are mostly used in open loop fashion.

Stepper Motor Performance Characteristics:

(1)Resolution: This is number of steps per revolution. Typical resolutions are full step resolution: 200 steps, half step resolution: 400 steps, and micro stepping: over 10,000 steps.

(2)Accuracy: This is the dimensional tolerance with respect to the nominal position.

(3)Holding (Static) Torque: This is the restoring torque versus the rotor position. This torque forces the rotor back to the equilibrium positions where the torque returns to zero.

(4)Dynamic Torque (Pull-Out Torque): This is generally the torque-speed curve, which indicates the maximum static torque load at corresponding speeds (or pulse rate) without pulling the motor out of synchronization with the input pulse rate. This curve shows the torque envelope that the motor can be used. When inertial loads are attached to the motor shaft, the effective maximum torque is reduced. The particular speed-torque curve associated with a given inertial load is called pull-in torque.

Figure 1: Counter #1 and #2 setup for controlling a single stepper motor.

To command/control the stepper motor at your bench, you will be using the CIO-INT32 board installed in the PC. The CIO-INT32 is a very versatile digital interface board. The heart of the CIO-INT32 is a pair of Zilog Z8536 programmable digital I/O chips. Each chip is equipped with 20 bits of Digital I/O that can be independently set for input/output and 3 counter/timers that can be set up independently or chained together internally.

To drive the stepper motor you will be using the CMD-50 stepper motor driver from American Precision Industries. This small stepper motor driver requires a voltage supply in the range 15-40 VDC and can produce 3.5 amps/phase maximum. This is more than enough power to drive the small stepper motor at your bench. We will be powering the CMD-50 with 20 VDC and applying approximately 0.3-0.4 amps/phase. There are four important digital input lines into the CMD-50 (they are labeled on the top of the CMD-50 box as): RUN/(RESET), HALF/(FULL), STEP IN, and CW/(CCW). The purpose of each of these input lines is as follows:

STEP INThis line receives the square wave voltage pulses that command the stepper motor to step to its next position. With each pulse (when the input square wave changes from 5V to 0V), the driver activates the adjacent motor coil. The frequency of the pulses then determines the speed the motor spins.

RUN/(RESET) When this input line is high (5 volt), the CMD-50 is in run mode (which we will call RUN). When this input line is low (0 volts), the CMD-50 is in RESET mode. In this mode, the driver ignores the input into the STEP IN port above and holds the stepper motor at it current position (Note: the use of a signal between 0 and 5 volts is called a TTL logic signal, or just TTL for short).

HALF/(FULL) When this input line is high, the driver excites adjacent coils or poles in order to step the motor half way (HALF) between the poles. In the low state, the CMD-50 uses single pole stepping the motor a full step (FULL). The half-step method produces more torque compared to the full-step. In most applications, the half-step method is used simply to obtain more torque.

CW/(CCW)When this line is high, the CMD-50 commands the motor to step in the clockwise (CW) direction. In the low state, the CMD-50 commands the motor to step in the counter clockwise direction (CCW).

To command the stepper motor to perform both velocity commands (spin at a certain speed) and position commands (step x number of steps from current position), we used two timer/counter channels and 3 digital I/O outputs. The three digital outputs are used to command 3 of the 4 lines described above: HALF/(FULL), RUN/(RESET), and CW/(CCW). The output of timer/counter #2 drives the STEP IN line.

Study Figure 1 to see how the Zilog 8536 chip is configured to accomplish the stepper motor control. The timer/counter #2 is used as a square wave generator. The frequency of this square wave corresponds to the speed you would like the stepper motor to spin (think pulses/second). Timer/counter #1 is used to make the stepper motor only move a certain number of steps. The stepper motor will then stop after this position is achieved (position command). Timer/counter #1 counts the number of steps that are sent to the stepper motor and when the desired number of steps has been reached, timer/counter #1’s output goes HI. This gates off timer/counter #2 and thus stops the square wave to the stepper driver. If you would like to just command the stepper motor to spin at a certain speed you can pretty much ignore timer/counter #1 and just program timer/counter #2 with the correct frequency.

The source code uses the following functions. Read through the comments to better understand how the stepper control is accomplished. If you wish, you can read through the Z8536 manual to better understand that chip. The manual is located in one of the bookshelves of the Mechatronics Lab.

Routines:

init_step - Sets up ports and timers

go_position - Go to a target position (relative)

go_velocity - Run at a target velocity

stop - Stop the pulses in position or velocity mode

Counter control routines:

set_frequency - Set the frequency for the steps (timer 2)

set_position - Set the number of steps to go

disable_ctrs - Inhibit counter activity

enable_ctrs - Allow counter activity

pause_ctr - Pause counting

continue_ctr - Continue counting

tigger_ctr - Start a counter running

count_in_prog - Indicates whether a counter is running

clear_IP - Clear the interrupt flag (set when ctr finishes)

Digital I/O routines:

set_RUN - Set driver to "RUN"

set_HOLD - Set driver to "HOLD"

set_CW - Set clockwise direction

set_CCW - Set counter-clockwise direction

set_HALF - Step by half-steps

set_FULL - Step by full-steps

The line connections to the computer are shown below in Figure 2:

Figure 2: The pin-out of the CIO INT-32 board.

In Lab Assignment:

RC Servos (15 min)

  1. Using the code supplied to you, determine approximately how many degrees the servos can move through.
  1. Scope a signal going to the servo. Sketch what it looks like. Very often hobbyists use IC chips to test their servos. What chip would they most likely use?
  1. Experiment with the servos. Do the servos move faster or slower than the stepper or DC motors? Is there a minimum angular resolution (approximate)? For their size, how would you rate the torque output of the servos?
  1. If you only need to command 1 stepper motor with the Int32 board, how many R/C servos can you command (this does NOT mean to code this)? If you are not using stepper motors, how many servos then?

Stepper Motors (remainder of lab)

  1. Play with the steppers. Can you stop them with your hand at low velocity? At high velocity?
  1. Command the motor to start moving with a certain velocity. Find out the highest attainable speed for your stepper motor if the motor is started at rest.
  1. Incrementally ramp up the speed of the motor (i.e. command it to 2000, then 3000, then 4000…). Find out the highest attainable speed by using this method. Is this highest speed less or more than the speed from 1 above? Why would this be?
  1. We want to implement a capability to go to a high velocity without doing the ramp up procedure manually. We will set up another RTSS timer to run a task that commands the motor to ramp up to a speed at a given acceleration. The starting speed, final speed, and acceleration should be downloaded from VB. To do this, you will need to use components developed in previous labs and make major modifications.
  1. Start by creating a new RTSS timer by copying all variables and function calls used to create the servo timer.
  2. When you call your new “RtCreateTimer” function, leave the priority of the timer the same as the servo’s timer (Lab 6 will study priorities).
  3. In the call to the new “RtSetTimerRelative” function, set the timer to a 20 ms sample rate.
  4. Within the RTSS timer, make the speed change at each time sample using a linear ramp (fit a line to the first velocity using the acceleration as the slope). Shut off the ramp once the final speed is achieved. Note: you will have to make a global variable that keeps track of time. It is best to save the global time value as an integer to prevent round-off error, and then multiply it by the time step when the “actual” time is needed. Otherwise, the round off error would slowly (to a computer, quickly to humans) drift. In addition, the “shut off” of the ramp should be done using a flag that is high when the final velocity is reached or when the user hits a “stop ramp” button (this allows the user to stop the ramp if it is not working or incredibly slow).