µC Stepper Control 2 Plus
by Martin Clausen (mc AT rotgradpsi DOT de)
This circuit employs a MCU to control one bipolar stepper motor via RS232.
- three phase movement: acceleration, constant speed, deccelleration
- true trapezoid motion profile
- drives one bipolar stepper motor in full step, half step, or quarter step mode
- constant torque in full and half step mode
- 0 to 16.7M steps per command
- 30Hz to 18KHz stepping frequency
- support for reference and limit switches
- current reduction / zero current during hold
- linking of mulitple axes (synchron within less then 1µs)
- soft and instant stop command (remaining steps are reported)
- processes new commands even during a move
- 8 general purpose in-/output lines
- up to 255 devices cascadeable, also compatible with the whole control familiy
- all commands from the computer pass through with a delay of only 29µs plus send time of one character, while no motor is running
- 128 bytes communication buffer
- RS232 interface, 8 databits, no parity, one stopbit
- supported baudrates: 115.2; 57.6; 38.4; 19.2; 9.6; 4.8; 2.4 and 1.2 kbps
- line end character: CR; other possible, please send me a mail
- LED shows activity
- low cost, low part count
- Labview driver supports relative and absolute move in "real word" units, multiple axes, home search, setting of parameters, read and write of the GPIO
- Program is freeware for non-commercial use.
Serial Interface
The device utilizes a 8051 and one or two driver chips (depending on configuration) to allow the user to control a bipolar stepper motor via RS232. All commands from the PC are passed through. If the device receives a command with it own address, it will also react as required. Messages from the controller are sent with its own address first and then followed by the data in hex-code (nibble by nibble from msb to lsb). All commands end with a line end character. This is normally CR. Address and line end character can be changed easily, just send me a mail with your demands. The LED will be on after power-up. After each correct command it will toggle between on and off. If a buffer overflow occurs, the LED will stay permanently off and the MCU is stopped.
Motion Control
Sequences of Move Commands
The steps of master move commands, which are received while another move command is executed, are all added up and executed when the older command is finished. In case you mix different step patterns (full/half/quarter - step), all steps will be executed using the stepping pattern of the last command. The number of accumulated steps may not extend 16.7M steps, or the accumulator will overflow.
Master Salve Connections and Commands
Slave move commands, which are received while another move command is executed, are ignored. A slave command which is waiting for a master pulse, can be replaced by sending any other move command. To link multiple axis, connect the corresponding /SyncMaster and /SyncSlave pins. The start of the movement is then synchron within a less then 1µs.
Limit Switches
If CWLimit is high, motion in the clockwise direction is stoped, if CCWLimit is high, motion in the counterclockwise direction is stoped.
Parameter Calculation
The maximum stepping frequency in Hertz reached for a motion longer than 4*f_stmax is given as:
f_stmax [Hz] = f_xtal / {12 * Acc * int(255 * [sqrt(f_stmax+1) - sqrt(f_stmax)])}
The function int() means here, that all decimal digits are cut off: e.g. int(7.95)=7
For the default values we get: f_stmax = 22118400 / {12 * 160 * int( 255 * [sqrt(256) - sqrt(255)])} = 1646 Hz
The minimum stepping frequency in Hertz at the first / last step is given as:
f_stmax [Hz] = f_xtal / {12 * Acc * 255}
For the default values we get: f_stmax = 22118400 / {12 * 160 * 255} = 45.18 Hz
If you want to calculate your own parameters, you normally set only Acc. f_stmax is left at 255, exept if you need to optimize vibrations during the very beginning and end of a movement. The correct values depend on the properties of the motor, the mechanical setup, driver supply voltage and operation mode:
Acc = f_xtal / {12 * int( 255 * [sqrt(256) - sqrt(255)]) * f_stmax [Hz]}
Acc = f_xtal / {84 * f_stmax [Hz]}
For information on the internal operation of a microcontroller stepper motor controller read AN155 from Silicon Laboratories.
Hold Current Control
General Instructions, No Hold Current
The hold jumper is used to switch off the hold current through the motor coils, while the motor stands still. A closed jumper corresponds to no hold current. The jumper is read after every movement. During power-up the level of /enable and enable is read. If both are low, a high on the hold pin drives the outputs for the motor driver high, while the motor stands still. This is particular useful for driver chips like PBL3717A which have no enable input.
If you want to control the hold pin via RS232 you could use a GPIO pin. There is no direct control of this feature via software, because in some applications the motor might be driven with a higher current than allowed for infinite time because of too high power dissipation. Since in this case wrong settings might damage the motors this option is normally not accessible via RS232.
Reduced Hold Current
Incase the position must be kept after a movement, but the friction in the system is not high enough to ensure this, a reduced current is most likely still sufficent to fix the position. This way power disipation can be reduced drasticly. The two following methods can be combined. Note, that potential enable pins of the driver chips must be pulled to V_logic and /enable pins to ground, but not controlled by the MCU.
Change current sensing
Required are two additional resistors, two CMOS switches (e.g. 2/4 74HC4066), and a driver chip with a seperate comperator input. The switch is controlled by the enable output of the MCU. The following circuit as to be implemented once for each winding:
(GND)---[R_shunt]---(Power output of driver)---[1k]---(Comperator input of driver)---[470]---(74HC4066)---(GND)
For PBL3717A driver this leads to a 4-fold increase of the driving current.
Change reference voltage I
Required are two additional resistors and a driver chip with a seperate reference input:
(+5V)---[1k]---(Reference input of driver)---[180]---(enable Pin of MCU)
For PBL3717A driver this leads to a 4-fold reduction of the hold current.
Change reference voltage II
Required is one additional resistor, one CMOS switch (e.g. 1/4 74HC4066) and a driver chip with a seperate reference input. The switch is controlled by the enable output of the MCU:
(+5V)---[27k]---(Reference input of driver)---(74HC4066)---(+5V)
For PBL3717A driver this leads to a 4-fold reduction of the hold current.
General Purpose Input Output
The GPIO lines are located at P1 of the MCU. They are open collector outputs with a weak pull-up resistor and contain also a circuit for read back. Refer to the microcontroller datasheet for details. The state of the GPIO after reset is high. Note that you need to write an one to a GPIO before it is possible to use it as an input, if it has been used as an output since the last reset.
Daisy Chaining of Devices
Devices can be put in a chain. Some components maybe saved if all MCUs and drivers reside in one case:
Clock Disribution: If the distance between the MCUs is within the range of a view centimeters, only one crystal is needed. Connect Xtal2 of one MCU to Xtal1 of another without a crystal.
Reset: MCUs can share a common reset capacitor. The value increases by 1µF for each controller.
RS232 Interface: In between MCUs the interface chip (e.g. MAX232) can be ommited. Connect TxD of one MCU to RxD of another directly.
Power Supply: As the number of MCUs increases, power consumption of the digital part increases as well. Depending on the driving voltage for the motor and the number of MCUs a switching regulator (e.g. LM2575-5) might be more appropriate, than a linear voltage regulator (e.g. 7805).
Example schematic with the interconnections only!
Labview Driver
The Labview driver offers the following functions:
High Level Functions
- Configuration
- ST2pInitCom: Setup communication port (configure serial port via the measurement and automation explorer)
- ST2pSetParameters: Setup parameters for motion profile (acceleration and maximum stepping frequency), calculates maximum speed reached during motion, may not be executed while a movement is performed
- ST2pHome: Performs home search
- Operation
- ST2pMoveAbs: Moves to an absolute position
- ST2pMoveRel: Moves to a relative position
- ST2pMoveAbsAxis: Moves to an absolute position on system with multiple axes
- ST2pMoveRelAxis: Moves to a relative position on system with multiple axes
- ST2pRotRel: Rotate to a relative angle
- ST2pRotRel2: Rotate for a defined time. Note that the speed input is not an independent parameter, but should be connected to the speed output of ST2pSetParameters. The direction is selected by the sign of the time input.
- ST2pWait4Move: Waits until movement is finished
- ST2pSoftStop: Terminates movement with decceleration, output of not executed steps, but the absolute position is not corrected
- ST2pReadGPIO: Reads GPIO
- ST2pWriteGPIO: Write GPIO
These vis take care of the low level comunication with the controller, provide some kind of error dedection and convert "real word units" (e.g. degree and millimeter) to steps. The move commands take into account the finite resolution of stepper motors. Controller Address, VISA Instrument Name, error cluster, scaling (in steps per "real world unit"), stepping mode and absolute postion (in "real wolrd units") are transfered form one vi to another by a cluster. See examples for details!
Low Level Functions
- ST2pCheck: Read the state of the controller, see command 8 for decoding of the output
- ST2pCommand: Sends a command to the controller
- ST2pRead: Reads data from the controller
- ST2pSnapShot: Support for ST2pHome
- ST2pMove2RefSW: Support for ST2pHome
Labview Example Programs
The following examples illustrate, ...
SetPos.vi
... how to do a home search and then move to a certain position. Preconfigured for a P40X.X2S translation stage from PI.
XYscan.vi
... how to handle two axes on one serial port. Uses home search and different move operations. Preconfigured for a P40X.X2S translation stage from PI.
SetRot.vi
... how to move a stepper motor by a defined angle.
SetRot2.vi
... how to move a stepper motor for a defined time.
Labview Driver - using multiple axes on a single serial port
It is possible to operate many motors on one single serial port. One has differentiate between mixed and uniform systems:
Uniform Systems
In these systems all stepper motors share the same operational mode and the same scaling. Therefore the parameter cluster is shared by all stepper motors and only the absolute positions are kept in a seperate array. Use ST2pMoveAbsAxis and ST2pMoveRelAxis for any movement. These functions feature a seperate input to select the controller. For all other commands the corresponding address in the parameter cluster has to be set first. Refer to the XYscan example for more information on the usage of an uniform system!
Mixed Systems
In these systems stepper motors may process different operational modi and / or different scalings. Therefore the parameter cluster cannot be shared by all stepper motors. The user has to take care to set the appropriate operational mode and scaling for each stepper motor before applying any command.
The user is encouraged to write an appropriate hardware abstraction layer.
The settings send by ST2pSetParameter (Acc and f_stmax) are kept directly on the controller and are therefore not affected by the details of the setup.
| Command No | Mode And Direction | Steps | Addtional Response | Description
|
|---|
| 0 |
| Value | Mode / Direction
|
|---|
| 0 | full step, clockwise
| | 1 | full step, counterclockwise
| | 2 | half step, clockwise
| | 3 | half step, counterclockwise
| | 4 | quarter step, clockwise
| | 5 | quarter step, counterclockwise
| | 6 | quarter step, clockwise
| | 7 | quarter step, counterclockwise
| | 8 to F | same as 0 to 7 with pulse on /SyncMaster
|
| Value: 0H to 0FFFFFFH Units: full/half/quarter steps depending on mode | none | Move motor with given mode and direction the number of steps as a master.
|
| 1 | same as command no 0, mode 0 to 7
| Move motor with given mode and direction the number of steps as a slave.
|
| 2 | dummy | Maximum stepping frequency = f_stmax Value: 0H to 0FFH default: 0FFH | none | It is important to set this parameters to obtain optimum performance (fast vibration-free movement without loss of steps).
|
| 3 | dummy | Acceleration = acc Value: 0FH to 0FFH default: 0A0H | none
|
| 4 | dummy | Lower byte is writen to GPIO | none | Write to GPIO. To pins which are used as inputs, only ones should be written.
|
| 5 | dummy | dummy | Device Address, two digit hex-number, line end character | Read GPIO.
|
| 6 | dummy | dummy | Device Address, six digit hex-number, line end character | The "steps to do register" is snapshot at the low transition of IE0 and send. Qued moves are not included. May intruduce a phase lag as small as 11 µs in the stepping pattern.
|
| 7 | dummy | dummy | Device Address, one digit hex-number, line end character | Do home search, the response will be zero if the reference switch was found to be implemented, the labview driver has a host based subroutine for this task, which does not relay on this command
|
| 8 | dummy | dummy | Device Address, one digit hex-number, line end character |
The response will be a hex-number with the bits of the corresponding set, if the signals are active.
| Bit | Signal
|
|---|
| 0 | motor moving
| | 1 | reference switch
| | 2 | CWLimit
| | 3 | CCWLimit
|
|
| 9 | dummy | dummy | Device Address, one digit hex-number, line end | Version of the software
|
| A | dummy | Stop mode Value: 0H to 0FFFFFFH
| LSB | Stop Mode
|
|---|
| 0 | stop at an instant
| | >0 | deccelerate
| | MSB | Step Accumulator
|
|---|
| 0 | clear
| | >0 | keep
|
| Device Address, six digit hex-number, line end character | Terminate movement and send remaining steps. Qued moves are not included. Cancels any active snapshot command. May intruduce a phase lag as small as 16 µs in the stepping pattern.
|
Baudrate Selection
| MSB - LSB | Baudrate / kbps
|
|---|
| 111 | 115.2
|
| 110 | 57.6
|
| 101 | 38.4
|
| 100 | 19.2
|
| 011 | 9.6
|
| 010 | 4.8
|
| 001 | 2.4
|
| 000 | 1.2
|
Meaning of 1 and 0 in this table:
The baudrate jumper are read up on reset.
- Semiconductors:
- 1 AT89C52 or AT89S52, 24MHz; see also programming tips
- 1 MAX232
- 1 set of drivers, see below
- 1 78L05
- 1 low current LED
Capacitors:
- 1 1µF / 25V axial
- 6 10µF / 25V axial
- 2 33pF cer
- 3 100nF cer
Resistors:
- 2 4,7k*8 / 9 pin sil array
- 1 1k
Mechanic:
- 1 22.1184MHz crystal
- 2 sub-D socket, 9 pin
- 1 dip switch with 4 switches
- 1 case
- 1 pbc
- 1 some thin wire
- 1 socket 16 pin
- 1 socket 40 pin
- 1 loop back plug (9 pin plug with only pin 2 and 3 connected to each other) for the last controller in a chain only
| Type | no. of chips | max. current | max. voltage | inhibit polarity | comment
|
|---|
| TCA3727 | 1 | 0,75A | 50V | P0.6 | temperature prealarm via inhibit and GPIO possible, no gitch filter for current sensing possible: Do not use, if the motor is connected via a long cabel!
|
| UDN2916 | 1 | 0,75A | 45V | pull enable and /enable to ground to enable hold on/off |
|
| UDN2917 | 1 | 1,5A | 45V | P0.7 | obsolete
|
| PBL3717 | 2 | 1A | 46V | pull enable and /enable to ground to enable hold on/off |
|
| TEA3717 | 2 | 0,8A | 45V | pull enable and /enable to ground to enable hold on/off |
|
| TEA3718 | 2 | 1,2A | 50V | pull enable and /enable to ground to enable hold on/off | temperature prealarm and alarm via GPIO possible
|
| LMD18245 | 2 | 3A | 55V | P0.7 (connect to brake) or pull enable and /enable to ground to enable hold on/off |
|
see Stepper Driver Connection Schemes for more information
| Type | Manufactor | Max. Current | Driver IC | R Shunt | U Driver | Parameters | Resolution | Comment
|
|---|
Stepper Motor QSH2818-32 | Trinamic | 0,67A | 2* PBL3717A | 0.6 Ohm | 24V | max. speed = 4635°/s = 5150 half steps/s f_stmax = 255 Acc = 51, but runs also with Acc = 32 (depending on load) HomeAcc = 255 RefSWtoMaxPos = 380 SnapShotMove = 190 (for a 50mm disk as a load) | 0.9° 1.11111 half steps/° | Due to the relatively low inductance and the high current, proper wiring and EMI prevention is required.
|
Translation Stages all M40X.X2S (Stepper) versions like M-403.12S | PI | 0,3A | 2* PBL3717A | 1.5 Ohm | 24V | max. speed = 3mm/s = 2400 quarter steps/s f_stmax = 255 Acc = 110, but runs also with Acc = 80 (depending on load) RefSWtoMaxPos = 20 (for 25mm stage) SnapShotMove = 3 | 1.25µm 800 quarter steps/mm | use a 74LS14 to invert limit switch signals
|
Rotation Stage PR50PP | Newport | 0,18A | 2* PBL3717A | 2.2 Ohm | 24V | max. speed = 20°/s = 1993 half steps/s f_stmax = 255 Acc = 134 RefSWtoMaxPos = 380 AnapShotMove = 30 | 0.01° 99.65928 half steps/° | adjust parameters, depending on load, device and driver |
The part description in schematics is read as follows:
part type + value in exponential form + package description + subpart number in package
for example: C1040805,1 means Capacitor, 100nF, package SMD 0805, first subpart in package
Disclaimer: No warranty at all!
Copyright by Martin Clausen, Germany.
Contact the author: mc AT rotgradpsi DOT de
Impressum