EENG 383 Microcomputer Architecture and Interfacing Spring 2015 Lab 2 – Stepper Motor January 22, 2015 In this lab you will use the HCS12 microcontroller on the SSMI board to control a stepper motor. You will implement simple delay loops in order to control the timing and speed of the stepper motor. You will also gain experience with a voltage regulator and a Darlington driver. 1 Prelab Questions (answer prior to coming to lab) Read this handout before coming to lab and answer the following questions. 1. Voltage regulator: a. What is the minimum input voltage needed in order to generate an output voltage of 5V? Hint: see “recommended operating conditions” on the device datasheet. b. Estimate the value of R2 in Equation 1, so that the output voltage is 5V. 2. ULN283 Darlington driver: a. How much current can the ULN2803 sink on each output (refer to the data sheet on the course website)? b. What should pin 10 of the ULN2803 be connected to? c. What is the typical collector-emitter saturation voltage of the ULN2803? 3. Looking at the schematic for the SSMI board (on the course website), you can see that pin 1 of jack J5 (this is what you connect your power supply to) comes out to a signal labeled Vpwr. This signal is also brought out to header H1 on the SSMI board. What pin is Vpwr on H1? 4. Port T is another input/output port, just like Port M. Where are Port T, pins 0..3 located on H1? 5. Write a little assembly language code snippet that outputs a logic high (+5V) on PT31. 2 Background The stepper motor in lab is unipolar, permanent magnet type with six pins (Figure 1). The “VM” pins will be connected to a +5V source. By pulling the other four pins low in sequence, we energize the coils in sequence and make the rotor turn. For example, the sequence A→B→A’→B’ will cause the rotor to turn to positions: 8→6→4→2. 1 “PT3” means Port T, pin 3. 1 Figure 1. Unipolar stepper motor (from http://www.solarbotics.net/library/pdflib/ pdf/motorbas.pdf) EENG 383 Microcomputer Architecture and Interfacing Spring 2015 Pulling a pin low means that a lot of current passes through the coil and must be sunk by the driving device. The microcontroller has far too little current output sinking capability to drive this stepper motor (or any motor, for that matter). Therefore, we will use the ULN2803 driver chip to interface to the motor. Study the data sheet of this chip. This device contains 8 bipolar power transistors, configured as “Darlington drivers” (Figure 2). Each of the outputs is independently controllable. The output of each driver transistor is open collector. Our strategy will be to use four of these outputs to drive the four windings of the stepper motor. Each output, when asserted, must be able to sink the current flowing through its respective winding of the motor. Figure 2. (Left) ULN2803 pinout. (Right) Each output is configured as a “Darlington driver”. Note the flyback diodes. One final issue has to do with the power supply for the stepper motor. The power supply that you have in the kits is a +9V AC-DC wall adapter2. However, the stepper motor is rated for only +5V DC. If you were to connect the motor to the +9V supply, the motor will overheat. Therefore, we need to lower the voltage that is supplied to the motor. We can do this with a voltage regulator. A voltage regulator is a circuit that can take a variable, unregulated input voltage (such as from a battery or your AC-DC wall adapter) and output a stable, constant voltage that doesn’t depend on the load. We will use the LM317 adjustable voltage regulator, which is a chip with 3 terminals (“input”, “output”, and “adj”). See the data sheet on the course website for the pinouts of this chip. The LM317 voltage regulator adjusts its output voltage so as to make the voltage drop between its “output” pin and its “adjust” pin equal to Vref = 1.25 V (see Figure 3). The input voltage must 2 Actually, if you measure the voltage with no load, you will probably get a higher voltage than +9V. This is a nonregulated power supply, so the output will fluctuate and will depend on the load. The +9V is just a nominal value. 2 EENG 383 Microcomputer Architecture and Interfacing Spring 2015 be higher than the desired output voltage. From Figure 3, you can calculate the output voltage as a function of R1 and R2: R VO Vref 1 2 I Adj R2 R1 Here, IAdj is a small current (typically 50 A) and is negligible in most applications. 3 (1) Voltage Regulator With the power supply unplugged, assemble the circuit shown in Figure 3 on the protoboard area of the SSMI board. Vi should be connected to Vpwr on H1. For R2, use the little “trimpot” that comes in the kit. Adjust the trimpot to the value that you calculated in the pre-lab exercise. Show your circuit to the instructor and get his or her approval before proceeding. Input Vi Output LM317 Adjust Vref = 1.25V VO R1 1K Iadj R2 Figure 3. LM317 adjustable voltage regulator. Capacitors can be added to improve ripple rejection (see the device datasheet). Plug in the 9V power supply and connect it to the SSMI board at connector J5. Measure the output voltage Vo. It may be necessary to adjust the potentiometer a little so that Vo equals 5V. 4 Stepper Motor 1. Estimate the step size (in degrees) of the stepper motor, by manually turning the shaft. You will feel a detent at each step. Hint - it is one of these possibilities: 5.0 degrees, 7.5 degrees, 10.0 degrees. 2. Measure the resistance across the coils of the stepper motor with the multimeter, and identify the pins in Figure 1. Note that the resistance from the center tap (e.g., VM in the figure) to one of the ends (e.g., Phase A) will be half the resistance from one end of the coil to the other (e.g., Phase A to Phase A’). 3. Estimate the current draw through the coils and make sure that the ULN2803 can handle this. To compute this, divide the voltage drop across the coil (5V minus the collector-emitter saturation voltage of the ULN2803) by the resistance of the coil. Include your calculations in your lab report. 3 EENG 383 5 Microcomputer Architecture and Interfacing Spring 2015 Driver Circuit With the power off, place the ULN2803 onto the protoboard area of the SSMI board. We will control the ULN2803 with four output pins of the HCS12 microcontroller chip. These are pins 0 through 3 of Port T. Identify where these come out to header H1. Draw a schematic diagram of the connections from the microcontroller to the ULN2803, and from the ULN2803 to the motor. Don’t forget the ground and Vcc (common) pins on the ULN2803. The power to the motor should come from the voltage regulator output. In this section you will design the circuit and make the connections. However, don’t plug in the power adapter until you show your schematic and the circuit to the instructor and get his or her approval before proceeding. Connect the components. 1. Sign-Off 1: Show your schematic and the circuit to the instructor and get his approval before proceeding. 6 Program Create the following short program to configure PT0..PT3 as output pins, and then go into an infinite loop: ldaa staa bra #%00001111 DDRT * ; configure PortT, bits 0..3 ; .. for output ; loop here forever Compile and load this program and start the debugger. Manually write to Port T to turn on and off the PT0..PT3 pins. You can do this by simply double clicking on address $240 in the memory window and typing in a new value there. For example, to turn on PT0 you would write a $01 to Port T; to turn PT1 you would write a $02, and so on. Find out what the sequence of values should be to make the motor rotate. Write a short program that continuously outputs the above sequence of values to Port T in order to drive the motor continuously. Include a short (~1 sec) delay after each value (you can use the module from class). The pseudo code for this program is: Configure PT0..PT3 as output pins while (true) do store first value to Port T delay store second value to Port T 4 EENG 383 Microcomputer Architecture and Interfacing Spring 2015 delay store third value to Port T delay store fourth value to Port T delay end while 1. Sign-Off 2: By adjusting the delay times, you can drive the motor at different speeds. Calculate the delay necessary to achieve a rotation speed of exactly 1 revolution per second. You may find it helpful to put a little mark on the shaft of the motor so you can see its position. Demonstrate your program to the instructor. Include your calculations and the assembly program in your report. 2. Sign-Off 3: Modify your program above so that instead of rotating continuously, the motor will rotate through a one full revolution and then stop. To do this, replace the infinite loop with a loop that tests a counter and stops when the count limit is reached. Demonstrate your program to the instructor. Include the assembly program in your report. 3. Now increase the pulse rate of the motor until it starts losing steps (this will be evident because the motor will not rotate smoothly through a complete turn). What is the maximum pulse rate in terms of cycles per second, for which the motor does not lose steps? 7 Extra Credit Modify the program so that it uses “half steps” instead of “full steps” (see Lecture 9, slide 5). Have the motor rotate through a one full revolution and then stop. How many steps do you need to have a full rotation? 5 EENG 383 Microcomputer Architecture and Interfacing Spring 2015 Lab 2: Stepper Motor Name: ________________________________Name: ________________________________ Task Description Initials Sign-Off 1 Schematic and Implementation Sign-Off 2 One RPS Sign-Off 3 360 Degrees 8 Rubric Deliverables 20 pts Pre-Lab Code with flowchart/psuedocode /7 Schematic / 5 Demonstrations Circuit and program Explanation /3 Graph, Scope traces /5 Composition Questions Sign-Off 1: Schematic/Implementation 5 pts Total / 50 pts 6 5 pts /5 20 pts /5 Sign-Off 2: One RPM /7 Sign-Off 3: 360 Degrees /8
© Copyright 2024