4 - Stepper Motors

Submitted by Webbot on July 10, 2008 - 11:22pm.

If you are unfamiliar with Stepper Motors then see my Stepper Motor tutorial http://www.societyofrobots.com/member_tutorials/node/120

 

This will show you how you can control each coil of a stepper motor and also introduces you to the different drive modes: wave, full-step, half-step etc and talks about the advantages/disadvantages of each mode. A working motor driver is disussed there. However: the draw back is that the above tutorial requires a large number of your I/O pins and it also requires your microcontroller to control these pins to create the required drivng mode. So, as a theoretical example, it helps you understand how the motors work but will refer you back to this page for a more 'practical' example.

 

Assuming that you now understand the difference between uni-polar and bi-polar motors, and the different drive/pulsing modes then lets see how we can improve the design.

 

Welcome to the L297 !!!!!!

 

The L297 chip is designed to make driving stepper motors easy! It allows us to remove the responsibility of coding the different outputs for the drive mode we want to use. This is GREAT as it means we can tell the L297 that we want to click the motor by another step- and the L297 is responsible for telling the motor how to do it. As we will see - the L297 can drive both bipolar and unipolar motors and so allows us (from the microcontroller end) to treat all stepper motors in the same way.

 

Check out this datasheet for the  L297

 

The L297 has its own oscillator (or heartbeat) so that it can generate all of the required drive modes. This is produced by a resistor and capacitor network (R3 and C1 in the later diagrams). Each L297 can drive a finite number of coils/motors and so additiomal L297s may be required if you need more motors - but they can all share the same oscillator. This can be done as follows: on the first (primary) chip connect the R3/C1 oscillator to pin 16 (as per diagram) - for other L297s connect their pin 16 to ground and their pin 1 to pin 1 of the primary chip.

 

Refering to the diagram you will note that pins 20 (RESET) and 10(ENABLE) have been tied high as it is doubtfulll you will want to waste further microcontroller pins to control them.

 

Pin 19 (H/F) allows you to choose whether the L297 will manipulate the output pins to produce Half step drive, or full step drive - ie it changes the sequence of the outputs.

 

Output pins A,B,C,D,INH1,INH2 are the output pins that send the correct drive mode signals to the motor driver logic.

 

 

This chip means you can forget about how to send pulses to the coils - it does it for you!

 

All you have to worry about are the two input pins:-

Pin 17 - determines if the motor rotates one way, or the other

Pin 18 - is the clock - each tick will move the motor by one step

 

NB This is very similar to my DC Motor tristate switch in that Pin 18 is a PWM accelerator pedal, and Pin 17 is forward or reverse. So now we can control DC Motors and/or stepper motors with the same microcontroller code !!

 

Chopper

Ok - so there is yet another cool thing about this chip. - it saves power !!

 

Going back to fundamentals - each coil in the stepper motor has a small resistance, and so requires a large current. But this current only moves the motor over a 'step' when other coils are energised at the appropriate time. Having moved a 'step' then any further current is 'a waste'. So think of it as - 'the motor requires a high current kick to move a step', but having done so then we can reduce the currrent to a minimum until the next 'kick'.

 

How is this done? Well, assume that you have a resistor in series with your motor. Since Volts=Amps x Resistance then the voltage is proportional to the current. So if we monitor this voltage (on pins 13 and 14) then we are monitoring the current through the motor coil. This voltage is called a sense voltage. When we ask the L297 to perform another step then: it applies voltage to the coils and as the current increases then so does the sensed voltage. This is compared against a reference voltage on pin 15.

 

When the current level triggers the "over current sense", the L297 goes into Chopper/PWM mode and adjusts the current to the maximum allowed (By Vref). It does so by modulating either the phase lines or the inhibit lines, depending on the logic level on Control (pin 11). Its a closed loop feedback system!! Since, at build time, we dont know what the value on pin 15 should be then its easiest to use a potentiometer/trimmer to allow us to adjust the value at runtime. This will then allow us to control the trade off between torque and power consumption.

 

Next we will look at practical circuits for both Bi-polar and Uni-polar Stepper motors.