Unipolar Stepper Motor Driver
Synopsis
The purpose of this project was to develop a stepper motor driver for 2-phase unipolar stepper motors that has built in current control. The eventual target project for this driver is for my CNC milling machine that I am currently planning out. This needs a few elements that are combined to provide a full driver.- Firstly a method of providing the required coil sequencing to step the motor backwards and forwards.
- Once this is established the current being supplied to the motor coils needs to be limitted in some way to stop melting anything... The obvious option here is to use a chopper circuit.
- Once the driver is up and running a power supply needs to be built to cope with the current the motors require.
- Finally an intelligent controller is required to provide the correct number of steps for a required distance of travel. Many simply use a PC parallel port for this on CNC projects but I want this to be more of a stand-alone driver that can be used for other things. Ideally I will include ethernet control so that I can run the CNC machine remotely from the comfort of my living room instead of the cold garage and negates the need for a dedicated control PC.
The device
The device is based around an L297 driver IC that performs the translation step (ie takes clock and direction input and generates the correct output sequence for driving the stepper) and has current limitting abilities. Additional logic and driver circuitry is then added to drive the motor coils. Each motor driver is fully independant of the other drives and is controlled with its own clock and direction signals, has a seperate current limitter setting and should not interfere with each other.- Circuit diagram
C7, C8 and C10 provide PSU filtering.
R1 and R2 set the output voltage of the LM317 regulator.
R6 (variable) and C1 set the chopper frequency.
R11 is a pull-up for the direction line to ensure it stays 'stable'.
R4 and C6 provide a filter for the direction line.
R10 and C2 provide a filter for the pulse line.
R12 is a pull-down to disable the outputs until set high.
R3 pulls H/F up so it can be toggled on or off easily by JP1.
R14 and R8 (variable) set the VRef reference voltage that determines the motor current.
C3 gives some voltage stability to the reference voltage.
C4 and C5 provide filters for the current sense lines.
R9 and R10 reduce current flowing from the sense resistors to the L297.
R7 and R13 are the sense resistors used to measure the current flowing through the motor coils. - The finished product photos will be added soon
Development choices, tips and debugging
In reaching this final solution I went through many designs, some of my own, some through various searches on the net. The final design is a combination of a few of the most common designs that can be found on the internet. One useful site I used is http://www.pminmo.com/ there are some good designs of stepper drivers and also a bulletin board where people share experiences and the owner gives great help. A good resource for describing stepper motors is Jones on Stepping MotorsFET choice
The FETs must be chosen to allow the switching of each coil in the motor at full current. They must also be able to cope with the inductive EMF spike generated by the motor that could otherwise destroy the FET. Some circuits show diodes being used to help control this spike and protect the FET, however in my experiments they caused more problems than they solved and generated a lot of heat. My circuit solution is simply to use FETs that are rated high enough to cope with this spike without the diode. Approximetly I have spec'd this as around 4 times the supply voltage, however there may be a better calculation to work out the exact requirement.The next thing to consider is the logic level that will be used to turn the FETs on/off, referred to as Vgs (voltage across the gate-source junction). In practice Vgs = Vcc - Vsense. ie The voltage across the FET gate is the supply voltage less the voltage across the sense resistor. The voltage across the sense resistor must therefore be controlled/limitted and the FET spec'd to work with 'what is left'. The sense resistor voltage is limitted by the L297 device by means of the current limitting circuitry. When Vsense (voltage across the sense resistor) reaches the reference voltage into the L297 Vref pin the inhibit output lines drop, in turn switching off the FETs and dropping Vsense. This sequence repeats giving an oscillating voltage across the sense resistor, this is known as the chopper action. In practise when measuring this 'chopped' voltage the reading is approx 2/3 of Vref, but for our calculations (giving us some VAT) it is best to use Vref itself in the calculations. So re-writing the previous formula:
Vgs = Vcc - Vref.
We set Vref between 0-1V and use a supply voltage of 5V for the logic.
So Vgs = 5 - 1 = 4V.
Now we need to refer to the datasheet of our FET and look at the Vgs vs Ids graph and ensure that when Vgs=4V the graph is not in its linear section (ie it has levelled out) and is therefore fully switched on. This will give us the best possible performance out of the FET. Note that some FETs do not switch on fully until Vgs >= 5/6/7 volts. Be careful in choosing different FETs paying attention to this specification.
After trying a few different models I eventually chose to use the IRL640 FETs as they performed the best and matched all of my required specifications. They have a Vds of 200V, meaning they should cope well with the inductive motor spike without needing diodes and a Ids of 17A, which is more than enough for the steppers motors I will ever use. These come in a TO220 package so are easy to mount and heatsink.
Misc circuit choices and information
The clock and direction pins use RC filters to help to stop interference giving invalid clocks to the L297. Although the exact resistor and capacitor values are not critically important they must not limit the step rate required for our maximum clock speed. The max allowed frequency to pass through the filter ist=RC. The L297 needs a step width of 500nS to operate, therefore we do not want to stop pulses greater than this. Choosing to allow steps of 200nS (ie 0.0002 seconds) through will give us a maximum clock speed of 5kHz. This will allow most steppers to reach top speed. Therefore R*C (R in KOhm, C in pF) will give us the actual pulse width allowed (in nS). Therefore a 2.2K resistor and a 100pF capacitor provides a reasonable filter.
The sense resistors should be metal film type and not wirewound, as the inductive properties of the wirewound resistors add additional complication and do not work as well as non-inductive types.
The ideal chopper frequency for the driver needs to be set for the motor being used, too high or too low a frequency can cause audible noises/buzzes and/or run the motors hot.
Always ensure the FETs are heatsinked, even if they don't get hot it is not worth risking. Be aware though that most FETs (including the IRL640's) have the tab as the drain and need to be isolated from the other FETs tabs. This means that they either need seperate heatsinks that do not touch each other, or a common heatsink with isolating mounts.
Current calculations
Setting the values for the sense resistors is perhaps the only main change to the circuit design that will be needed based on the motor being used. The calculation we will use is Motor currentImax = Vref / Rsense. We ideally want to limit the current for the motor to its maximum when Vref is at its maximum, therefore we cannot (in theory) damage the motor by turning Vref up too high. We have already stated that Vref should not exceed 1.0V, so we can simplify the calculation to Imax = 1 / Rsense or Rsense = 1 / Imax. So with a motor with a maximum current of 2A per coil, Rsense = 1 / 2 = 0.5 Ohms. The power then disapated through the resistor is Psense = Isense * Vsense. Vsense should not be greater than 1.0V, so taking this as a worst case maximum, Psense = Isense * 1 = Isense, so the power disapated is equal to the motor current value (in this case 2Watts). At this rating, ensure the resistors used are rated to this value, and expect them to get nice and warm! In practice you may find that a lower power rating is ok to use as you won't run the motor at full current and the voltage across the sense resistor doesn't actually reach Vref, but feel free to have a play. Cooling the resistors with a fan is not such a bad idea, and with some thought the same fan can cool the FET heatsink also.
Fault finding
The first thing to check in the event the motor is not behaving correctly is that the wiring is correct, check and double check each pin on the L297, 74AC08 and FETs. Once you are sure everything is correct, check for shorts across the board. Next switch on the power and check the supply voltage to each IC. Once this is done ensure the four LED's are switching as the clock line is pulsed, if not then there is something wrong with the L297/AND gate circuit side, to confirm remove the motor and if possible the motor supply voltage (leaving the logic level voltage on). These should follow this sequence:1001
1010
0110
0101
If this sequence is correct then check the FETs. Switch off the power and check the following using a multimeter:
Resistance measure:
Pin 1-2: should be nothing *(nothing)
Pin 2-3: should be approx 3 MegOhms *(2.5MOhms)
Pin 1-3: should be nothing *(100 Ohms)
Diode measurement setting:
Pin 1-2: should be nothing *(nothing)
Pin 2-3: should be 0.5V *(0.5V)
Pin 1-3: should be nothing *(0.1V)
*The values shown in brackets were measured from a blown (dead) device, although a blown device will not always show these values this is just one case.
Limitations
- The supply voltage should be no higher than approx 50V - I need to confirm the exact maximum voltage.
Future expansion and development
- The next stage of development is to include this design into an ethernet based 3-axis stepper motor controller. This then will be used to control my CNC miller.
- Once the 3-axis controller is complete and the CNC miller running I will produce some 'final' PCB boards for the drivers.
- Also a high current PSU needs to be built to drive all 3 motors (2A/phase 2-phase ON = 4A per motor. 4A * 3 = 12A).
