Stepper Motor Demonstration and Tester

= Stepper Motor Demonstration and Test Projects =

This page is draft will superceed much of the info on PIC Stepper Motor Tester which is for the PIC and a new page Stepper Motor Tester for the Arduino which is for the arduino

Archive zip file see individual pages for each sub project, PIC Stepper Motor Tester which is for the PIC and Stepper Motor Tester for the Arduino for the Arduino or email me russ_hensel for the most up to date info.
 * Name: Stepper Motor Demonstration and Test Project
 * Status: still developing, but is working. 2 Versions one for PIC and one for the Arduino.  Most of the code is very similar, circuits as well
 * Technology: Both Programmed in C.
 * Author: russ_hensel ( where you can find an email address to reach me )
 * Summary: A project that operates a stepper motor under the control of a PC running a terminal program. Can both test the motor and demonstrate its functions
 * Last revision Dec 20 2010
 * Downloads are available see download section on the sub page for each project

This project has several potential uses:


 * Example code for stepper motor control and for RS232 communications.
 * Determining which drive wire is which on a unipolar stepper motor. This is the type of motor that I have most commonly found surplus or in salvage equipment.
 * Determing angle per step or steps per revolution of a stepper motor.
 * Determing maximum speed of stepper motor.
 * Demonstrating the operation of a stepper motor.

The project is able to drive a stepper motor in a number of ways ( controlled by the RS232 connection ):


 * Set the number of steps
 * Set the direction of the steps
 * Set the time delay between the steps
 * Drive the wires to the stepper in any of the 6 possible connections ( permutations), this allows the user to determine which wire is which.
 * Test the max speed of the motor using an accelerating drive signal.

In general the stepper is driven by issuing several commands to set it up and then a final command to take a series of steps using this setup.

Example:

Hardware
See the individual pages, in general the ucontroller does all the logic and the drive is done by low side darlington transistors see: Stepper Motor Tester which is for the PIC and Stepper Motor Tester for the Arduino.

Command Interface
All commands ( except stop should be terminated with a carriage return ) Note that the command interface is not very smart, giving parameters that are out of range my blow the whole program up. If so reboot the microcontroller. Do not send a new command ( except stop ) until earlier commands have been completed ( actually you can get ahead some if you are careful ). Commands may be either upper or lower case. The backspace key usually works.

Notes on terminal program set up.

Some terminal programs will not transmit in lower case ( all our commands are lower case ) unless specially set to do so. Set it to allow lower case.
 * Baud rate should be 19.2K 8N1, but is easily adjustable in the header file for the program.
 * Most terminal programs can be set to treat a carriage return as a carriage return line feed. Do it.

Microcontroller Program Design
I no longer have the patience for assembly language. I have moved on to C in particularly BoostC on the PIC the C in arduino.exe for the Arduino, see link below. Writing in C should makes the program fairly easy to read. Most of the design should be evident by reading the program, however a few notes here may help.

The idea is to put each activation sequence in a table ( or Array if you prefer ) and then step through that table and activate the corresponding port bits and thus stepper coils. The four wires can be activated in a total of 6 different ways, one table corresponds to each permutation. The particular table to use is set using the permutation command ( p ).

The series of wires to energize is specified in the arrays StepperStepsN where N is the number of the wire permutation. Each step just increments its way through the array wrapping around the the beginning and the end.

Commands are received via an serial communications routine, the main loop checks each time around to see if a complete command has been received. Because commands are only interpreted in the main loop all commands are ignored until the program returns to the main loop. The exception to this is the stop command which will terminate a g or x command and return to the main loop quickly. RS232 transmission is not driven by an interrupt and so during transmission from the microcontroller no stepping takes place. Commands which do not result in motion execute very quickly, most of the time is for communications.

Currently drive to the motor is half step drive. This gives twice as many steps per revolution as is labeled on the motor. I plan later to let you select half step, full step or wave drive. See the links below for more information.

Which Wire is Which?
Unipolar motors typically have 6 wires that come in 2 pairs. Typically the “center tap” of each winding is connected to V+ and the individual windings are grounded ( as with the Darlington array described in hardware ) to switch them on. The tester does not determine which of the wires are the center taps, but that is easy to do with an ohm meter. Each center tap will have the same resistance to far end of either of the coils connected to it. There will be twice the resistance between the ends of the coils. Sometimes the two center taps will be connected together so the motor has only 5 wires. Sometimes the center taps will be the only two wires that are the same color. Once the center taps have been determined connect them to V+ ( whatever voltage is appropriate for the motor ) and the other wires in any order to the 4 ports. Name the wires A, B, C, D ( or use the wire colors if available, adjusting the chart below for the colors ) and connect to the drivers on bit 0, 1, 2, 3. ( in the software given I have actually used bits 4, 5, 6, 7 )

Make sure the microcontroller booted up all right and the serial connection is working – use the Version command ( v) and see if the response is reasonable, if not try the command another couple of times, if it sill does not work reboot the microcontroller. If it still does not work check over the communications parameters on your terminal program. And so on.

Set the motor to run forward, with say 10 ms delay per step ( t10 ) Choose permutation 0 ( p0 ). Now try 100 steps ( g100 ) If the motor does not run try another permutation.

If the motor is good you should find 2 configurations that work, one forward, one back. ( In some cases I have found more than 2, I do not quite understand this, look for the smoothest running -- add a little resistance to turning and you will find the duplicates have almost no torque ) The jerky motion of the shaft can be deceiving, I add a pointer to the shaft, one that will not slip. This chart then tells you the “standard” identification of the wires:

Discussion

Which wire is which depends in part what you consider a standard coil activation sequence. From my reading I believe that this corresponds to the table Zero_StepperSteps in the code. Your standard may differ, if so you can modify the code. The code uses a so-called “half step” drive. You can contact me russ_hensel if you are having trouble figuring this out. Google will link you to a huge amount of information on steppers.

Stepper Test Form
I have developed a form for testing motors that I find useful. It looks something like this ( and is included in the file download package ):



In use:

Example, filled out:



Other Things to Try With the Tester
Run it faster and faster ( shorter time delay ) until it fails. You may want to turn it 400 turns to clockwise fast, then 400 counter clockwise slow. If it does not end up where it started then it skipped a step or more. If you know how many steps per rev then you need not reverse it just ask it to go a round number of revolutions.
 * How fast can your stepper go?

Guess, try to make it turn 10 revolutions fairly slowly or at least slowly enough so that it is not skipping steps.. If you number is right it will end up at the same angle it started. If not try a new guess.
 * How many steps per revolution for your motor?


 * Demo the motor with Special Commands x1 and x2:
 * x1: spins the motor one way faster and faster, then reverses and returns to original position.
 * x2: motor vibrates faster and faster through smaller and smaller arc, then stops where it started.

Additions/Changes
These are changes I may or may not make: ( or you may take them on )


 * Add servo testing to the project ( actually fairly easy as I already have the servo tester, standalone, done. Just need to merge in the code. ).


 * Add selection for half step, full step or wave drive.


 * Use low side switches ( normally darlington connected transistors, or logic level mosfets ) with higher current ( and perhaps voltage ) rating. The current circuit is limited to about 500 ma.


 * Move the rs232 level shifter into the cable and drop it from the circuit, then the level shifter can be used for many projects.

Possibly useful links
This program uses my: Serial Communications Library -- BoostC and 16F877A

A closely related project with a lot of similar code: PIC based Stepper Motor Dancing Analog Clock

[RS232] Discusses the sort of interface that is used by this project.

More information on serial communications with microcontrollers: Microcontroller Serial Communications Articles

Info on steppers: Stepper motors http://www.allaboutcircuits.com/vol_2/chpt_13/5.html

More info on steppers: Basic Stepping Motor Control Circuits http://www.cs.uiowa.edu/~jones/step/circuits.html


 * PC-Microcontroller Communications discusses free terminal programs, most much better than hyperterminal.

BoostC – I think the free version is enough to compile the program: SourceBoost Technologies http://www.sourceboost.com/

Some may considered this project for just determining which stepper wire is which overly complicated: there are some simpler methods ( for example: http://www.doc.ic.ac.uk/~ih/doc/stepper/others/ ). However for one reason or another this has not always worked for me, this test is definitive and fun.

Download
Archive zip file see individual pages for each sub project, PIC Stepper Motor Tester which is for the PIC and Stepper Motor Tester for the Arduino for the Arduino or email me russ_hensel for the most up to date info.

Comment, Questions, Contributions?
Email me russ_hensel, or use the talk page for this topic. All feedback is welcome.