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-6-lab6a:start [2017/03/28 21:00] – [8.4. Testing] Marthalearn:courses:unit-6-lab6a:start [2022/10/04 11:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Lab 6a: Open-loop Process Control ====== ====== Lab 6a: Open-loop Process Control ======
 +[[{}/learn/courses/unit-6/start|Back to Unit 6]]
  
 === Download This Document === === Download This Document ===
-  * {{ :learn:courses:unit-6-lab6a:lab_6a.pdf |Lab 6a PDF}}+{{ :learn:courses:unit-6-lab6a:lab_6a.pdf |Lab 6a PDF}}
  
  
 ===== 1. Objectives ===== ===== 1. Objectives =====
-  * Generate PWM outputs to implement analog motor supply voltage. +  - Generate PWM outputs to implement analog motor supply voltage. 
-  * Implement a tachometer operation using PIC32 Timers. +  - Implement a tachometer operation using PIC32 Timers. 
-  * Develop MPLAB X projects that implement open-loop and closed-loop motor control. +  - Develop MPLAB X projects that implement open-loop and closed-loop motor control. 
-  * Develop C program code to implement a PI controller and a moving averaging digital filter. +  - Develop C program code to implement a PI controller and a moving averaging digital filter. 
-  * Manage multiple background tasks in an interrupt driven system. +  - Manage multiple background tasks in an interrupt driven system. 
-  * Send real time data monitoring devices.+  - Send real time data monitoring devices.
  
  
Line 17: Line 18:
  
 ===== 2. Basic Knowledge ===== ===== 2. Basic Knowledge =====
-  * How to configure pins on a Microchip® PIC32 PPS microprocessor.  +  - How to configure pins on a Microchip® PIC32 PPS microprocessor.  
-  * How to implement a real-time system using preemptive foreground – background task control. +  - How to implement a real-time system using preemptive foreground – background task control. 
-  * How to generate a PWM output with the PIC32 processor. +  - How to generate a PWM output with the PIC32 processor. 
-  * How to configure the Analog Discovery 2 to display logic traces. +  - How to configure the Analog Discovery 2 to display logic traces. 
-  * How to implement the design process for embedded processor based systems.+  - How to implement the design process for embedded processor based systems.
  
  
Line 28: Line 29:
 ===== 3. Equipment List ===== ===== 3. Equipment List =====
 ==== 3.1. Hardware ==== ==== 3.1. Hardware ====
-  * [[http://store.digilentinc.com/basys-mx3-pic32mx-trainer-board-recommended-for-embedded-systems-courses/|Basys MX3 trainer board]] +  - [[https://digilent.com/shop/basys-mx3-pic32mx-trainer-board-for-embedded-systems-courses/|Basys MX3 trainer board]] 
-  * Workstation computer running Windows 10 or higher, MAC OS, or Linux +  - Workstation computer running Windows 10 or higher, MAC OS, or Linux 
-  * 2 [[http://store.digilentinc.com/usb-a-to-micro-b-cable/|Standard USB A to micro-B cables]] +  - 2 [[https://digilent.com/shop/usb-a-to-micro-b-cable/|Standard USB A to micro-B cables]] 
-  * [[http://store.digilentinc.com/motor-gearbox-1-19-gear-ratio-custom-12v-motor-designed-for-digilent-robot-kits/|5V DC motor with tachometer]] +  - [[https://digilent.com/shop/dc-motor-gearbox-1-19-gear-ratio-custom-12v-motor-designed-for-digilent-robot-kits/|12 V DC motor with tachometer]] 
-  * [[http://store.digilentinc.com/5v-2-5a-switching-power-supply/|5V, 2.5A power supply]]+  - [[https://digilent.com/shop/5v-4a-switching-power-supply/|5V, 4A DC power supply]]
  
 In addition, we suggest the following instruments: In addition, we suggest the following instruments:
  
-  * [[http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/|Analog Discovery 2]]  +  - [[https://digilent.com/shop/analog-discovery-2-100ms-s-usb-oscilloscope-logic-analyzer-and-variable-power-supply/|Analog Discovery 2]]  
-  * [[http://store.digilentinc.com/autorange-digital-multimeter-ms8217/|Digital Multimeter]]+  - [[https://digilent.com/shop/ms8217-autorange-digital-multimeter/|Digital Multimeter]]
  
  
 ==== 3.2. Software: ==== ==== 3.2. Software: ====
 The following programs must be installed on your development workstation: The following programs must be installed on your development workstation:
-  * [[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/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://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]] +  - [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]] 
-  * [[http://store.digilentinc.com/waveforms-2015-download-only/|WaveForms 2015]] (if using the Analog Discovery 2) +  - [[https://digilent.com/shop/software/digilent-waveforms/|WaveForms]] (if using the Analog Discovery 2) 
-  * [[http://www.putty.org/|PuTTY Terminal Emulation]] +  - [[http://www.putty.org/|PuTTY Terminal Emulation]] 
-  * Spreadsheet application (such as Microsoft Excel)+  - Spreadsheet application (such as Microsoft Excel)
  
  
Line 53: Line 54:
  
 ===== 4. Project Takeaways ===== ===== 4. Project Takeaways =====
-  * How to read analog voltage with a PIC32 processor. +  - How to read analog voltage with a PIC32 processor. 
-  * How to use the PIC32 Output Compare to implement a PWM analog output. +  - How to use the PIC32 Output Compare to implement a PWM analog output. 
-  * How to use the PIC32 Timer and Input Capture to implement a tachometer. +  - How to use the PIC32 Timer and Input Capture to implement a tachometer. 
-  * Fundamental analog and filtering concepts for data smoothing and open-loop control.+  - Fundamental analog and filtering concepts for data smoothing and open-loop control.
  
  
Line 64: Line 65:
 [[https://en.wikipedia.org/wiki/Open-loop_controller|Open-loop control]] involves one or more inputs, some type of conversion or means of combining the values of the inputs, and one or more outputs represented by the block diagram in Fig. 5.1. As was demonstrated in Unit 2, [[https://en.wikipedia.org/wiki/Stepper_motor|stepper motors]] are often used for open-loop control of position. A stepper motor rotates to one of a number of fixed positions, according to its internal construction. Sending a stream of electrical pulses to it causes it to rotate by exactly that many steps, hence the name. Such motors are often used, together with a simple initial datum sensor (a switch that is activated at the machine's home position), for the control of simple robotic machines such as the commonplace [[https://en.wikipedia.org/wiki/Inkjet_printer|inkjet printer]] head. The drawback of open-loop control of steppers is that if the machine load is too high, or if the motor attempts to move too quickly, then steps may be skipped. The controller has no means of detecting this and so the machine continues to run slightly out of adjustment, until reset. For this reason, more complex robots and machine tools instead use [[https://en.wikipedia.org/wiki/Servomotor|servomotors]] rather than stepper motors, which incorporate position [[https://en.wikipedia.org/wiki/Rotary_encoder|encoders]] and [[https://en.wikipedia.org/wiki/Closed-loop_controller|closed-loop controllers]].((Open-Loop Controller, [[https://en.wikipedia.org/wiki/Open-loop_controller|https://en.wikipedia.org/wiki/Open-loop_controller]])) [[https://en.wikipedia.org/wiki/Open-loop_controller|Open-loop control]] involves one or more inputs, some type of conversion or means of combining the values of the inputs, and one or more outputs represented by the block diagram in Fig. 5.1. As was demonstrated in Unit 2, [[https://en.wikipedia.org/wiki/Stepper_motor|stepper motors]] are often used for open-loop control of position. A stepper motor rotates to one of a number of fixed positions, according to its internal construction. Sending a stream of electrical pulses to it causes it to rotate by exactly that many steps, hence the name. Such motors are often used, together with a simple initial datum sensor (a switch that is activated at the machine's home position), for the control of simple robotic machines such as the commonplace [[https://en.wikipedia.org/wiki/Inkjet_printer|inkjet printer]] head. The drawback of open-loop control of steppers is that if the machine load is too high, or if the motor attempts to move too quickly, then steps may be skipped. The controller has no means of detecting this and so the machine continues to run slightly out of adjustment, until reset. For this reason, more complex robots and machine tools instead use [[https://en.wikipedia.org/wiki/Servomotor|servomotors]] rather than stepper motors, which incorporate position [[https://en.wikipedia.org/wiki/Rotary_encoder|encoders]] and [[https://en.wikipedia.org/wiki/Closed-loop_controller|closed-loop controllers]].((Open-Loop Controller, [[https://en.wikipedia.org/wiki/Open-loop_controller|https://en.wikipedia.org/wiki/Open-loop_controller]]))
  
-{{ :learn:courses:unit-6-lab6a:lab6a-fig-5-1.png?nolink&600 |Figure 5.1. Open-loop motor control block diagram.}}+{{ :learn:courses:unit-6-lab6a:lab_6a_fig_5_1.jpg?nolink&600 |Figure 5.1. Open-loop motor control block diagram.}}
 //Figure 5.1. Open-loop motor control block diagram.// //Figure 5.1. Open-loop motor control block diagram.//
 +
  
 ---- ----
Line 80: Line 82:
 The potentiometer labeled the Analog Input Control (R134) on the Basys MX3 trainer board, as shown in Fig. 7.1, will be used as the input for controlling the motor speed. The potentiometer wiper terminal is connected to the PIC32MX370 processor Port B pin 2. Using the PIC32 analog-to-digital converter (ADC) is rather straightforward with the aid of the example code provided by the MPLAB X Help for the XC32 Peripheral Libraries. Listing B.1 in Appendix B shows how to initialize an ADC channel to continuously sample and convert analog data. Listing B.2 is example code to read the most recent ADC conversion and call functions to set the motor direction of rotation and speed. The motor control is discussed in section 7.4 below.   The potentiometer labeled the Analog Input Control (R134) on the Basys MX3 trainer board, as shown in Fig. 7.1, will be used as the input for controlling the motor speed. The potentiometer wiper terminal is connected to the PIC32MX370 processor Port B pin 2. Using the PIC32 analog-to-digital converter (ADC) is rather straightforward with the aid of the example code provided by the MPLAB X Help for the XC32 Peripheral Libraries. Listing B.1 in Appendix B shows how to initialize an ADC channel to continuously sample and convert analog data. Listing B.2 is example code to read the most recent ADC conversion and call functions to set the motor direction of rotation and speed. The motor control is discussed in section 7.4 below.  
  
-{{ :learn:courses:unit-6-lab6a:lab6a-fig-7-1.png?nolink&600 |Figure 7.1. Analog Input Control schematic diagram.}}+{{ :learn:courses:unit-6-lab6a:lab_6a_fig_7.1.jpg?nolink&700 |Figure 7.1. Analog Input Control schematic diagram.}}
 //Figure 7.1. Analog Input Control schematic diagram.// //Figure 7.1. Analog Input Control schematic diagram.//
 +
  
 ==== 7.2. Motor Speed Indication ==== ==== 7.2. Motor Speed Indication ====
Line 97: Line 100:
 In this lab we will be using a [[https://en.wikipedia.org/wiki/Brushed_DC_electric_motor|permanent magnet brushed DC motor]], as shown in Fig. 7.2, where the speed of a DC motor is proportional to the applied DC voltage. References 3 and 4 provide insight on the speed control characteristics of this type of electric motor. The characteristic of interest to us is that the speed of the motor is roughly proportional to the applied DC voltage. The challenge for Lab 6a is how best to generate a variable DC motor supply using the PIC32 processor. In this lab we will be using a [[https://en.wikipedia.org/wiki/Brushed_DC_electric_motor|permanent magnet brushed DC motor]], as shown in Fig. 7.2, where the speed of a DC motor is proportional to the applied DC voltage. References 3 and 4 provide insight on the speed control characteristics of this type of electric motor. The characteristic of interest to us is that the speed of the motor is roughly proportional to the applied DC voltage. The challenge for Lab 6a is how best to generate a variable DC motor supply using the PIC32 processor.
  
-{{ :learn:courses:unit-6-lab6a:unit_6_-_photo_1.jpg?nolink&600 |Figure 7.2. DC Motor with digital tachometer.}}+{{ :learn:courses:unit-6-lab6a:unit_6_-_photo_1.jpg?nolink&400 |Figure 7.2. DC Motor with digital tachometer.}}
 //Figure 7.2. DC Motor with digital tachometer.// //Figure 7.2. DC Motor with digital tachometer.//
  
Line 103: Line 106:
  
  
-{{ :learn:courses:unit-6-lab6a:lab6a-fig-7-3.png?nolink&600 |Figure 7.3. Basys MX3 Motor driver circuit.}}+{{ :learn:courses:unit-6-lab6a:lab_6a_fig_7.3.jpg?nolink&600 |Figure 7.3. Basys MX3 Motor driver circuit.}}
 //Figure 7.3. Basys MX3 Motor driver circuit.// //Figure 7.3. Basys MX3 Motor driver circuit.//
 +
  
 **Table 7.1. Motor driver IC7 connection to PIC32 processor.** **Table 7.1. Motor driver IC7 connection to PIC32 processor.**
-^ Function  ^ IC7 Pin  ^ PIC32 Port Pin  ^ Function                ^ Motor COnnector  ^+^ Function  ^ IC7 Pin  ^ PIC32 Port Pin  ^ Function                ^ Motor Connector  ^
 | AIN1      | 10       | RB3             | Motor Supply +          | Red              | | AIN1      | 10       | RB3             | Motor Supply +          | Red              |
 | BIN1      | 8        | RE9             | Not Used - Set to zero  |                  | | BIN1      | 8        | RE9             | Not Used - Set to zero  |                  |
Line 133: Line 137:
 ---- ----
  
-===== Lab 6b =====+===== 8. Lab 6a =====
 ==== 8.1. Requirements ==== ==== 8.1. Requirements ====
   - Phase 1: Background Tasks   - Phase 1: Background Tasks
Line 189: Line 193:
   - Phase 2 Construction   - Phase 2 Construction
     - Attach the workstation monitor and launch the terminal emulator application.     - Attach the workstation monitor and launch the terminal emulator application.
-    - Port in the LCD code from [[https://reference.digilentinc.com/learn/courses/unit-3-lab3a/start|Lab 3a]] or [[https://reference.digilentinc.com/learn/courses/unit-3-lab3b/start|3b]] into this project and display the motor Analog Control Input value, the percentage PWM and the motor speed in RPM. +    - Port in the LCD code from [[/learn/courses/unit-3-lab3a/start|Lab 3a]] or [[/learn/courses/unit-3-lab3b/start|3b]] into this project and display the motor Analog Control Input value, the percentage PWM and the motor speed in RPM. 
-    - Port the UART code from [[https://reference.digilentinc.com/learn/courses/unit-4-lab4a/start|Lab 4a]] into this project and initialize for 38000 BAUD with no parity.+    - Port the UART code from [[/learn/courses/unit-4-lab4a/start|Lab 4a]] into this project and initialize for 38000 BAUD with no parity.
     - Modify the background task to update the LCD and UART once each 250 ms.      - Modify the background task to update the LCD and UART once each 250 ms. 
  
Line 207: Line 211:
     - Plot the motor speed vs. percent PWM as demonstrated in Fig. 8.3. All motors have different power-speed characteristics.     - Plot the motor speed vs. percent PWM as demonstrated in Fig. 8.3. All motors have different power-speed characteristics.
  
-{{ :learn:courses:unit-6-lab6a:lab6a-fig-8-1.png?nolink&800 |Figure 8.1. H-Bridge inputs for CW motor rotation for 60% PWM.}}+{{ :learn:courses:unit-6-lab6a:lab_6a_fig_8_1.png?nolink&1100 |Figure 8.1. H-Bridge inputs for CW motor rotation for 60% PWM.}}
 //Figure 8.1. H-Bridge inputs for CW motor rotation for 60% PWM.// //Figure 8.1. H-Bridge inputs for CW motor rotation for 60% PWM.//
  
-{{ :learn:courses:unit-6-lab6a:lab6a-fig-8-2.png?nolink&800 |Figure 8.2. H-Bridge inputs for CCW motor rotation for 60% PWM.}}+{{ :learn:courses:unit-6-lab6a:lab_6a_fig_8_2.png?nolink&1100 |Figure 8.2. H-Bridge inputs for CCW motor rotation for 60% PWM.}}
 //Figure 8.2. H-Bridge inputs for CCW motor rotation for 60% PWM.// //Figure 8.2. H-Bridge inputs for CCW motor rotation for 60% PWM.//
 +
  
 {{ :learn:courses:unit-6-lab6a:lab6a-fig-8-3.png?nolink&600 |Figure 8.3. Example plot of motor speed vs. %PWM.}} {{ :learn:courses:unit-6-lab6a:lab6a-fig-8-3.png?nolink&600 |Figure 8.3. Example plot of motor speed vs. %PWM.}}
Line 221: Line 226:
 ===== 9. Questions ===== ===== 9. Questions =====
 1. After plotting the data in Phase 2 testing part c, describe the resulting curve.\\ 1. After plotting the data in Phase 2 testing part c, describe the resulting curve.\\
- 
-<color #ed1c24>ANSWER:\\ 
-The curve demonstrates that the faster the motor is turning; the more input power is required to increase the motor speed.</color>\\ 
  
 2. Explain whether Input Capture, Timer 2, or Timer 3 should be set to the higher interrupt level.\\ 2. Explain whether Input Capture, Timer 2, or Timer 3 should be set to the higher interrupt level.\\
- 
-<color #ed1c24>ANSWER:\\ 
-Timer 2 and Timer 3 have no effect on the PWM output operation hence the Input Capture, should have the highest interrupt priority.</color>\\ 
  
 3. If Input Capture, Timer 2, and Timer 3 are set at the same priority level, explain which interrupt should be set to the higher sub interrupt level.\\ 3. If Input Capture, Timer 2, and Timer 3 are set at the same priority level, explain which interrupt should be set to the higher sub interrupt level.\\
- 
-<color #ed1c24>ANSWER:\\ 
-The answer is essentially the same as for question 2.</color>\\ 
  
 4. Explain the difference in interrupt operation between question 2 and question 3.\\ 4. Explain the difference in interrupt operation between question 2 and question 3.\\
- 
-<color #ed1c24>ANSWER:\\ 
-The interrupt scheme described in question 2 results in nesting interrupts where interrupts can interrupt ISRs. The scheme described in question 3 describes the order of execution when multiple interrupts are simultaneously pending.</color>\\ 
  
 5. Consider the case when the motor draws more current than can be supplied by a single H-Bridge driver and the outputs from A1 must be in parallel with B1 and A2 in parallel with B2. What effect on motor operations does changing the primary output compare registers (OCxR) instead of the secondary output compare registers (OCxRS)?\\ 5. Consider the case when the motor draws more current than can be supplied by a single H-Bridge driver and the outputs from A1 must be in parallel with B1 and A2 in parallel with B2. What effect on motor operations does changing the primary output compare registers (OCxR) instead of the secondary output compare registers (OCxRS)?\\
- 
-<color #ed1c24>ANSWER:\\ 
-Setting the OCxR registers result in the PWM duty cycle being changes as soon as the timer matches the OCxR register value. Since the OCxR registers are set with individual code instructions, the PWM outputs can wind up changing at different times. If, perchance driver outputs for AIN1 and BIN1 or AIN2 and BIN2 are at opposite binary values instead of the same value, the external supply would be shorted by output A1 high and B1 low. Understandably, the duration of this faulted condition could be kept quite short if the code is written correctly. However, since requirements specify that the OCxR registers are to be changed in the background, it is probable that eventually an interrupt will occur while the changes are being implemented thus extending the period where such a faulted condition can occur.\\ 
- 
-Unless the OCxRS is set as well as the OCxR register, the OCxR register will be set to whatever value the OCxRS register is currently set to.\\ 
- 
-By setting the OCxRS secondary registers, the changes of all PWM outputs are guaranteed to be delayed at least one PWM period. For the specified implementation, this allows at least one millisecond to set all OCxRS registers and deal with the time to execute any preemption code.</color>\\ 
  
 ---- ----
Line 477: Line 463:
 } }
 </code> </code>
 +
 +----
 +
 +[[{}/learn/courses/unit-6/start|Back to Unit 6]]
 +[[{}/learn/courses/unit-6-lab6b/start|Go to Lab 6b]]
 +[[{}/learn/courses/unit-7/start|Go to Unit 7]]