Stepper Motor Drive
Like many of my projects, the original aim gets off target by some other interesting pursuit. In this case, it was controlling a 24V power supply. I was thinking ahead toward an application where the power would be under computer control for safety reasons, so those thoughts crept into the project as well. Here's a set of slides that describe what I did. We'll start with that:
The L297 is the controller for the L298, which is just the H-bridge for the motor. The L297 only needs a few signals from the Arduino and they are at TTL logic levels, so this makes it easy. The PWM to control the motor speed is done on the L297. Check out the slide showing the motor board - the Home signal is an open collector output from the L297. You could add a pull-up resistor to the circuit board and use this as an input to tell you each time the motor returns to its initial coil initial state, which would give an indication of RPM. There is a current sensing resistor for each phase that is fed back to the L297 to constrain the coil current to a safe level and provide a way to back off the current when just holding a position. So the only two signals you have to worry about are the direction signal and the clock. The clock rate determines speed and is accomplished in the sketch with a digitalWrite HIGH and LOW with a short delay in between.
The rest of the project was to control a power supply's AC coming on with a relay and then bringing up the 24V supply up a controlled manner with another relay. You could add a safety circuit if anything went wrong to power down the system. The picture shows the backside of the moon for the motor board.
You could add more features by utilizing the Reset and Half/Full Step signals. The Reset signal when pulled low will reset the phases back to the index position. I'm not sure why you would want to do that, since the motor starts off in that position. But stepping from Full to Half could be very useful to speed up the motor and smooth out the run. The trade-off is holding torque once stopped. The thing to do would be to ramp up the speed after switching to full-steps and then ramp down to half=steps before a stop and go back into full steps to set the torque higher. My goal for this project was just to successfully build the motor controller board and understand how bipolar motors work. I won't belabor the fundamentals here, because there are hundreds of websites that do a great job of explaining that on the Internet.
Be sure to look at the spec sheets for the L297 and L298 chips. I keep a folder of the spec sheets for all the ICs I might use. They don't read well the first few glances, but after a while the subtuties of what's going on soaks in. I might caution that there are occasionally errors found in spec sheets that have been there for decades, but you can spot them and work around them. Trust your instincts and experiments to establish true behavior. This is where separate volt and amp meters come in handy and the occasional oscilloscope probing.