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/04/04 11:59] – [7.1. Analog Speed Control] Marthalearn:courses:unit-6-lab6a:start [2021/10/13 15:23] (current) Arthur Brown
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 |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.//
-{{ :learn:courses:unit-6-lab6a:lab6a-fig-7-1.png?nolink |}}+ 
 ==== 7.2. Motor Speed Indication ==== ==== 7.2. Motor Speed Indication ====
 Section 7.2.1 of the Unit 6 tutorial describes the details of measuring the period of the pulse output of a digital tachometer. Listing B.3 and B.4 of this text present the code for initializing the input capture to generate an interrupt on every positive transition and the interrupt service routine that computes the period between successive captures. Since the period measurement is instantaneous, it is very sensitive to input noise. One means of reducing the effects of noise on a measurement is to implement a low-pass filter using a [[http://www.analog.com/media/en/technical-documentation/dsp-book/dsp_book_Ch15.pdf|moving average]] (MA) algorithm. This common smoothing algorithm is expressed in Eq. 7.1. The smooth output, //y[i]//, requires the N-1 past inputs to be summed and that sum to be divided by the value of N. The filter expressed in Eq. 7.1 is a non-recursive implementation that only uses past inputs to generate the newest output average. It requires N addition operations and one division as well as N-1 memory locations. Section 7.2.1 of the Unit 6 tutorial describes the details of measuring the period of the pulse output of a digital tachometer. Listing B.3 and B.4 of this text present the code for initializing the input capture to generate an interrupt on every positive transition and the interrupt service routine that computes the period between successive captures. Since the period measurement is instantaneous, it is very sensitive to input noise. One means of reducing the effects of noise on a measurement is to implement a low-pass filter using a [[http://www.analog.com/media/en/technical-documentation/dsp-book/dsp_book_Ch15.pdf|moving average]] (MA) algorithm. This common smoothing algorithm is expressed in Eq. 7.1. The smooth output, //y[i]//, requires the N-1 past inputs to be summed and that sum to be divided by the value of N. The filter expressed in Eq. 7.1 is a non-recursive implementation that only uses past inputs to generate the newest output average. It requires N addition operations and one division as well as N-1 memory locations.
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 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 458: 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]]