PIC Stepper Motor Tester

From OpenCircuits
Revision as of 07:42, 10 March 2008 by Russ hensel (talk | contribs)
Jump to navigation Jump to search

PIC Stepper Motor Demonstration and Test Project

Summary: A PIC16F877A project that operates a stepper motor under the control of a PC running a terminal program.

Author: Russ Hensel, struve13@verizon.net email me any comments questions Last revision November 26 2007 – Draft, near completion except for Java control program. The C code works, but there are lots of errors in other parts of the project – they should be fixed soon, check back or email me Archive zip file ( SerialStepperTest.zip ) includes: this doc, eagle schematic, program listing. 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 De terming angle per step or steps per revolution of a stepper motor. De terming 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, or as an alternative running a Java program that was developed especially to control the PIC. 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.
  • Demonstrate possible stepper motions with a few sets of special routines.

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:

Command Meaning v<cr> Get the version make sure the command interface is running, usually takes 2 tries to initialize, this is a bug which I have not fixed yet. t10<cr> Set the step delay to 10 ms p1<cr> Select permutation 1 d+<cr> Set direction forward g400<cr> Go for 400 steps – full turn on many motors

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. Schematic ( also eagle file is in zip archive see above ):


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 ) Command Code Notes, PIC Response Report version v Version of the PIC software as: v2.3 or similar Set direction d+ d- + for forward, - for back Direction set. Request motor position w Step taken since power on. Signed int. Report on all parameters r Reports on internal state of the PIC driver. Go for a number of steps ( max. about 30,000 ) gnnnn Move nnnn steps. Responds with a !<cr> when done Time delay between steps in ms ( max 255 ) t Reports delay set. Micro second delay in addition to to the ms delay. u Reports delay set. Ok to use values as high as 5000 us. Set the permutation of the motor wires. ( n 0 to 5 ) pn

Set the permutation, find the value that works for your motor. Report permutation set Spin the motor in an interesting way x1 Motor spins !<cr> when done. Vibrate the motor first a lot then less and less to stop x2 !<cr> when done. Stop s Should almost immediately stop long running commands like Go or x1 or x2 !<cr> when done.


Command Meaning Comment
v<cr> Get the version make sure the command interface is running, usually takes 2 tries to initialize, this is a bug which I have not fixed yet.
t10<cr> Set the step delay to 10 ms
p1<cr> Select permutation 1
d+<cr> Set direction forward
g400<cr> Go for 400 steps – full turn on many motors


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.

Possibly useful links: 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

A terminal program this may work for you: Welcome to our Free Download/New Products Page! http://www.rs485.com/psoftware.html

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.