Lab 9, CMPET 211 FSM Controlled Stepper Motor
Total Page:16
File Type:pdf, Size:1020Kb
Lab 9, CMPET 211 – FSM Controlled Stepper Motor
Fall 15, ADH
Lab Summary In this lab, the student will learn how to build a uni-pole stepper motor controller. The binary interface (built with transistors, diodes, and resistors) can be extended to control other binary actuators including brushed DC motors, relays, solenoids, and speakers. The software driving the stepper motor controller uses the Finite State Machine design methodology. In this lab, the software will control on/off modes and fast/slow modes. Due to the nature of Finite State Machines, the software could be quickly modified to accommodate single stepping, half stepping, and reverse modes.
Learning Objectives
Build a binary interface which could be extended to many binary actuators
Use the microcontroller to drive a DC Stepper motor
Create a project “from scratch”
Increase working knowledge of Finite State Machines
Lab Materials and Software Students will need a Tiva TM4C123GXL LaunchPad microcontroller by Texas Instruments, the supplied USB cable and access to Tiva TM4C123 software.
Students will also need:
1x 5 Volt, 0.5 AMP Stepper Motor (P/N 25BY4801)
4x TIP120 Transistors
4x 1.5kΩ Resistors
4x 1N914 Diodes
4x pushbutton switches
Breadboard and jumpers
Dual (or triple) output DC power supply
IMPORTANT NOTE: Datasheets are found on the course website.
1 Students need access to CCS, TivaWare, and LMFlashProgrammer software. The software may be downloaded for free (instructions are on Hilshey’s website).
Pre-Lab Procedure Before your lab period you should have defined a Finite State Machine, created a State Transition Graph, written C code to implement your Finite State Machine, and debugged your code (by single stepping and observing state transitions and outputs given inputs).
Your Finite State Machine should drive a DC stepper motor operating in one of three modes: 1.) off mode; 2.) slow forward mode; and 3.) fast forward mode. The mode selection should be determined by using the Tiva LaunchPad push buttons (one button for on/off, the other button for slow/fast).
If this prelab homework assignment is not complete, you should continue straight to the next section (“In Lab Procedure”) and worry about the software outside of and after lab.
In-Lab Procedure Following a careful procedure will prevent damage to your Tiva LaunchPad and the provided lab equipment. Please follow the steps carefully.
Build the “manual” stepper motor of Appendix 1. Tip: Use short jumper wires to increase visibility; pay careful attention to organization. These ideas will help you to save time in troubleshooting and double-checking your circuitry.
READ THIS ENTIRE SUB-SECTION BEFORE BUILDING THE CIRCUIT: Before using the LaunchPad, we will build the stepper motor driver circuit which will be “mildly” functional without the microcontroller’s presence (i.e. pusbuttons will allow you to step the motor without the microcontroller). To avoid damage to the Tiva LaunchPad, a separate 3.3 Volt DC source will simulate the LaunchPad output voltage (use the output of the 0-6Volt variable DC power supply, set to 3.3 Volts). Pushbuttons will be connected to the 3.3 volt source and will allow you to simulate GPIO pins firing high (button pushed) or going low (button not pushed). The pushbuttons (with 3.3 volt source) will control the transistors that allow current to flow (or not flow) through the stepper motor coils.
PLEASE DO NOT SET THE 0-6 VOLT SUPPLY BEYOND 3.3 VOLTS!
The brown and orange wires of the stepper motor will be tied to a separate 5 volt source (use the output of the 0-25 volt DC power supply). They will power coils A and B.
PLEASE DO NOT SET THE 0-25 VOLT SUPPLY BEYOND 5 VOLTS!
A 1.5kΩ resistor between each pushbutton and each TIP120 transistor base pin is used to limit current. It has been chosen in accordance with transistor datasheet information and the assumption that the voltage source tied to the base is 3.3 volts and that the stepper motor will draw approximately 0.5 Amps
2 with a 5 volt power source. See example 8.1 in the Valvano textbook for sample calculations. Note: this is similar to using KVL to determine a current limiting resistor for a diode (performed in an earlier lab).
A 1N914 diode is placed in parallel with its respective coil ground wire (black, white, red, or yellow) and the 5 volt stepper motor power supply. Its purpose is to control “kickback” current, which will protect the circuitry. There is a cathode and anode side to the diode (it must be connected correctly to function!); be sure to check out the datasheet (available on course website) and Figure 1 schematic in this handout for proper installation.
The black wire will eventually (i.e. in the next sub-section) be tied to the bit 0 transistor; white will be tied to the bit 1 transistor; red will be tied to the bit 2 transistor; and yellow will be tied to the bit 3 transistor. Be particular with how you organize your transistors and pushbuttons to ensure that you eventually tie the correct transistor to the appropriate GPIO pin (in the next section).
DOUBLE CHECK ALL CONNECTIONS BEFORE POWERING UP! Are all Diodes oriented correctly? Are the pushbuttons wired correctly (not shorted across pins) and not installed sideways? Are the Transistor pins used correctly? Did you use resistors between the pushbuttons and the transistor base pins?
Once the circuit is built (LunchPad is STILL not involved), power it up and try to manually step the motor by executing (with the pushbuttons) the binary nibble sequence: 5, 6, 10, 9 (presented here as decimal numbers). Check your lecture notes from week 9 if this does not make sense.
To get the stepper to spin around, you will need to carefully press both desired buttons at the same time (or the rotor might just oscillate back and forth somewhat).
If all of the pushbuttons are able to lock the rotor, and if you can get it to spin around manually, progress to the next section.
Build the MCU stepper motor driver of Figure 2. With the previous section satisfied, disconnect the 3.3 volt source (keep the 5 volt source from the 0-25 Volt DC supply, but power down for now). Next, carefully remove the pushbuttons from the breadboard and make connections from the appropriate LaunchPad GPIO pins to the base resistors (the other end of the resistors tie into the base pins of the transistors).
Before running the C code, verify that your delays between state transitions are appropriate. To start, within your C code, you may wish to set your bus clock to 40 MHz and choose slow delays of 100,000 in the SysCtlDelay() TivaWare function. Fast delays could be 50,000. Note: you may choose any delays you wish, but if the delay is too small, the coils may not have time to respond.
Hopefully you’re spinning! If not, verify that the correct motor wires are tied to the correct GPIO pins (i.e. black to pin 0). If this checks out and everything worked in the previous section, then it’s time to re- debug your code.
3 Note on limited access to motors and DC power supplies If you do not finish the lab during this lab period, two spare DC motors will be kept in the 208 Force Computer Lab under the podium. You are free to use them, but THEY SHOULD NOT LEAVE 208 Force (because other people will need them). For a makeshift power supply for the orange and brown motor wires, use the Tiva LaunchPad +3.3Volt and GND pins to drive your motor (as might be expected, the torque will be lower than using a 5 volt source, but it will work). Please don’t use 9 volt batteries or anything else which is higher than 5 volts to power the motor.
Demonstration/Grading Demonstrate the lab and turn in a commented source code. Also include the following:
1. Answer or show the following:
a. How many how many degrees does each stepper motor step take?
b. Verify the base resistor value through calculations (use the stepper motor data sheet, the transistor data sheet, and optionally examples in chapter 8 of the Valvano textbook). Show calculations.
c. Given 40 MHz bus clock, choose a SysCtlDelay() value which would complete one stepper motor rotation in 1 second. Remember that SysCtlDelay(1) = 3 bus cycles. Show calculations.
2. Turn in your readable State Transition Graph
4 Appendix 1. Building a Stepper Motor Binary Interface
Figure 1 Building the Stepper Motor Driver WITHOUT the LaunchPAD
5 6 Appendix 2. Connecting the Stepper Motor Interface to the Microcontroller
Figure 2: Connecting the Stepper Motor Driver to the Tiva LaunchPad
7 Appendix 3. Block Diagram of Pins used in this lab
8 9