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:microprocessor-io-lab-1a:start [2017/03/15 17:18] – [3.2. Software:] Marthalearn:courses:microprocessor-io-lab-1a:start [2022/10/04 11:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Lab 1a: Microprocessor IO ====== ====== Lab 1a: Microprocessor IO ======
 +[[{}/learn/courses/microprocessor-io-unit-1/start|Back to Unit 1]]
 == Download This Document == == Download This Document ==
-  * {{ :learn:courses:microprocessor-io-lab-1a:lab_1a.pdf |Lab 1a PDF}}+{{ :learn:courses:microprocessor-io-lab-1a:lab_1a.pdf |Lab 1a PDF}} 
  
  
Line 21: Line 22:
 ===== 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]] 
-  * [[http://store.digilentinc.com/usb-a-to-micro-b-cable/|Standard USB A to micro-B cable]] +  - [[https://digilent.com/shop/usb-a-to-micro-b-cable/|Standard USB A to micro-B cable]] 
-  * Workstation computer running Windows 10 or higher, MAC OS, or Linux+  - Workstation computer running Windows 10 or higher, MAC OS, or Linux
  
 In addition, we suggest the following instruments: 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]]+  - [[http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,842,1018&Prod=ANALOG-DISCOVERY|Digilent Analog Discovery 2]]
  
 ==== 3.2. Software: ==== ==== 3.2. Software: ====
 The following programs must be installed on your development work station: The following programs must be installed on your development work station:
-  * [[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]]
  
  
 ---- ----
  
-===== 4. Takeaways =====+===== 4. Project Takeaways =====
   - Know how to generate a microprocessor development project using MPLAB X.   - Know how to generate a microprocessor development project using MPLAB X.
   - Know how to configure the Microchip PIC32 processor pins as either digital inputs or outputs.   - Know how to configure the Microchip PIC32 processor pins as either digital inputs or outputs.
Line 45: Line 46:
  
 ===== 5. Fundamental Concepts ===== ===== 5. Fundamental Concepts =====
-This lab focuses on control of PIC32MX370 IO pins. It consists of a simple example that demonstrates the syntax as well as a mini project. The mini project is designed to demonstrate the process for approaching software-based design of an open-ended problem and to apply the design approach given only the performance specifications. +This lab focuses on control of PIC32MX370 I/O pins. It consists of a simple example that demonstrates the syntax, as well as a mini project. The mini project is designed to demonstrate the process for approaching software-based design of an open-ended problem and to apply the design approach given only the performance specifications. 
  
 ---- ----
  
 ===== 6. Problem Statement ===== ===== 6. Problem Statement =====
-In this lab, you will be using specified switches to turn specified RED, BLUE, and GREEN colors of the tri-color LED8 either on or off using SW0, SW1, and SW2, respectively.+In this lab, you will turn the RED, BLUE, and GREEN colors of the tri-color LED8 either on or off using SW0, SW1, and SW2, respectively.
  
 ---- ----
Line 56: Line 57:
 ===== 7. Background Information ===== ===== 7. Background Information =====
 ==== 7.1. Control Registers ==== ==== 7.1. Control Registers ====
-In this lab, we will make use of the TRISx, LATx, and PORTx control registers. TRISx registers simply control the data direction flow through port I/O pins, e.g., whether a PORTx I/O pin is an input or an output. If the data direction bit is a “1”, then the corresponding PORTx I/O pin is an input, and vice versa. +In this lab, we will make use of the TRISx, LATx, and PORTx control registers. TRISx registers simply control the data direction flow through port I/O pins, e.g., whether a PORTx I/O pin is an input or an output. If the data direction bit is a “1,” then the corresponding PORTx I/O pin is an input, and vice versa. 
  
-LATx registers (PORTx data latch) hold data written to port I/O pins. A write to a LATx register latches data to the corresponding port I/O pins and those I/O port pins configured as outputs are updated. A read from a LATx resister reads the data held in the PORTx data latch, not directly from the port I/O pins (this distinction will come into play in [[https://reference.digilentinc.com/learn/courses/microprocessor-io-lab-1b/start|Lab 1b]]). +LATx registers (PORTx data latch) hold data written to port I/O pins. A write to a LATx register latches data to the corresponding port I/O pins and those I/O port pins configured as outputs are updated. A read from a LATx resister reads the data held in the PORTx data latch, not directly from the port I/O pins (this distinction will come into play in [[/learn/courses/microprocessor-io-lab-1b/start|Lab 1b]]). 
  
-PORTx registers are the registers that allow I/O pins to be accessed. A write to a PORTx register writes to the corresponding LATx register (PORTx data latch) and those I/O port pins configured as outputs are updated. This is effectively the same as writing to a LATx register. A read from a PORTx register reads the synchronized signal applied to the post I/O pins. +PORTx registers are the registers that allow I/O pins to be accessed. A write to a PORTx register writes to the corresponding LATx register (PORTx data latch) and those I/O port pins configured as outputs are updated. This is effectively the same as writing to a LATx register. A read from a PORTx register reads the synchronized signal applied to the port I/O pins. 
  
 ==== 7.2. Configuring the PIC32 for Digital Inputs ==== ==== 7.2. Configuring the PIC32 for Digital Inputs ====
-As noted from Appendix E, Table E.1 in the Unit 1 description, the eight slide switches are connected to various pins on differing IO ports of the PIC32 processor. This then requires that PIC32 pins connected to the switches must be configured as inputs either individually or in groups if multiple pins are connected to a common PIC32 port. Notice that some of these pins have an “AN” designation in the Alt column of Appendix E, Table E.1. These pins are analog capable. To be used as a digital input, port pins that can be used as analog inputs must have the analog input disabled as well as be set as an input by setting the corresponding bit in the TRIS (tristate) register to a 1. To be used as an output, this bit must be set to 0.  For example, to program SW5, SW6, and SW7 as digital inputs, the following statements must be included in the hardware initialization. The order of these statements is not critical.+As noted from Appendix E Table E.1 in the Unit 1 description, the eight slide switches are connected to various pins on differing I/O ports of the PIC32 processor. This then requires that PIC32 pins connected to the switches must be configured as inputs either individually or in groups if multiple pins are connected to a common PIC32 port. Notice that some of these pins have an “AN” designation in the Alt column of Appendix E Table E.1. These pins are analog capable. To be used as a digital input, port pins that can be used as analog inputs must have the analog input disabled as well as be set as an input by setting the corresponding bit in the TRIS (tristate) register to a 1. To be used as an output, this bit must be set to 0.  For example, to program SW5, SW6, and SW7 as digital inputs, the following statements must be included in the hardware initialization. The order of these statements is not critical.
  
 ---- ----
  
-==== Listing 7.1. Instructions for Setting Analog Inputs to be Digital Inputs fro SW5 Through SW7 ====+==== Listing 7.1. Instructions for Setting Analog Inputs to be Digital Inputs for SW5 Through SW7 ====
 <code> <code>
     TRISBbits.TRISB9  = 1; // Set Port B bit 9 for input mode (3.3V tolerant only)     TRISBbits.TRISB9  = 1; // Set Port B bit 9 for input mode (3.3V tolerant only)
Line 79: Line 80:
 ---- ----
  
-If multiple IO pins on a common processor port are to be simultaneously set, then the code in Listing 1.2 can be used. The bits do not need to be in succession and the ordering of the two statements is not critical. Only the bit positions designated as “1” will be set or cleared and all other bit positions will be unchanged by the “SET” and “CLR” instructions. +If multiple I/O pins on a common processor port are to be simultaneously set, then the code in Listing 7.2 can be used. The bits do not need to be in succession and the ordering of the two statements is not critical. Only the bit positions designated as “1” will be set or cleared and all other bit positions will be unchanged by the “SET” and “CLR” instructions. 
  
 ---- ----
Line 91: Line 92:
 ---- ----
  
-Note: If the instruction //TRISB =  0b0000111000000000;// is used, all bit positions of the TRISB register will be set according to the bit positions of the 1s and 0s.+Note: If the instruction TRISB =  0b0000111000000000; is used, all bit positions of the TRISB register will be set according to the bit positions of the 1s and 0s.
  
-If the peripheral library function is used, the statement //PORTSetPinsDigitalIn(IOPORT_B, BIT_9 | BIT_10 | BIT_11);// will both disable the analog input and set the specified TRIS register bits. This instruction is equivalent to the two statements in Listing 7.2. +If the peripheral library function is used, the statement PORTSetPinsDigitalIn(IOPORT_B, BIT_9 | BIT_10 | BIT_11); will both disable the analog input and set the specified TRIS register bits. This instruction is equivalent to the two statements in Listing 7.2. 
  
-Other PIC IO pins that serve solely as digital inputs require only the instruction to set the appropriate TRIS bit. For example, to program the PIC32 to an input for SW0, initialize using the statement //TRISFbits.TRISF3 = 1;//. +Other PIC I/O pins that serve solely as digital inputs require only the instruction to set the appropriate TRIS bit. For example, to program the PIC32 to an input for SW0, initialize using the statement TRISFbits.TRISF3 = 1;. 
  
-Figure A.1 shows that seven of the switches (SW0 through SW6) are isolated from the PIC32 processor IO pins by a 10K ohm resistor. This means the PIC32 pins could be used as outputs with no ill effect on the operations of the PIC32 processor. Note also that SW7 (PIC32 pin RB9) is connected via a voltage divider to the Analog Discovery 2 Trig2 pin. Therefore, SW7 can be used as a manual trigger for the Analog Discovery by setting RB9 as an input, or used as a software-controlled trigger by setting RB9 as an output and setting SW7 off.     +Figure A.1 shows that seven of the switches (SW0 through SW6) are isolated from the PIC32 processor I/O pins by a 10K ohm resistor. This means the PIC32 pins could be used as outputs with no ill effect on the operations of the PIC32 processor. Note also that SW7 (PIC32 pin RB9) is connected via a voltage divider to the Analog Discovery 2 Trig2 pin. Therefore, SW7 can be used as a manual trigger for the Analog Discovery 2 by setting RB9 as an input, or used as a software-controlled trigger by setting RB9 as an output and setting SW7 off.      
 +   
  
 ==== 7.3. Configuring the PIC32 for Digital Outputs ==== ==== 7.3. Configuring the PIC32 for Digital Outputs ====
-Figure A.2 shows the portion of the Basys MX3 schematic for connection to the tri-color LED.  The corresponding PIC32 pins connected to the tri-color LED must be configured as outputs. If output pins are analog capable, they must be set for digital mode operation as described above. +Figure A.2 shows the portion of the Basys MX3 schematic for connection to the tri-color LED. The corresponding PIC32 pins connected to the tri-color LED must be configured as outputs. If output pins are analog capable, they must be set for digital mode operation as described above. 
  
 ---- ----
Line 106: Line 108:
 ===== 8. Lab 1a ===== ===== 8. Lab 1a =====
 ==== 8.1. Requirements ==== ==== 8.1. Requirements ====
-This exercise uses the Basys MX3 switches SW0 through SW2 to control the red, blue, and green LEDs on the tri-colored LED labeled LED8 according to the following rules (referring to the schematic diagrams in Appendix A of this lab for additional details):+This exercise uses the Basys MX3 switches SW0 through SW2 to control the red, blue, and green LEDs on the tri-colored LED labeled LED8 according to the following rules (refer to the schematic diagrams in Appendix A of this lab for additional details):
   - SW0 is to turn the RED color of LED8 on or off.   - SW0 is to turn the RED color of LED8 on or off.
   - SW1 is to turn the BLUE color of LED8 on or off.   - SW1 is to turn the BLUE color of LED8 on or off.
   - SW2 is to turn the GREEN color of LED8 on or off.   - SW2 is to turn the GREEN color of LED8 on or off.
   - All switch combinations are allowable.   - All switch combinations are allowable.
 +
  
 ==== 8.2. Design Phase ==== ==== 8.2. Design Phase ====
Line 166: Line 169:
  
 ====== Appendix A: Schematic Drawings ====== ====== Appendix A: Schematic Drawings ======
-{{ :learn:courses:microprocessor-io-lab-1a:figure-a-1.png?nolink |Figure A.1. Slide switch schematic diagram.}}+{{ :learn:courses:microprocessor-io-lab-1a:basys_mx3_schematic_switches.png?nolink |Figure A.1. Slide switch schematic diagram.}}
 //Figure A.1. Slide switch schematic diagram.// //Figure A.1. Slide switch schematic diagram.//
  
-{{ :learn:courses:microprocessor-io-lab-1a:figure-a-2.png?nolink |Figure A.2. Schematic of PIC32 interconnection with the Tri-color LED.}}+{{ :learn:courses:microprocessor-io-lab-1a:basys_mx3_schematic_rgbled.png?nolink |Figure A.2. Schematic of PIC32 interconnection with the Tri-color LED.}}
 //Figure A.2. Schematic of PIC32 interconnection with the Tri-color LED.// //Figure A.2. Schematic of PIC32 interconnection with the Tri-color LED.//
  
-{{ :learn:courses:microprocessor-io-lab-1a:figure-a-3.png?nolink |Figure A.3. Basys MX3 LEDs.}}+{{ :learn:courses:microprocessor-io-lab-1a:basys_mx3_schematic_leds.png?nolink |Figure A.3. Basys MX3 LEDs.}}
 //Figure A.3. Basys MX3 LEDs.// //Figure A.3. Basys MX3 LEDs.//
  
Line 190: Line 193:
     - The run section must contain an infinite software loop that, under no condition, must ever end.  Typically this infinite loop is written as for(;;){ … } or while(1){ …}. The embedded application executes from the infinite loop or from interrupts that preempt this loop.     - The run section must contain an infinite software loop that, under no condition, must ever end.  Typically this infinite loop is written as for(;;){ … } or while(1){ …}. The embedded application executes from the infinite loop or from interrupts that preempt this loop.
  
 +----
 +
 +[[{}/learn/courses/microprocessor-io-unit-1/start|Back to Unit 1]]
 +[[{}/learn/courses/microprocessor-io-lab-1b/start|Go to Lab 1b]]