Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| learn:courses:microprocessor-io-lab-1b:start [2017/03/15 17:51] – [7.1. Control Registers] Martha | learn:courses:microprocessor-io-lab-1b:start [2022/10/04 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Lab 1b: Microprocessor | + | ====== Lab 1b: Microprocessor |
| + | [[{}/ | ||
| + | [[{}/ | ||
| == Download This Document == | == Download This Document == | ||
| - | * {{ : | + | {{ : |
| ===== 1. Objectives ===== | ===== 1. Objectives ===== | ||
| Line 19: | Line 20: | ||
| - How to write a computer program using the [[http:// | - How to write a computer program using the [[http:// | ||
| - How to launch a [[http:// | - How to launch a [[http:// | ||
| - | - How to configure the PIC32 I/O pins for digital input and output (See [[https:// | + | - How to configure the PIC32 I/O pins for digital input and output (See [[/ |
| Line 29: | Line 30: | ||
| ===== 3. Equipment List ===== | ===== 3. Equipment List ===== | ||
| ==== 3.1. Hardware ==== | ==== 3.1. Hardware ==== | ||
| - | | + | |
| - | | + | |
| - | | + | |
| In addition, we suggest the following instruments: | In addition, we suggest the following instruments: | ||
| - | | + | |
| Line 60: | Line 61: | ||
| ===== 6. Problem Statement ===== | ===== 6. Problem Statement ===== | ||
| - | The objective of this lab is to program the PIC32 processor to implement the functionality of a simple integer calculator that displays the result of X (?) Y where the operator, | + | The objective of this lab is to program the PIC32 processor to implement the functionality of a simple integer calculator that displays the result of X • Y where the operator, |
| ---- | ---- | ||
| Line 75: | Line 76: | ||
| The disparate assignments of processor IO pins connected to the eight slide switch inputs makes it imperative to use bit reading instructions. The instruction “s0 = PORTFbits.RF3; | The disparate assignments of processor IO pins connected to the eight slide switch inputs makes it imperative to use bit reading instructions. The instruction “s0 = PORTFbits.RF3; | ||
| + | < | ||
| X=PORTFbits.RF3+(PORTFbits.RF5≪1)+(PORTFbits.RF4≪2)+(PORTDbits.RD15≪3); | X=PORTFbits.RF3+(PORTFbits.RF5≪1)+(PORTFbits.RF4≪2)+(PORTDbits.RD15≪3); | ||
| + | </ | ||
| Similarly, an expression can be created that will generate a value for another variable, Y, using SW4 through SW7. | Similarly, an expression can be created that will generate a value for another variable, Y, using SW4 through SW7. | ||
| ==== 7.3. Using the Push Button’s Inputs ==== | ==== 7.3. Using the Push Button’s Inputs ==== | ||
| - | As with the slide switches, the push buttons must be individually set as PIC32 inputs. BTNR, BTNL, and BTNU are analog pins, and hence require disabling the analog input. Remember that PIC32 IO pins that also function as analog inputs must have the appropriate ANSELx bit set low. The state of the BTND push buttons can be read using the following C statement: | + | As with the slide switches, the push buttons must be individually set as PIC32 inputs. BTNR, BTNL, and BTNU are analog pins, and hence require disabling the analog input. Remember that PIC32 I/O pins that also function as analog inputs must have the appropriate ANSELx bit set low. The state of the BTND push buttons can be read using the following C statement: |
| + | < | ||
| BTND=PORTAbits.RA15; | BTND=PORTAbits.RA15; | ||
| + | </ | ||
| - | Figure A.1 shows that these five processor signals all have alternate uses. BTNR, BTND, and BTNC can be used as outputs for controlling servo motors and triggering the Analog Discovery 2. The 10K ohm resistors in series with the push buttons allow the buttons to be pressed with no effect on the PIC32 when these pins are configured as outputs. | + | Figure A.1 shows that these five processor signals all have alternate uses. BTNR, BTND, and BTNC can be used as outputs for controlling servo motors and triggering the Analog Discovery 2. The 10K ohm resistors in series with the push buttons allow the buttons to be pressed with no effect on the PIC32 when these pins are configured as outputs. |
| - | + | ||
| - | BTNL and BTNU are also used for MPLAB debugging and processor programming that renders them unavailable for push button inputs while the MPLAB X debugger is running. The PIC32 must be programmed for stand-alone operation to allow using BTNL and BTNU for inputs to the PIC32. | + | |
| + | BTNL and BTNU are also used for MPLAB debugging and processor programming that renders them unavailable for push button inputs while the MPLAB X debugger is running. The PIC32 must be programmed for standalone operation to allow using BTNL and BTNU for inputs to the PIC32. | ||
| - | ==== 7.4. Using a Seven Segment Display ==== | ||
| - | As previously discussed for the slide switch and push button inputs, the seven segment LED controls are scattered over multiple ports and pins. Again, Table E.1 of Unit 1 must be used to identify those pins that need to have the analog functionality disabled. Each segment should be set on or off using the LATxSET = BIT_xx and LATxCLR = BIT_xx instructions. | ||
| - | The particular [[http:// | + | |
| + | ==== 7.4. Using a 7-Segment Display ==== | ||
| + | As previously discussed for the slide switch and push button inputs, the 7-segment LED controls are scattered over multiple ports and pins. Again, Table E.1 of Unit 1 must be used to identify those pins that need to have the analog functionality disabled. Each segment should be set on or off using the LATxSET = BIT_xx and LATxCLR = BIT_xx instructions. | ||
| + | |||
| + | The particular [[http:// | ||
| + | |||
| ---- | ---- | ||
| Line 105: | Line 112: | ||
| LATDCLR = BIT_7; // Segment F on | LATDCLR = BIT_7; // Segment F on | ||
| LATDCLR = BIT_13; // Segment G on | LATDCLR = BIT_13; // Segment G on | ||
| - | LATGSET = BIT_14; // Segment DP off | + | LATGSET = BIT_14; // Segment DP off |
| LATBSET = BIT_12; // Display 0 off | LATBSET = BIT_12; // Display 0 off | ||
| LATBSET = BIT_13; // Display 1 off | LATBSET = BIT_13; // Display 1 off | ||
| Line 118: | Line 125: | ||
| Variations of the code in Listing 7.1 must be used to light different numbers on each of the four digits. The last four instructions select the display digit. | Variations of the code in Listing 7.1 must be used to light different numbers on each of the four digits. The last four instructions select the display digit. | ||
| - | ==== 7.5. Persistence: | + | |
| - | The display in Fig. 8.2 appears to have LED segments in three digits simultaneously displayed. As just discussed, the cathodes of all four of the seven segment LEDs are connected in parallel and the particular digit is selected by asserting the common anode pin high. In order to make the four-digit display appear that all four LED digits are simultaneously on, one should make sure each digit is displayed for a minimum of 1 millisecond. Listing 7.2 provides a simple software delay. Since this delay is dependent on the speed of execution, the “ms_cnt” will need to be changed depending on the speed of the core frequency. For the example shown in Listing 7.2, the ms_cnt value of 1000 is set to generate a one ms delay when the core frequency is set to 80 MHz. | + | ==== 7.5. Persistence: |
| + | The display in Fig. 8.2 appears to have LED segments in three digits simultaneously displayed. As just discussed, the cathodes of all four of the 7-segment LEDs are connected in parallel and the particular digit is selected by asserting the common anode pin high. In order to make the 4-digit display appear that all four LED digits are simultaneously on, one should make sure each digit is displayed for a minimum of 1 millisecond. Listing 7.2 provides a simple software delay. Since this delay is dependent on the speed of execution, the “ms_cnt” will need to be changed depending on the speed of the core frequency. For the example shown in Listing 7.2, the ms_cnt value of 10000 is set to generate a one ms delay when the core frequency is set to 80 MHz. | ||
| ---- | ---- | ||
| Line 127: | Line 135: | ||
| void sw_delay(int ms) | void sw_delay(int ms) | ||
| { | { | ||
| - | unsigned int ms_cnt; // 1 ms counter | + | unsigned int ms_cnt; |
| - | while(ms--) // ms loop counter | + | while(ms--) |
| { | { | ||
| - | ms_cnt = 10000; // Reset ms counter | + | ms_cnt = 10000; |
| - | while(--ms_cnt); | + | while(--ms_cnt); |
| } | } | ||
| } | } | ||
| Line 140: | Line 148: | ||
| ===== 8. Lab 1b ===== | ===== 8. Lab 1b ===== | ||
| ==== 8.1. Development Plan ==== | ==== 8.1. Development Plan ==== | ||
| - | Follow the system design plan presented in the Unit 1 description | + | Follow the system design plan presented in Unit 1 by completing the actions described in steps 1 through 5 of Table 8.1. After the planning activity has been completed, proceed to the design phase by setting up your development environment. Note that a test plan is included in the list of activities so that any test hardware and or software is included in the overall design. |
| **Table 8.1. Software based system work flow.** | **Table 8.1. Software based system work flow.** | ||
| Line 155: | Line 163: | ||
| ==== 8.2. Project Requirements ==== | ==== 8.2. Project Requirements ==== | ||
| - | Using the five push buttons and eight slide switches | + | Using the five push buttons and eight slide switches |
| **Table 8.2. Button operation.** | **Table 8.2. Button operation.** | ||
| Line 166: | Line 174: | ||
| | BTNL (1) | CLEAR RESULT: Result = 0 | | | BTNL (1) | CLEAR RESULT: Result = 0 | | ||
| - | Note 1. BTNU and BTNL can only be implemented when MPLAB is not in debug mode. | + | Note 1: BTNU and BTNL can only be implemented when MPLAB is not in debug mode (see hardware.h in Unit 1, Appendix C). |
| - | The eight slide switches shown in Fig. 8.1 are divided into two groups of four switches to generate values for X and Y by setting the switches in a binary fashion | + | The eight slide switches shown in Fig. 8.1 are divided into two groups of four switches to generate values for X and Y by setting the switches in a binary fashion. The X and Y values |
| $$X=(SW0 \cdot 2^0) + (SW1 \cdot 2^1)+(SW2 \cdot 2^2)+(SW3 \cdot 2^3) Eq.1$$ | $$X=(SW0 \cdot 2^0) + (SW1 \cdot 2^1)+(SW2 \cdot 2^2)+(SW3 \cdot 2^3) Eq.1$$ | ||
| Line 176: | Line 184: | ||
| Where SW0 through SW7 has a value of one if in the on (up) position, or zero if in the off (down) position. | Where SW0 through SW7 has a value of one if in the on (up) position, or zero if in the off (down) position. | ||
| - | {{ : | + | {{ : |
| //Figure 8.1. Partitioning of switches assigned to variables X and Y.// | //Figure 8.1. Partitioning of switches assigned to variables X and Y.// | ||
| The mathematical operation on variables X and Y produce a new result that is displayed on the four digit seven-segment display, as shown in Fig. 8.2, whenever one of the push buttons is pressed. The operations associated with the push buttons are shown in the green text in Fig. 8.3. (Note: BTNL and BTNU are not functional when MPLAB X is running in debug mode.) | The mathematical operation on variables X and Y produce a new result that is displayed on the four digit seven-segment display, as shown in Fig. 8.2, whenever one of the push buttons is pressed. The operations associated with the push buttons are shown in the green text in Fig. 8.3. (Note: BTNL and BTNU are not functional when MPLAB X is running in debug mode.) | ||
| - | {{ : | + | {{ : |
| - | //Figure 8.2. Four digit- | + | //Figure 8.2. 4-digit 7-segment display.// |
| - | {{ : | + | {{ : |
| //Figure 8.3. Operator assignments to push buttons.// | //Figure 8.3. Operator assignments to push buttons.// | ||
| Line 236: | Line 244: | ||
| - Consider the case when pin RF0 is programmed to be an input and the signal TRIG_1 is a digital output signal from an external device that is either 0 or 3.3V. What effect will pressing the BTNC button have on the processor RF0 pin when TRIG_1 is low and when it is high? | - Consider the case when pin RF0 is programmed to be an input and the signal TRIG_1 is a digital output signal from an external device that is either 0 or 3.3V. What effect will pressing the BTNC button have on the processor RF0 pin when TRIG_1 is low and when it is high? | ||
| - Consider the case when pin RF0 is programmed to be an output and the signal TRIG_1 is a digital input signal to an external device. What effect will pressing the BTNC button have on the TRIG_1 signal when the RF0 output is low and when it is high? | - Consider the case when pin RF0 is programmed to be an output and the signal TRIG_1 is a digital input signal to an external device. What effect will pressing the BTNC button have on the TRIG_1 signal when the RF0 output is low and when it is high? | ||
| - | - Measure the loop execution time by toggling Pmod connector JA pin 1 at the start of the loop execution using the instruction | + | - Measure the loop execution time by toggling Pmod connector JA pin 1 at the start of the loop execution using the instruction |
| - What is this time? | - What is this time? | ||
| - Is this time expected? | - Is this time expected? | ||
| Line 250: | Line 258: | ||
| ====== Appendix A: Schematic Drawings ====== | ====== Appendix A: Schematic Drawings ====== | ||
| - | {{ : | + | {{ : |
| //Figure A.1 Push button schematic diagram.// | //Figure A.1 Push button schematic diagram.// | ||
| - | {{ : | + | {{ : |
| //Figure A.2 Schematic diagram of Basys MX3 slide switches.// | //Figure A.2 Schematic diagram of Basys MX3 slide switches.// | ||
| - | {{ : | + | {{ : |
| //Figure A.3 Four digit seven segment display schematic.// | //Figure A.3 Four digit seven segment display schematic.// | ||
| + | ---- | ||
| + | |||
| + | [[{}/ | ||
| + | [[{}/ | ||

