µ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.

Features

Usage of Device

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

    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

    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.

    Comand Structure

    Command NoMode And DirectionStepsAddtional ResponseDescription
    0
    ValueMode / Direction
    0full step, clockwise
    1full step, counterclockwise
    2half step, clockwise
    3half step, counterclockwise
    4quarter step, clockwise
    5quarter step, counterclockwise
    6quarter step, clockwise
    7quarter step, counterclockwise
    8 to Fsame as 0 to 7 with pulse on /SyncMaster
    Value: 0H to 0FFFFFFH
    Units: full/half/quarter steps depending on mode
    noneMove motor with given mode and direction the number of steps as a master.
    1same as command no 0, mode 0 to 7 Move motor with given mode and direction the number of steps as a slave.
    2dummyMaximum stepping frequency = f_stmax
    Value: 0H to 0FFH
    default: 0FFH
    noneIt is important to set this parameters to obtain optimum performance (fast vibration-free movement without loss of steps).
    3dummyAcceleration = acc
    Value: 0FH to 0FFH
    default: 0A0H
    none
    4dummyLower byte is writen to GPIOnoneWrite to GPIO.
    To pins which are used as inputs, only ones should be written.
    5dummydummyDevice Address, two digit hex-number, line end characterRead GPIO.
    6dummydummyDevice Address, six digit hex-number, line end characterThe "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.
    7dummydummyDevice Address, one digit hex-number, line end characterDo 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
    8dummydummyDevice 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.
    BitSignal
    0motor moving
    1reference switch
    2CWLimit
    3CCWLimit
    9dummydummyDevice Address, one digit hex-number, line endVersion of the software
    AdummyStop mode
    Value: 0H to 0FFFFFFH
    LSBStop Mode
    0stop at an instant
    >0deccelerate
    MSBStep Accumulator
    0clear
    >0keep
    Device Address, six digit hex-number, line end characterTerminate 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 - LSBBaudrate / kbps
    111115.2
    11057.6
    10138.4
    10019.2
    0119.6
    0104.8
    0012.4
    0001.2

    Meaning of 1 and 0 in this table:

    SignSwitch
    1closed
    0open

    The baudrate jumper are read up on reset.

    Parts

    Driver IC Recommendations

    Typeno. of chipsmax. currentmax. voltageinhibit polaritycomment
    TCA372710,75A50VP0.6temperature 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!
    UDN291610,75A45Vpull enable and /enable to ground to enable hold on/off 
    UDN291711,5A 45VP0.7obsolete
    PBL371721A 46Vpull enable and /enable to ground to enable hold on/off 
    TEA371720,8A 45Vpull enable and /enable to ground to enable hold on/off 
    TEA371821,2A 50Vpull enable and /enable to ground to enable hold on/offtemperature prealarm and alarm via GPIO possible
    LMD1824523A 55VP0.7 (connect to brake)
    or
    pull enable and /enable to ground to enable hold on/off
     

    see Stepper Driver Connection Schemes for more information

    Connecting Translation Stages and Rotary Stages

    TypeManufactorMax. CurrentDriver ICR ShuntU DriverParametersResolutionComment
    Stepper Motor
    QSH2818-32
    Trinamic0,67A2* PBL3717A0.6 Ohm24Vmax. 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
    PI0,3A2* PBL3717A1.5 Ohm24Vmax. 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
    Newport0,18A2* PBL3717A2.2 Ohm24Vmax. 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

    Download of Program and Circuit

    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