PIC32MX: Driving a Stepper Motor

From Mech
Revision as of 19:20, 27 January 2010 by Lynch (talk | contribs) (New page: == Original Assignment == '''Do not erase this section!''' Your assignment is to create code that reads a voltage from a potentiometer and controls a stepper motor to rotate at a proport...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Original Assignment

Do not erase this section!

Your assignment is to create code that reads a voltage from a potentiometer and controls a stepper motor to rotate at a proportional speed. The middle range of the analog input (i.e., 1.65 V) corresponds to zero speed, the minimum is maximum backward speed, and the maximum is maximum forward speed. You will create an interrupt service routine that is called every 500 microseconds. Each time through the routine, you will add 1 to a counter. When that counter (time, in units of 500 microseconds) exceeds the inverse of the desired speed (time per step), you will change the digital outputs controlling the stepper motor to the next position, depending on the direction of motion, and set the counter back to zero.

To do this, you must create a function that takes the analog input, turns it into a speed, then turns it into an inverse of speed that the ISR uses. Clearly the shortest allowable inverse of speed is 1 unit (500 microseconds per step). But can your motor really do this, or does it just vibrate if you try to rotate that fast? Based on your experiments, you should find the maximum speed that the motor actually tracks and set that as a constant. Then 3.3 V and 0 V map to this speed, in opposite directions.

You will use a geared stepper motor that we provide.

Overview

Summarize briefly what the page is about.

Circuit

Include a schematic and give any part numbers. A photo of your circuit is OK, but not as a replacement for a schematic.

Code

Where possible, make it a single piece of well-commented cut-and-pastable code, or at least make each function that way, so others can easily copy it. Most comments should be in the code itself; outside the code (on the wiki) should only be explanatory comments that are too cumbersome to include in the code.