Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
learn:courses:unit-2-lab2b:start [2017/02/10 21:05] – [Table] Marthalearn:courses:unit-2-lab2b:start [2021/10/13 22:18] (current) Arthur Brown
Line 1: Line 1:
 ====== Lab 2b: Dynamic Stepper Motor Control ====== ====== Lab 2b: Dynamic Stepper Motor Control ======
 +[[{}/learn/courses/unit-2-lab2a/start|Back to Lab 2a]]
 +[[{}/learn/courses/unit-2/start|Back to Unit 2]]
 +
 == Download This Document == == Download This Document ==
-  * +{{ :learn:courses:unit-2-lab2b:lab_2b.pdf |Lab 2b PDF}}
  
  
Line 22: Line 25:
 ===== 3. Equipment List ===== ===== 3. Equipment List =====
 ==== 3.1. Hardware ==== ==== 3.1. Hardware ====
-  - Basys MX3 trainer board+  - [[https://digilent.com/shop/basys-mx3-pic32mx-trainer-board-for-embedded-systems-courses/|Basys MX3 trainer board]] 
-  - PC or Linux Workstation computer. +  - [[https://digilent.com/shop/usb-a-to-micro-b-cable/|Micro USB cable]] 
-  - [[http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/|Analog Discovery 2]]. +  - Workstation computer running Windows 10 or higher, MAC OS, or Linux 
-  - [[http://store.digilentinc.com/stepper-motor/|4 wire stepper motor]]. +  - [[https://digilent.com/shop/stepper-motor/|4 wire stepper motor]] 
-  - [[http://store.digilentinc.com/5v-2-5a-switching-power-supply/|5 V @ 2.5 A DC power supply]].+  - [[https://digilent.com/shop/5v-4a-switching-power-supply/|5V, 4A DC power supply]] 
 + 
 +In addition, we suggest the following instruments: 
 +  - [[http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,842,1018&Prod=ANALOG-DISCOVERY|Digilent Analog Discovery 2]] 
  
  
 ==== 3.2. Software: ==== ==== 3.2. Software: ====
-  - [[http://www.microchip.com/mplab/mplab-x-ide|Microchip MPLAB X® v3.35 or higher]]. +  - [[http://www.microchip.com/mplab/mplab-x-ide|Microchip MPLAB X® v3.35 or higher]] 
-  - [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]]. +  - [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]] 
-  - [[http://www.microchip.com/SWLibraryWeb/product.aspx?product=PIC32%20Peripheral%20Library|PLIB Peripheral Library]]. +  - [[http://www.microchip.com/SWLibraryWeb/product.aspx?product=PIC32%20Peripheral%20Library|PLIB Peripheral Library]] 
-  - [[http://store.digilentinc.com/waveforms-2015-download-only/|WaveForms 2015]].+  - [[https://digilent.com/shop/software/digilent-waveforms/|WaveForms]]
  
  
 ---- ----
  
-===== 4. Takeaways =====+===== 4. Project Takeaways =====
   - The ability to control the speed of rotation of a stepper motor.   - The ability to control the speed of rotation of a stepper motor.
   - Determine the number of steps required for one rotation of the rotor.   - Determine the number of steps required for one rotation of the rotor.
Line 57: Line 64:
  
 ===== 7. Background Information ===== ===== 7. Background Information =====
-Stepper motors are electrical mechanical devices used in many robotics applications. In this lab, we will look at how the PIC32 internal timers can be used to implement both cooperative and preemptive scheduling for a real-time system application. We will use time management to transition between states, giving the appearance of continuous rotation of the motor. The position of the stepper motor shaft is a function of four outputs. These outputs must change in a predefined order to cause the motor shaft to move in discrete steps. The outputs to the stepper motor are controlled using a state machine algorithm that generates output patterns and will be used to control position and angular velocity.  +Stepper motors are electrical mechanical devices used in many robotics applications. In this lab, we will look at how the PIC32 internal timers can be used to implement both cooperative and preemptive scheduling for a real-time system application. We will use time management to transition between states, giving the appearance of continuous rotation of the motor. The position of the stepper motor shaft is a function of four outputs. These outputs must change in a predefined order to cause the motor shaft to move in discrete steps. The outputs to the stepper motor are controlled using a state machine algorithm that generates output patterns and will be used to control position and angular velocity. 
 + 
 Since the PIC32 outputs represent a form of memory, I find it convenient to use state [[https://en.wikipedia.org/wiki/UML_state_machine#Entry_and_exit_actions|on-entry or on-exit actions]] to set the processor pins. An on-entry action sets the phase outputs specified for that case whenever a state (case) is entered. An on-exit action sets the phase outputs specified for that case whenever a next state (case) is set. The DIR and MODE inputs define the next state using “if-else” or a sub level of “switch-case” statements. Since the PIC32 outputs represent a form of memory, I find it convenient to use state [[https://en.wikipedia.org/wiki/UML_state_machine#Entry_and_exit_actions|on-entry or on-exit actions]] to set the processor pins. An on-entry action sets the phase outputs specified for that case whenever a state (case) is entered. An on-exit action sets the phase outputs specified for that case whenever a next state (case) is set. The DIR and MODE inputs define the next state using “if-else” or a sub level of “switch-case” statements.
  
 An alternate implementation uses a table of output codes and an index that becomes the state. It must be remembered that the Basys MX3 platform does not connect consecutive processor pins on a single port to the stepper motor phases. Hence, the state output table must be replaced with a sequence of bit-banging instructions to individually set each phase output pin. An alternate implementation uses a table of output codes and an index that becomes the state. It must be remembered that the Basys MX3 platform does not connect consecutive processor pins on a single port to the stepper motor phases. Hence, the state output table must be replaced with a sequence of bit-banging instructions to individually set each phase output pin.
 +
  
  
Line 86: Line 94:
   - Concept maps   - Concept maps
     - Develop a Data flow diagram that relates slide switch inputs, push button inputs, and timer interrupts to stepper motor and seven segment LED outputs.     - Develop a Data flow diagram that relates slide switch inputs, push button inputs, and timer interrupts to stepper motor and seven segment LED outputs.
-    - Develop a state transition diagram similar to the one described in [[https://reference.digilentinc.com/learn/courses/unit-2/start|Unit 2]].+    - Develop a state transition diagram similar to the one described in [[/learn/courses/unit-2/start|Unit 2]].
     - Develop a control flow diagram that describes the total system operation. Background operations are represented separately from each foreground operation.     - Develop a control flow diagram that describes the total system operation. Background operations are represented separately from each foreground operation.
   - Review the pertinent schematic diagrams to determine the relevant IO pin assignments. Refer to Figs. A.3, A.4, and A.5 in Appendix A.   - Review the pertinent schematic diagrams to determine the relevant IO pin assignments. Refer to Figs. A.3, A.4, and A.5 in Appendix A.
Line 114: Line 122:
  
  
----- 
  
-===== 9Questions ===== +==== 8.4. Testing ==== 
-**1.** Configure the Analog Discovery to display the PIC32 outputs used for the stepper motor control, as shown in Fig. 9.1.+**1.** Configure the Analog Discovery to display the PIC32 outputs used for the stepper motor control, as shown in Fig. 8.1.
  
-{{ :learn:courses:unit-2-lab2b:figure-9-1.png?nolink |Figure 9.1. Waveforms screen capture showing stepper motor output signals.}} +{{ :learn:courses:unit-2-lab2b:lab_2b_fig_8_1.png?nolink |Figure 8.1. Waveforms screen capture showing stepper motor output signals.}} 
-//Figure 9.1. Waveforms screen capture showing stepper motor output signals.//+//Figure 8.1. Waveforms screen capture showing stepper motor output signals.//
  
 **a.** Measure the step interval for switch settings in the following table and compute the motor speed in RPM using the expression developed for Phase 1, step 1. **a.** Measure the step interval for switch settings in the following table and compute the motor speed in RPM using the expression developed for Phase 1, step 1.
  
-**Table 9.1.  Stepper motor speed control performance log.**+**Table 8.2.  Stepper motor speed control performance log.**
  
 ^ SW7-SW0          ^ BTND  ^ Set Rotor Speed RPM  ^ Step Period – ms  ^ Calculated Rotor Speed RPM  ^ ^ SW7-SW0          ^ BTND  ^ Set Rotor Speed RPM  ^ Step Period – ms  ^ Calculated Rotor Speed RPM  ^
Line 144: Line 151:
 | 1 0 0 0 0 0 0 0  | Up    | 16.0                                                               | | 1 0 0 0 0 0 0 0  | Up    | 16.0                                                               |
  
-**b.** Capture the WaveForms 2015 screen when slide switches are configured for 0x40 (SW6, and SW4 set high resulting in 10.00 RPM), as shown in Fig. A.1, when BTND push button is depressed.+**b.** Capture the WaveForms screen when slide switches are configured for 0x40 (SW6, and SW4 set high resulting in 10.00 RPM), as shown in Fig. A.1, when BTND push button is depressed.
  
  
 ---- ----
  
-===== 10. Questions ===== +===== 9. Questions ===== 
-  - How are you able to accurately determine the number of steps per revolution? How many steps occur in the phase period shown in Fig. 9.1?  +  - How are you able to accurately determine the number of steps per revolution? How many steps occur in the phase period shown in Fig. 8.1? 
-  - How many steps occur in the same phase period for the screen capture completed under Testing 1.b?+
   - From the expression that converts RPM to ms per step, what is the effect of using integer division on the actual stepper motor rotational speed?     - From the expression that converts RPM to ms per step, what is the effect of using integer division on the actual stepper motor rotational speed?  
   - What is the measured stepper motor maximum rotational speed?    - What is the measured stepper motor maximum rotational speed? 
   - Using the pin designated for LCD DB0 on the Basys MX3 processor board (PIC32 RE0), measure the minimum and maximum ISR execution time. Using the MPLAB stopwatch feature and the assembler code for the Timer 1 ISR prologue and epilogue (saving and restoring) times, what is the worst case ISR execution time?   - Using the pin designated for LCD DB0 on the Basys MX3 processor board (PIC32 RE0), measure the minimum and maximum ISR execution time. Using the MPLAB stopwatch feature and the assembler code for the Timer 1 ISR prologue and epilogue (saving and restoring) times, what is the worst case ISR execution time?
-  - Using the pin designated for LCD DB0 on the Basys MX3 processor board, measure the minimum and maximum background loop. What is the worst case response time for a user input measured in microseconds? Does this agree with measurements taken for 5 above+  - Using the pin designated for LCD DB0 on the Basys MX3 processor board, measure the minimum and maximum background loop. What is the worst case response time for a user input measured in microseconds?
  
  
 ---- ----
  
-===== 11. References =====+===== 10. References =====
   - [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|PIC32MX330/350/370/430/450/470]] Family Data Sheet.   - [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|PIC32MX330/350/370/430/450/470]] Family Data Sheet.
   - Basys MX3 Reference Manual.    - Basys MX3 Reference Manual. 
Line 170: Line 176:
  
 ===== Appendix A: Basys MX3 Schematic Drawings and Equipment Configurations ===== ===== Appendix A: Basys MX3 Schematic Drawings and Equipment Configurations =====
-{{ :learn:courses:unit-2-lab2b:figure-a-1.png?nolink |Figure A.1. Equipment configuration for Lab 2b.}}+{{ :learn:courses:unit-2-lab2b:unit_2_-_photo_1.jpg?nolink&400 |Figure A.1. Equipment configuration for Lab 2b.}}
 //Figure A.1. Equipment configuration for Lab 2b.// //Figure A.1. Equipment configuration for Lab 2b.//
  
Line 176: Line 182:
 //Figure A.2. Basys MX3 slide switch schematic.// //Figure A.2. Basys MX3 slide switch schematic.//
  
-{{ :learn:courses:unit-2-lab2b:figure-a-3.png?nolink |Figure A.3. Switch setting for 18.25 RPM.}}+{{ :learn:courses:unit-2-lab2b:unit_2_-_photo_2.jpg?nolink&400 |Figure A.3. Switch setting for 18.25 RPM.}}
 //Figure A.3. Switch setting for 18.25 RPM.// //Figure A.3. Switch setting for 18.25 RPM.//
  
-{{ :learn:courses:unit-2-lab2b:figure-a-4.png?nolink |Figure A.4. Push button schematic diagram.}}+{{ :learn:courses:unit-2-lab2b:lab_2b_fig_a_4.jpg?nolink&600 |Figure A.4. Push button schematic diagram.}}
 //Figure A.4. Push button schematic diagram.// //Figure A.4. Push button schematic diagram.//
  
-{{ :learn:courses:unit-2-lab2b:figure-a-5.png?nolink |Figure A.5. Schematic diagram of stepper motor driver.}}+{{ :learn:courses:unit-2-lab2b:lab_2b_fig_a_5.jpg?nolink&600 |Figure A.5. Schematic diagram of stepper motor driver.}}
 //Figure A.5. Schematic diagram of stepper motor driver.// //Figure A.5. Schematic diagram of stepper motor driver.//
  
-{{ :learn:courses:unit-2-lab2b:figure-a-6.png?nolink |Figure A.6.  Stepper motor connector to Basys MX3 connection. The stepper motor pink wire is not connected.}}+{{ :learn:courses:unit-2-lab2b:unit_2_-_photo_3.jpg?nolink&400 |Figure A.6.  Stepper motor connector to Basys MX3 connection. The stepper motor pink wire is not connected.}}
 //Figure A.6.  Stepper motor connector to Basys MX3 connection. The stepper motor pink wire is not connected.// //Figure A.6.  Stepper motor connector to Basys MX3 connection. The stepper motor pink wire is not connected.//
  
Line 310: Line 316:
 | 77       | RD2   | AN25/RPD2/RD2                          | LED8_R        | "                        | | 77       | RD2   | AN25/RPD2/RD2                          | LED8_R        | "                        |
 | 88       | RF1   | RPF1/PMD10/RF1                         | MODE          | Stepper motor            | | 88       | RF1   | RPF1/PMD10/RF1                         | MODE          | Stepper motor            |
-| 25       | RB0   | PGED1/AN0/RPB0/RB0                     | P32_PGC/BTNU  | Push Button              | +| 25       | RB0   | PGED1/AN0/RPB0/RB0                     | P32_PGC/BTNL  | Push Button              | 
-| 24       | RB1   | PGC1/AN1/RPB1/CTED12/RB1               | P32_PGD/BTNL  | "                        |+| 24       | RB1   | PGC1/AN1/RPB1/CTED12/RB1               | P32_PGD/BTNU  | "                        |
 | 57       | RG2   | SCL1/RG2                               | SCL           | I2C - Accelerometer      | | 57       | RG2   | SCL1/RG2                               | SCL           | I2C - Accelerometer      |
 | 56       | RG3   | SDA1/RG3                               | SDA           | "                        | | 56       | RG3   | SDA1/RG3                               | SDA           | "                        |
Line 330: Line 336:
 | 63       | RC12  | CLKI/RC12/OSC1                                                                | | 63       | RC12  | CLKI/RC12/OSC1                                                                |
 | 64       | RC15  | CLKO/RC15/OSC2                                                                | | 64       | RC15  | CLKO/RC15/OSC2                                                                |
 +
 +----
 +
 +[[{}/learn/courses/unit-2-lab2a/start|Back to Lab 2a]]
 +[[{}/learn/courses/unit-2/start|Back to Unit 2]]
 +[[{}/learn/courses/unit-3/start|Go to Unit 3]]