cec322 s17.lab 6.stepper...

13
February 22, 2017 1 CEC 322 Laboratory Exercise #6 Stepper Motor operations Fixed frequency & follower operation Performed: As noted on Canvas Due: As noted on Canvas For this lab, work should be done in groups of two students or individually unless otherwise discussed with the lab instructor. Purpose: To utilize a TM4C development kit to control a unipolar 4-phase stepper motor. It will be necessary to have multiple operational control modes for the stepper motor. It must be possible to set the stepper motor to run in either direction at a fixed frequency. In this mode, the direction and or frequency should be capable of being changed and should be at a known and reported RPM. A second control mode is control the motion of the stepper motor in such a way that it follows the rotation of a connected potentiometer. It will be required to design Objectives: Increases usage of the DK-TM4C123G (or equivalent) Development Kit Introduces the concept and usage of General Purpose (digital) outputs Utilizes interrupts to generate known frequency operation Usage of the Timer Peripheral Utilize Analog to Digital Converters Utilize functions and constants in TivaWare® Peripheral Driver Library Use of the ‘C’ programming language Make use of example code and example projects Increases familiarization with the lab equipment. Increases understanding of the engineering design process. Requirements: Demonstrate to the laboratory faculty a ‘C’ software project, running on a TivaWare development kit of your choice, under the debug mode of the IAR development environment, which meets the assignment requirements. In this experiment 4 bits of a GPIO port will be used drive four logical-level output signals required to drive the four coils of the stepper motor. It will be necessary to write a software

Upload: others

Post on 23-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 1

CEC 322Laboratory Exercise #6

Stepper Motor operationsFixed frequency & follower operation

Performed: As noted on Canvas

Due: As noted on Canvas

For this lab, work should be done in groups of two students or individually unless otherwise discussed with the lab instructor.

Purpose:

To utilize a TM4C development kit to control a unipolar 4-phase stepper motor. It will be necessary to have multiple operational control modes for the stepper motor. It must be possible to set the stepper motor to run in either direction at a fixed frequency. In this mode, the direction and or frequency should be capable of being changed and should be at a known and reported RPM. A second control mode is control the motion of the stepper motor in such a way that it follows the rotation of a connected potentiometer. It will be required to design

Objectives:• Increases usage of the DK-TM4C123G (or equivalent) Development Kit

• Introduces the concept and usage of General Purpose (digital) outputs

• Utilizes interrupts to generate known frequency operation

• Usage of the Timer Peripheral

• Utilize Analog to Digital Converters

• Utilize functions and constants in TivaWare® Peripheral Driver Library

• Use of the ‘C’ programming language

• Make use of example code and example projects

• Increases familiarization with the lab equipment.

• Increases understanding of the engineering design process.

Requirements:

Demonstrate to the laboratory faculty a ‘C’ software project, running on a TivaWare development kit of your choice, under the debug mode of the IAR development environment, which meets the assignment requirements.

In this experiment 4 bits of a GPIO port will be used drive four logical-level output signals required to drive the four coils of the stepper motor. It will be necessary to write a software

Page 2: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 2

project which can drive the stepper motor, in either direction, at a known rotational frequency. In addition your software project must be capable of turning off all coils of the stepper motor and rotating the stepper motor in a manner which mimics the rotation of the on-board potentiometer.

Resource Documents:

TivaWare® for C Series

• http://www.ti.com/tool/sw-tm4c• Includes Peripheral Driver Library & Documentation• Version 2.0.1.11577 delivered with boards & used in development• Version 2.1.0.12573 on web Oct.-2014 through Feb.-2015.• Version 2.1.1.71 on web May-2015 through Dec.-2015.• Version 2.1.2.111 on web Dec.-2015 through July-16• Version 2.1.3.156 on web July-2016 through current

Useful URLs / FAQ

• Airpax Motorhttp://www.ece.ualberta.ca/~ee401/parts/data/AirpaxCatalog.pdf(42M048C1B from Pg. 22)

• Seiko Epson Motorhttp://www.portescap.com/sites/default/files/20m020d_specifications.pdf(20M020D1U)

• ULN2803http://www.ti.com/lit/ds/symlink/uln2803a.pdf

• Otherhttp://www.alhekma4u.com/Products/Motors/PM4222/index.htmhttp://www.dx.com/p/uln2803-stepper-motor-driver-module-for-arduino-red-156795

Suggested Procedure:

It is recommended that you follow the suggested procedure, but if you are able to complete the requirements of the problem, the procedure is secondary. Lab faculty will be present during lab period to clarify and we appreciate input on making the procedure clearer.

Example Code Retrieval1. It is suggested that you start from an existing project. Which existing project to start from is

at your discretion. The elements and / or peripherals which are useful in this lab are:

a. OLED display and on-board LED “heartbeat”

b. Timer to generate known frequency procedure calls

c. General purpose I/O (GPIO) to drive (4) pins

d. Analog to Digital to read onboard potentiometer position

e. UART for communication

Page 3: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 3

2. It will be useful to have available as code examples which contain these element or utilize these peripherals. Maintaining a set of operational projects or example code is useful for project development.

Building your Project3. The objective of your code development is to create a program which controls the operation

of the stepper motor as given in the requirements below.• Credits screen on the OLED at the startup of your code and when selected thereafter• At least (3) unique modes of operation for the stepper motor• (1) Mode in which all coils on the stepper motor are deactivated, not drawing any current• (2) Mode in which the stepper motor is rotating with a known, reported RPM. In this mode

you should have the ability to reverse rotation and adjust the rotational speed between 1 and 300 RPM.

• (3) Mode in which the stepper motor motion will follow the motion of a connected potentiometer. In the follow mode, if the on-board potentiometer is rotated X degrees clockwise, the stepper motor should also rotate ~X degrees clockwise.

4. Use of the UART is a required element for the assignment. The UART allows the programmer to change the display modes and/or known frequency RPM through a terminal program such as putty.

5. It is a requirement that your program MUST use a connected potentiometer to drive the stepper motor in follow-mode operation.

6. For the development of this project it is your decision on the starting project to use. This is largely based upon your preference and comfort with each project. Many other starting projects are conceivably just as useful as a starting point. The following procedure is only suggested guidance.

a. Establish control input/output communication with the development kit, through the UART, push button and/or OLED peripherals.

b. Configure the timer and “step” ISR to be executed at a frequency corresponding with a known RPM number of steps per second. 60 RPM or 30 RPM are suggested starting default rotational speeds. It may be useful to blink the LED to indicate that this “step” ISR has been executed. It may also be useful to write a function which encapsulates the RPM to step calculations and changes the timer load set accordingly.

c. Use the Analog Discovery to observe the GPIO outputs from your software. Verify that you do not have any output state(s) which would energize more than 2 adjacent coils of the stepper simultaneously.

d. Make the connections between the development kit and the SDK-51 and from there to the stepper motor. It will be necessary to use a 12V supply to power the SDK-51.

e. Test your project for operation of the stepper motor. Observe that the operation is consistent with your calculated RPM and that the motion of the motor is smooth.

Page 4: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 4

f. Add the ability to turn the motion of the stepper motor off. It is required that in this mode your stepper motor drive circuit not be consuming drive-level currents. This corresponds to the MTR_OFF constant defined in Figure 3. It is recommended that you remember the step value last driven to your motor to maintain smooth operation on motor startup.

g. Add the ability, through your UI, to reverse the rotational direction of the motor and change the rotational frequency (RPM). This will in most cases mean changing the operational frequency timer making calls to the “step” ISR.

h. Add the operational mode called ‘follow mode’ in which the motion of the stepper motor follows the motion of the on-board potentiometer. It is suggested that in this mode your “step” ISR is called at the RPM_MAX frequency as defined in Figure 3.

7. It is mandatory that you have an ISR to perform an operation at a known frequency. It is suggested that in this ISR is the only place which you move the stepper motor (i.e. write (4) signals to a GPIO port). You will be required to configure a timer to call this “step” ISR at a frequency known to correspond with a given motor RPM.

8. Numerous port / pin selections are possible to drive the GPIO signals. Both port L and port N have been shown to function on the DK-TM4C123G. In order to utilize a GPIO port, it will be required to enable the port and set the direction on the port before performing the first write operations to the port. It is not necessary to use a port with pins 3-0 available, but is definitely reduces the work required for the programmer and is therefor suggested for this assignment. Throughout this document the term MOTOR_PORT will be used to refer to this implementation specific selection.

9. The stepper motor nominally used in this experiment is an AIRPAX unipolar model with four drive phases. Other motors are available, and it is possible to complete this lab with any unipolar 4-phase stepper motor. Different values for {Steps per rotation, series-resistance} will be needed to be used, for software and circuit respectively, depending upon the motor used.

10. It will be necessary to generate four GPIO signals to drive the stepper motor through clockwise and counterclockwise rotational motion. The four signals which are output from MOTOR_PORT of the development kit each correspond to a phase of the stepper motor.

11. Figure 1 shows the signal patterns for {A, B, C, D} which correspond to Forward and Backward rotation. This sequence of signals is known to operate for the stepper motors used in the CEC322 lab. Your design should proceed through each of these patterns.

Page 5: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 5

12. Figure 1 illustrates the relationship between the motion of the stepper motor and the driven

coil phases. The motor can be driven using different drive patterns which have different numbers of degrees per step and different current draw requirements. It is encouraged that you utilize the full-torque drive.

13. An alternative drive illustration for the motor drive is given in Figure 2. The “Normal” sequence from Figure 2 is the same as the Full-Torque drive from Figure 1, which is the recommended sequence for use in this assignment.

14. To simplify the stepper motor functionality, it is suggested that you use the data definition given in Figure 3 to drive the stepper motor in clockwise and/or counterclockwise rotation.

15. Your program will be required to step through the 4-bit encodings corresponding to the stepper motor phase winding signals. Arrays, defined in C syntax, which facilitate stepping through the motor steps are given in Figure 3 below. This code fragment includes constants

corresponding to the values which turn off the motor drive windings (MTR_OFF) as well as recommendations for the maximum, minimum and initial RPM values.

FIGURE 1. Phase Sequencing for different design objectives

Low-Torque Drive

Full-Torque Drive

Half-Step Drive

const int half_step_array[9] = {0xC, 0x4, 0x6, 0x2, 0x3, 0x1, 0x9, 0x8};const int full_drive_array[5] = {0xC, 0x6, 0x3, 0x9};const int low_torque_array[5] = {0x1, 0x2, 0x4, 0x8};#define MOTOR_OFF 0x0#define STEPS_PER_REV 48#define INIT_RPM 60#define RPM_MAX 300#define RPM_MIN 1

FIGURE 3. Defined variables for use with the 4-phase unipolar stepper-motor

Page 6: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 6

16. Before constructing a high-current motor drive circuit, it is highly advised that you develop your software to the point that you can observe outputs on the development kit pins, as shown in Figure 4. Only after you can switch between an active output drive pattern, as

given in this figure, and the ability to turn the motor off, signified by the same (4) signals all having a logical low value, should the power driver circuit be constructed.

FIGURE 2. Motor connections & Drive signals from Datasheet

FIGURE 4. Four GPIO signals, monitored at the development kit pins, connected to stepper motor through SDK-51 stepper motor driver circuit

Page 7: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 7

17. Each time that the “step” ISR is called, there a number of operations which must be performed. In the fixed RPM mode, that could be as simple as increment a static value corresponding to the current index into the step_array and drive the corresponding value from the step_array out to pins {3..0} of MOTOR_PORT.

18. As your number of operating modes becomes larger it will be required to add code to this “step”ISR to enable all of the operational modes. While adding code to the ISR the program should remember that any code which consumes time (loops, Gr*Draw, UARTSend) should be kept outside of the ISR to prevent the ISR from consuming too much time and starving other processes.

19. At least one display mode should show personalized credits for your team to uniquely identify your code. It is good programming style for this to flash on the screen for 1-4 seconds on startup also.

Power Driver Options20. Unfortunately, but as is typical, the development kit signals do not have the drive strength to

directly drive the phases of a stepper motor. A circuit external to the development kit must be constructed to convert low drive strength GPIO signals to high drive strength motor drive signals. There are many techniques for generating the motor drive signals. At the moment, students are encouraged to utilize a Darlington array IC, but this procedure will describe: (a) through the use of a Darlington array IC installed into a breakout-board and series current limiting resistors, (b) the use of the same Darlington array IC installed in a breadboard, and (c) through the use of discrete components {transistors, diodes, resistors}.

Use of a Darlington Array, Specifically the ULN2803 (Option A and/or B)

21. It is logical to use an integrated circuit to interface between the low-drive strength outputs of the TM4C and the high drive strength requirements of a stepper motor. One such integrated circuit is the ULN2803 Darlington Transistor Array, 8-wide. This device allows for 500mA current sinking on each of the outputs.

22. There are available ULN2803 breakout boards, and discrete ULN2803 IC’s for installation into breadboards. It is advisable to use a ULN2803 breakout due to the currents being sourced/sank, and the higher gauge supply wires which are usable with the ULN2803 breakout.

23. Figure 5 shows an example of the connections between the DK-TM4C123G using the ULN2803 breakout. The white/green wires shown at the bottom of the figure are power/ground respectively.

24. Figure 6 shows an example of a connection between the DK-TM4C123G and the stepper motor in which a discrete ULN2803 is plugged into the breadboard and used to drive the stepper motor. This usage is possible, but discouraged because it requires that 500mA be sourced/sank through the lower-gauge supply wires.

Page 8: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 8

25. Regardless of which mechanism is used to connect the ULN2803, it will be necessary to use this device together with series resistors for each stepper motor phase to limit the current sunk by the ULN2803. Correct selection of series resistors allow the circuit to operate within the current limitations of both the Darlington array and the stepper motor selected.

FIGURE 5. Development Kit connected to stepper motor through ULN2803 Darlington Array breakout (small red board)

FIGURE 6. Development Kit connected to stepper motor through ULN2803 Darlington Array plugged into breadboard

Page 9: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 9

26. The schematic for the connections between the stepper motor, ULN2803 and microcontroller GPIO is shown in Figure 7. This figure is accurate of a single one of four phases of the unipolar stepper motor drive circuit. It is required that you calculate the correct value(s) of Rseries given the Rcoil and Lcoil for your selected stepper motor from the datasheet.

Use of a Discrete Component Circuit (Option C)

27. .Another alternative for the power drive circuit is to build the circuit from discrete components, as shown in Figure 8. The use of the LED, as shown in this image is optional, and the circuit is otherwise as shown in Figure 7, with a 3-pin transistor substituting for the each of the channels in the Darlington array.

Reverse, Change Frequency, and Follow28. After you have determined which mechanism you are

going to use to drive the power required for the Stepper Motor phases, continue with software development until your program is capable generating a single known RPM (i.e. 60RPM or 120 RPM) operation of the stepper motor. Any program which is capable of known RPM stepper motor rotation is sufficient of the first signoff.

29. When debugging the communication path between the development kit and the phases of the stepper motor, it is useful to monitor the circuit using the analog discovery. Figure 9 shows the interface when both the GPIO driven signals (DIO3-0) and ULN2803 driven signals (DIO15-12) are being monitored. Note, output from the ULN2803 must be monitored at the ULN2803 pin rather than the motor input due to the voltage drop across Rseries. Also note the logical inversion between the ULN2803 input and output due to the inverting nature of the Darlington array.

30. Figure 4 shows the four stepper motor driver signals which are driven by the development kit and subsequently amplified a power drive circuit. Use of the Analog Discovery to watch these signals is highly advised as a mechanism for debugging software.

FIGURE 7. Circuit used to interface to motor using ULN2803 and to calculate the appropriate Rseries

FIGURE 8. Stepper Motor “H-Bridge” driver circuit on

breadboard

Page 10: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 10

31. Clean up your code for final submission. Verify operation of all of the requirements listed in this document. Before calling over the lab faculty for signoff, verify operation of project with all listed requirements. Be sure you are able to complete the data collection table on the data instructor sign-off sheet.

32. Request the final signoff. At this time please ask if you have any questions or concerns to address with the lab faculty.

33. After signoff, make sure that you have all of the information necessary to complete the consideration questions prior to circuit tear-down.

Consideration Questions:

Please answer the following questions as a portion of your completed lab report.

1. Provide the list of functions from the Texas Instruments provided library(s) which you used FOR THE FIRST TIME under IAR in your software project. State what include files and/or libraries are necessary due to the usage of this function.

2. Draw a schematic of the connections between the (a) TM4C development kit, (b) your selected power-drive circuit and (c) the stepper Motor. Be SPECIFIC about individual pins used from a development kit or IC. It is suggested you perform this exercise BEFORE making these connections in lab with hardware.

3. Find the Rcoil for the stepper motor used from the datasheet. Assuming the use of a Darlington array with a maximum current specification of 500mA, the motor you utilized for the lab, the connection circuit shown in Figure 7, and a COM voltage of 12V, calculate the appropriate values of Rseries which will allow to Darlington to operate at 90% of current specification and 20% of current specification.

FIGURE 9. Eight GPIO signals, Four (DIO 0-3) monitor the development kit pins, and Four (DIO 12-15) monitor the connections to each of the stepper

motor phases, as connected through a ULN2803. Noise is shown on DIO 12

Page 11: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 11

4. Review the development kit schematic, datasheet and possibly other documentation to identify the rated pin current of the MOTOR_PORT pins 3- 0.

5. Define:• Full Drive• Half-step Drive• ISR

6. Provide formula(s) which can be used to convert a given RPM to the corresponding number of steps per second for BOTH the Full-Drive and the Half-Step arrays.

7. Referencing Figure 4, answer the following questions.

a. Does the figure show the use of a half-step or full drive array? Justify your answer.

b. What is the approximate rotational velocity of the stepper motor connected to the signals shown. Show your work.

8. What were the surprises you encountered in completing this laboratory exercise, what were the challenges you encountered in completing this laboratory exercise, what could be done to make this exercise better in the future?

Deliverables:

Due at your arrival to Lab the next lab.

1. Your name, the class number (CEC322), the Lab #, and the Lab title on the front page of the completed assignment, this does not need to be a cover page.

2. Lab report, in format consistent with the Lab Policies guidelines posted to the course webpage.

3. All ‘C’ code modified or developed to solve the problem set forth in this assignment. If at all possible this should be printed in such a way as to include color coding as provided in an IDE.

4. At least one picture of your operational system illustrating the wired connections.

5. At least one screen capture from the analog discovery illustrating the logical connections. Similar to Figure 4 and / or Figure 9.

6. The original In-Lab Data Recording sheets with instructor initials.

7. Responses to the consideration questions given above.

Page 12: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 12

Grade Point Allocation:

Category Points PossibleReport 5Presentation 5Consideration Q’s 5‘C’ Code style, implementation & operation 5Signoff 5Total 25

TABLE 1. Grade Point Allocation

Page 13: cec322 s17.Lab 6.Stepper Motor.v8mercury.pr.erau.edu/~siewerts/cec320/labs/cec322_Lab_6.Stepper_Motor.v8.pdfperiod to clarify and we appreciate input on making the procedure clearer

February 22, 2017 13

Instructor Sign-off

Each laboratory group must complete a copy of this sheet.

Student A Name ____________________________________________

Student B Name ____________________________________________

Development Kit Used ______________

Lab Station Used ______________

1. Demonstrate operation of your a project driving a stepper motor at a known rotational frequency (RPM).

Instructors’s Initials ________________________Date/Time___________________

Starting Project used : ________________________

Drive Array used : ________________________

2. Demonstrate a software project which meets all of the requirements set for in the laboratory procedure. Smooth operation of (a) off, (b) reported RPM, and (c) follow mode are required. Additionally in reported RPM mode, the UI should enable rotation in both directions and the ability to change the RPM.

Answer any questions the lab faculty may have, and demonstrate to the lab faculty that you have met the requirements of this laboratory exercise.

Instructors’s Initials ________________________Date/Time___________________

/5