Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

SN74410 H-Bridge Driver

The SN754410 H-bridge driver is connected to a bipolar stepper motor with a PIC18F248 microcontroller. The various stepper motor modes (wave, half-step, full-step) are demonstrated/coded.

A stepper motor has widely varying uses because the various ways the device can be driven and the inherent compatibility with digital control/systems. Stepper motors find application from CNC machines through to robots and toy vehicles etc, i.e. anything that needs rotational movement (particularly in measurement and control applications). For example, the DIY spectrophotometer project requires a stepper motor to position the diffraction grating to provide "monochromatic" light for chemical analysis of hydroponic nutrient solutions. A Microchip application note (1) lists the following features of stepper motors that are desirable in many applications

    • Stepper motors are brushless (more reliable, don't create sparks/arcs)
    • Rotate at set speed regardless of load (as long as load less than motor torque rating)
    • Open loop positioning - as long as within torque specs, don't need position feedback mechanism/circuit
    • Can hold the rotating shaft stationary if required
    • Fast start-up, stopping and reverse motion possible

A stepper motor requires a set pattern of input currents to the various terminals in order to produce an individual discrete movement (i.e a "step"). A series of these input current patterns producing a set of discrete current pulses then in turn enables rotational movement of desired speed, direction and or magnitude. While a microcontroller could possibly be used to control a stepper motor directly, with some discrete circuitry to handle the required currents (2), generally specifically designed IC's that incorporate the necessary H-Bridge/switching circuitry are used, which in turn receive control inputs from a microcontroller.

There are numerous H-Bridge driver IC's but the SN754410 (leaving aside microstepping drivers) has a number of desirable characteristics listed below from the datasheet, and since it is widely used, therefore inexpensively available even in small quantities:

    • Quadruple drivers on single chip, 1A output current capability/driver
    • Wide supply voltage (4.5-36V) with seperate input-logic supply
    • Diode clamped inputs, thermal shutdown, internal ESD protection

Stepper motors can be either unipolar or bipolar and can be connected/wired in various ways (3). A bipolar stepper motor (scrounged from an old printer) was used in this case. A PIC18F248 was used to produce the timing/control signals. The PIC18F248 was used because it was already on the DIY PIC Development Board (only require a spare output port with four pins available and preferrably a timer/interrupt).

The following sections describe the circuit connections and CCS C code for wave, half-step, and full-step operation of the stepper motor (with some simple testing of performance in terms of angular position and torque).

The schematic for the SN754410 with connections to the PIC18F248 is given in the Schematics Section below. The ancillary circuitry for the PIC18F248 also includes connection via RS232 to a PC (enables PC control of motor speed and direction). For initial testing, a SPST momentary button (with some switch debounce circuitry) is used to signal individual steps to the stepper motor.

Power Supply

A typical "wall-wart" power-supply is used (a surplus laptop charger in this case) in conjunction with a voltage regulator (LM317T) to provide the regulated 5V required by the PIC microcontroller. Since the stepper motor was only being controlled for test purposes (i.e. check circuit connections and software code) a seperate motor voltage source was not used (which would have allowed higher currents/voltages producing more torque etc if required by the particular application).

Circuit Operation

The internal workings/operation of a stepper motor are detailed in numerous references, the Microchip application note is a good starting point if required (1). The minimum understanding required is that a stepper motor has various windings that need to be energised in a set pattern to produce a varying magnetic field that interacts with the rotor shaft to produce movement in discrete steps. The direction the current is feed into the stepper motor windings is important, as magnetic fields of opposite direction need to be produced in sequence. Therefore, circuitry to allow current to flow in either direction across the stepper motor windings as required is necessary. This is generally a H-bridge arrangement. Again, the operation of a H-bridge circuit is detailed in numerous references, for example here (4). The SN754410 contains four half H-bridge drivers, which means a single SN754410 can control a bipolar stepper motor.

Figure 1 below, based on (5), summarises the connection of the PIC microcontroller to the SN754410 H-bridge driver and in turn to the bipolar stepper motor. Four control signals (the SN754410 also has enable pins that can be used to enable/disable pairs of H-bridge drivers, if this was desired, an additional two control pins from the PIC would be required) from the PIC microcontroller control which outputs of the SN754410 will be energised. The outputs from the SN754410 then determine the current flow and direction within the stepper motor windings. This arrangement allows logic level signals (5V and a few mA) to control appropriate currents/voltage to the stepper motor. Sending the appropriate pattern of control signals from the PIC microcontroller, the stepper motor can be rotated in the desired direction/speed and or held at a particular position.

  • Figure 1: Stepper Motor Connection via SN754410 and PIC microcontroller

    Stepper Motor Connection DiagramStepper Motor Connection Diagram

    Silver Membership registration gives access to full resolution schematic diagrams.

    Figure 1: Stepper Motor Connection via SN754410 and PIC microcontroller

There are three possible "appropriate patterns" (ignoring microstepping as such) with which the PIC microcontroller can control the stepper motor via the SN754410. These are called wave drive, full step (or two phase) drive and half-step drive which are summarised on the following diagram (based on (6)). Wave drive has the lowest torque but could have utility if only very low power was required/available. Full step drive is the normal sequence for a bipolar motor and has the highest torque. Whereas, half-step has the benefit of giving a better effective step angle, but with the disadvantage of uneven torque. Stepper motor direction is simply reversed by sending the sequences in reverse order. Stepper motor speed is determined by the frequency with which the sequence is clocked to the SN754410.

  • Figure 2: Bipolar Stepper Motor Drive Sequences

    Bipolar Stepper Motor Drive SequencesBipolar Stepper Motor Drive Sequences

    Silver Membership registration gives access to full resolution schematic diagrams.

    Figure 2: Bipolar Stepper Motor Drive Sequences

Software/Firmware

The required firmware is relatively straight forward. An array is defined to store the bit patterns corresponding to the various sequences required by the type of drive being used (wave, full-step or half-step). The value (i.e. bit pattern) from an element in the array is placed into one of the output ports of the PIC microcontroller that is physically connected to the SN754410. This instructs the SN754410 to energise the stepper motor coils appropriately.

Therefore, in order to make the stepper motor move, the value from the elements in the array just need to be placed onto the output port in succession. Reversing the order in which the values are output reverses the direction of the stepper motor. Increasing and or decreasing the frequency with which the values are output controls the rotation speed.

One item of note is the use of the modulus (%) function e.g, "currentStep=(currentStep+1) % 4;" in the code. This is just a method for conveniently ensuring that the array "loops around" to the start, and therefore produces a continuous sequential pattern for driving the stepper motor. The "index variable" (the variable "currentStep" in the code fragment) stores the current position within the drive stepping pattern array. A seperate variable could be used in conjunction with this to record the current angular position (in this particular case, each step of the stepper motor was 0.9o).

The remainder of the code in the code fragment below deals with "button debouncing" and not involved per se with stepper motor control. A SPST momentary contact button was used as a convenient/easy method for signalling when a step of the stepper motor should be performed.


    #include <spectro.h>
    
    #zero_ram             //all variables automatically initialised to 0
    #define LEDred PIN_A0 //visually show PIC operating   
    int8 mode_button;     //for button debouncing     
    
    void main() {
       int16 debounceCount;
       //comment out motorStep[] definition as appropriate 
       int motorSteps[4] = {0x0A,0x02,0x04,0x01};   //wave drive
       //int motorSteps[4] = {0x0A,0x06,0x05,0x09}; //full step drive
       //int motorSteps[8] = {0x0A,0x02,0x06,0x04,0x05,0x01,0x09,0x08}; //half-step drive
       int currentStep;
       
       output_high(LEDred); //turn on Red LED to indicate PIC program running
    
       output_c(motorSteps[currentStep]); //energise stepper motor to 1st step position
       delay_ms(1000); //wait for circuit to settle (avoids problems with debounce)    
       
       while(TRUE){ 
          if (debounceCount == 0){ 
             if (mode_button) {// button has been previously pressed on 
                if (!input_state(PIN_B1)) {  
                   mode_button = 0; //clear previous pressed on state      
                }
             } else { 
                if (input_state(PIN_B1)) { //check if PIN_B1 pressed on
                   mode_button = 1 ; //1=down
                }
             }
          }
          if (mode_button) {
             delay_ms(100); //give time for stepper motor to complete the step
              //currentStep=(currentStep+1) % 8; //for half-step drive
             currentStep=(currentStep+1) % 4; //for wave and full-step drive
             output_c(motorSteps[currentStep]);  
          }
       }
    }                 
   	

Note: Image loading can be slow depending on server load.

  • SN754410 Basic Interface SchematicSN754410 Basic Interface Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    SN754410 Basic Interface Schematic

See the Construction Notes/Trouble Shooting Section about the possible need for external flyback protection diodes, which are not indicated on the above schematic.

This project did not require a PCB.

The construction was done using prototyping board. See the photographs and schematic diagram sections.

Qty Schematic Part-Reference Value Notes/Datasheet
Resistors
3R110K1/4W, 10% 
Diodes
1D11N4002
Integrated Circuits
1U1PIC18F248PIC microcontroller datasheet
1U27805Linear Voltage Regulator  datasheet
1U3SN754410Quad half-H bridge driver datasheet
1U440106Hex Schmitt Trigger datasheet
1U5MAX232ERS232 Driver/Receiver datasheet
Capacitors
2C1,C222pFceramic disk
1C30.33uFaluminium or tantalum electrolytic
1C40.1uFaluminium or tantalum electrolytic
5C5-C91uFaluminium or tantalum electrolytic
2C10,C1110uFaluminium or tantalum electrolytic
Miscellaneous
1J1CONN-H55-pin connector for ICSP
1P1CONN9-pin connector for RS232
1SW1SW-SPDT 
1X110MHzCrystal Oscillator
Description Downloads
SB754410 H-Bridge - Bill of Materials Text File Download

Some basic testing was performed checking the operation of the hardware/firmware controlling the rotation of the stepper motor. This involved checking angular change in response to the instructed number of steps to be performed, and a rudimentary check of torque versus voltage and type of stepper motor drive waveform. The stepper motor used was scrounged from a disused printer and was labelled as manufactured by Shinano Kenshi, model STH-39C013, 0.9o step and 21ohm. However, I could not find further specifications.

The stepper motor was temporarily mounted "vertically" to enable the desired testing (see Photographs Section). A coupling was made to enable connection of a pointer (from an old Alan (hex) Key) to the motor shaft. This pointer was also used as the lever for the torque testing. A circular "face plate" was constructed with markings at various angles. This enabled visual determination of the angular distance moved by the motor shaft/pointer in relation to the number of commanded steps to be performed.

Using wave and full-step drive sequences, the stepper motor moved 0.9o as per the specifications label. The half-step drive sequence produced the expected 0.45o/step.

Some simple holding torque tests were performed by increasing the weight being suspended on the stepper motor/lever arm until the stepper motor failed to hold the weight. The following graph presents the results of this testing which examined holding torque versus drive waveform and applied motor voltage. As expected, the full-step waveform provided more torque (~35%) than the wave drive sequence. And again as expected, increased applied motor voltage (hence current) produced higher holding torque.

  • Graph 1: Stepper Motor Torque Test Graph

    Stepper Motor Torque Test GraphStepper Motor Torque Test Graph

    Silver Membership registration gives access to full resolution schematic diagrams.

    Stepper Motor Torque Test Graph

Since no specifications where available for the model STH-39C013, difficult to assess the actual magnitude of the holding torque observed (although appears to be low compared to other bipolar motors available on ebay that appear to be the same physical size). The observed current (0.2A @ 6V, 0.34A @ 10V)) during the holding torque testing and known applied motor voltage enabled calculation of motor winding resistance (~30ohm) which compares to the 21 ohm specified on the motor label.

This project only tested the SN754410 to the breadboard stage. Some potentially relevant learnings involve how to determine the type of stepper motor, if scrounged from disused equipment, and the use of external clamping diodes.

Determining Stepper Motor Type

The following information is copied from National Instruments (7)

Some stepper motors have a motor case ground that can be tied to the ground of the system. It is usually a black wire, and it will add one additional wire to the overall count (4 coil wires + 1 casing ground = 5 wires total).

If there are four coil wires from the stepper motor, using a multimeter:

    • Each of the two phases should have the same resistance when measured with a multimeter. When measuring the resistance across one wire from each of the two phases, the resistance should be infinite because the circuit is open. Locate the two pairs of wires that represent the two phases; both pairs of wires will have similar internal resistance.
    • Connect each phase to the driver and ignore the polarity (+ / -), for now. You have a 50 percent chance of guessing right.
    • Send a command to move the motor. If the motor rotates in the wrong direction, then switch either phase A and A- or B and B- (effectively reversing directions).

If there are six coil wires, then each phase has a center tap wire: The center tap wire should have half the internal resistance of the full phase. The easiest option is to use a multimeter to find the two pairs of wires that have the maximum resistance. Connect each phase to the driver, and ignore the polarity (+ / -) for now. You have a 50 percent chance of guessing right. The motor should rotate, and if it is in the opposite direction, then switch either phase A and A- or B and B- (effectively reversing directions).

If there are eight coil wires, then it is highly recommended you find the exact pinout for the motor. The eight wires represent four pairs of wires, and each pair has the same resistance. It is not easy to find what two pairs represent phase A and phase B without dismantling the motor.

Internal/External Clamping Diodes

From the datasheet, internal diodes exist on the outputs of the SN754410. The SN754410 when connected places these across the stepper motor windings (i.e. inductive load) which can act as flyback diodes, meant to protect the circuitry from voltage spikes. However, based on the application circuit on page 6 of the datasheet, it appears that external diodes are needed. There are many references that indicate that the internal diodes on the SN754410 are only to be used for electrostatic discharge (8), even though they may work as flyback diodes. It is reported (9) "After careful reading of the datasheet and discussion with TI tech support and power engineers it appears that the output diodes were designed for ESD protection only and that using them as [flyback]-protection is a hack and not guaranteed for performance".

The testing performed on the small model STH-39C013 stepper motor reported here did not use external flyback protection diodes, without any apparent problems. However, with larger stepper motors (and higher voltage/currents) the external diodes are probably warranted (and in the DIY situation, the cost of a few additional diodes is minimial compared to damaging a stepper motor).

ref001: http://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en012151

ref002: http://en.wikipedia.org/wiki/H_bridge

ref003: http://www.piclist.com/techref/io/stepper/connections.htm

ref004: http://www.dprg.org/tutorials/1998-04a/

ref005: http://www.freescale.com/files/microcontrollers/doc/app_note/AN2974.pdf

ref006: http://www.engr.mun.ca/~fifield/eng1040/Mechanical/Stepper_Motors.pdf

ref007: //digital.ni.com/public.nsf/allkb/0AEE7B9AD4B3E04186256ACE005D833B

ref008: http://www.picaxeforum.co.uk/showthread.php?22664-L293D-driver-and-SN754410-substitution

ref009: http://www.ladyada.net/make/mshield/use.html

Comments/Questions

No comments yet.

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with correct Membership Level can download.


Membership starts at only $2, so join now!