Stepper motor control with the PIC

From Mech
Jump to navigationJump to search

Original Assignment

The project is to use an interrupt to achieve stepper motor control along arbitrary motion profiles (e.g., mathematical functions of time, including constant velocity profiles). For example, if your interrupt is at 1 ms, you can compare your desired step count at the current time to the desired step count at the current time and step the motor forward, backward, or not at all, as appropriate. A simpler variant of this is constant speed control: the main program sets the speed, and the interrupt determines whether or not to step the motor at each interrupt time. Your documentation must provide evidence that the interrupt service routine always completes in less time than the time between interrupts (e.g., you can use the oscilloscope and look at a pin going high at the beginning of the ISR and low at the end).

Also, stepper motors tend to have relatively low torque, but are capable of high speeds. To improve the torque, we can add a gearhead or other transmission element. It is convenient to have the motor and gearhead in a single package, so if you see a relatively inexpensive stepper motor + gearhead combination in an appropriate size, let us know!

Overview

Circuit

The Stepper Motor


Wiring Up The L293B

Wiring diagram for the L293B

A DIP16-L293B quad push pull driver is used to control the two windings for the bipolar stepper motor. +5V powers the logic supply voltage for pin 16, and +8.6V feeds into the supply voltage pin 8.

The PIC's output channels RD0-RD3 wire directly into the L293B's four inputs. The blue and red wires pertaining to one set of windings connect to pins 3 and 5 of the L293B, and the white and yellow wires for the other half go to pins 11 and 14. The remaining pins 4,5,12 and 13 all connect to a common ground.


A spec sheet for the L293B can be found here. [1]


Adjusting The Speed With A Trimpot

A convenient method of providing a varying input for the stepper motor is with a trimpot, or potentiometer. This circuit utilizes a 10k Ohm trimpot to control the speed of the stepper motor along with the direction. For this case, it will be utilized as a voltage divider, with the wiper connected to the analog input for the PIC. Zero voltage and the max +5V will emulate maximum speed for forwards and backwards directions, with the capability of slower intermediate speeds as the potentiometer reaches the halfway mark resulting in +2.5V being read by the analog input.


Code