PIC Stepper Motor Tester

= PIC Stepper Motor Demonstration and Test Project =

There are multiple versions of this project for general infomation see: Stepper Motor Demonstration and Tester Note: we now have a version for the Arduino: Stepper Motor Tester for the Arduino


 * Name: PIC Stepper Motor Demonstration and Test Project
 * Status: still developing ( on back burner ), but is working. Planning a version for the Arduino.
 * Technology: PIC microcontroller with code in BoostC
 * Author: russ_hensel ( where you can find an email address to reach me )
 * Summary: A PIC16F877A project that operates a stepper motor under the control of a PC running a terminal program.

Last revision July 4 2008 – Draft, near completion except for Java control program. The C code works, but there are lots of some in other parts of the project. Archive zip file ( SerialStepperTest.zip ) includes: this doc, eagle schematic, program listing. Posted in download section.

This project has several potential uses:


 * Example code for stepper motor control and for RS232 communications ( interrupt driven on the receive end ) on the PIC16F877A.
 * 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.

Platform: PIC16F877A using BoostC connected via rs232 to a PC running a terminal program. The PIC chip is supplemented with a MAX232 chip and a ULN2003 driver.

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.

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
I have used a PIC 16F877A for the project, but pretty much any PIC with a uart and another 4 free I/O lines should do. To increase the drive to the motor I used a ULN2803 which is simply an array of Darlington transistors and diodes to be used as a low side switch for each motor winding. There are other similar chips around or discrete devices can be used. I run the pic, on 5 volts, and a larger voltages for the stepper, up to the limit of the driver. ( the UNL2803 is good for 50 v at .5 amp as a switch ) and the rating of the stepper motor. If you have a high power motor you may want a driver with more guts, Just put in some substitute. Coil drive is on or off there is no PWM involved here. Note that the hardware has substantial uncommitted resources. You could easily drive another motor for example. Also some of you may want to put some pull up or down resistors on some of the uncommitted resources. Instead of this board you could use the circuit from the PIC based Stepper Motor Dancing Analog Clock, the main difference is that that circuit does not use the MAX232 chip, it relies on an off board level shifter ( makes it easy to shift the level shifter from project to project while saving some money and board space )

Schematic


Parts -- this is not up to date, working on it

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 PIC. Do not send a new command ( except stop ) until earlier commands have been completed ( actually you can get ahead some if you are careful ). In earlier versions the commands had to be in lower case, I think current versions take either upper or lower case - check it out.

see: Stepper Motor Demonstration and Tester which covers both the PIC and Arduino Version.

Microcontroller Program Design
I no longer have the patience for assembly language. I have moved on to C in particularly BoostC, see link below. I like this compiler it has both a free version with some restrictions and a very reasonably priced full version. Writing in C should make the program fairly easy to read. Most of the design should be evident by reading the program, however a few notes here may help. see: Stepper Motor Demonstration and Tester for comments that apply to both the PIC and Arduino versions of the project.

Compiling
The zip file contains the entire source bootst project. Unzip into a directory and open in source boost. Set the target to 16F877A and change the linker options ( Settings -> options -> linker Settings -> options -> compiler   ) There are 2 #defines, one for 20 meg crystal and one for a 4 meg crystal. After compiling my compiler reports something like:

Memory Usage Report


 * RAM available:368 bytes, used:139 bytes (37.8%), free:229 bytes (62.2%),
 * Heap size:229 bytes, Heap max single alloc:95 bytes
 * ROM available:8192 words, used:2118 words (25.9%), free:6074 words (74.1%)

I think you could contract the program a bit to get under the 2K free compiler limit.

Java Control Program
This was once an idea, but I have dropped it for lack of interest ( both mine and others ). Some thoughts that I had in the past:

Rather than use a terminal emulation program you can use a Java Program. This makes it easier to issue commands and has a much lower chance of making a mistake. The interface looks like this: ( actually almost written, email me if you have a special interest ).

This basically issues the same commands as you can issue with the terminal. There are a couple of enhancements

 sends all the parameters then the go command, thus you can run the whole setup by typing in the parameters and pressing .

Which Wire is Which?
Stepper Motor Demonstration and Tester which covers both the PIC and Arduino Version.

Other Things to Try With the Tester
Stepper Motor Demonstration and Tester which covers both the PIC and Arduino Version.

Additions/Changes
Stepper Motor Demonstration and Tester which covers both the PIC and Arduino Version.

Possibly useful links
Stepper Motor Demonstration and Tester which covers both the PIC and Arduino Version.

Download
If you want the most up to date version, email me to see if there have been some unposted revisions. russ_hensel

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