Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
learn:courses:microprocessor-io-unit-1:start [2017/03/14 09:45] – Martha | learn:courses:microprocessor-io-unit-1:start [2021/10/13 15:24] (current) – Arthur Brown | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Unit 1: Microprocessor | + | ====== Unit 1: Microprocessor |
+ | [[{}/ | ||
==Unit 1 Labs== | ==Unit 1 Labs== | ||
- | * [[https:// | + | * [[/ |
- | * [[https:// | + | * [[/ |
== Download This Document == | == Download This Document == | ||
- | * {{ : | + | {{ : |
===== 1. Introduction and Chapter Objectives ===== | ===== 1. Introduction and Chapter Objectives ===== | ||
- | The goal for this series of laboratory designs is to teach not only how to manage the PIC32 processor to solve engineering design problems, but also how to produce [[https:// | + | The goal for this series of laboratory designs is to teach not only how to manage the PIC32 processor to solve engineering design problems, but also how to produce [[https:// |
---- | ---- | ||
- | ===== 2. Objectives: ===== | + | ===== 2. Objectives ===== |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | ===== 3. Basic Knowledge: ===== | ||
- | * Fundamentals of digital [[https:// | ||
- | * How to interpret a schematic diagram and electric circuits. | ||
- | * How to write a computer program using the [[http:// | ||
- | * How to launch a Microchip [[http:// | ||
- | ===== 4. Equipment | + | ---- |
- | ==== Hardware: ==== | + | |
- | | + | ===== 3. Basic Knowledge ===== |
- | * Basys MX3 processor | + | - Fundamentals of digital [[https:// |
- | | + | - How to interpret a schematic diagram and electric circuits. |
+ | - How to write a computer program using the [[http:// | ||
+ | - How to launch a [[http:// | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== 4. Equipment | ||
+ | ==== 4.1. Hardware ==== | ||
+ | | ||
+ | - [[https://digilent.com/shop/usb-a-to-micro-b-cable/|Micro USB cable]] | ||
+ | | ||
In addition, we suggest the following instruments: | In addition, we suggest the following instruments: | ||
- | * Logic analyzer or oscilloscope (e.g. [[http:// | ||
- | ==== Software: ==== | + | - [[http:// |
- | The following programs must be installed on your development | + | |
- | | + | ==== 4.2. Software ==== |
- | * [[http:// | + | The following programs must be installed on your development |
- | * [[http:// | + | |
- | | + | * [[http:// |
- | | + | * [[http:// |
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | ---- | ||
===== 5. Project Takeaways ===== | ===== 5. Project Takeaways ===== | ||
- | | + | |
- | | + | - Know how to generate a microprocessor development project using MPLAB X. |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
+ | | ||
---- | ---- | ||
Line 55: | Line 68: | ||
===== 6. Fundamental Concepts ===== | ===== 6. Fundamental Concepts ===== | ||
==== 6.1. Project Planning ==== | ==== 6.1. Project Planning ==== | ||
- | A [[https:// | + | A software-based system consists of a collection of electrically interconnected electronic hardware components, some of which require programming using a computer language. Software-based system design is an engineering effort and requires a good process to obtain good results. The life cycle of system development uses a series of activities that, when considered in proper order, minimize design effort and achieve maximum benefit using the available resources of the software-based system. |
Coding is one of the last phases when developing software-based systems. There are many methods and tools available today to assist in code development planning. Not all software applications require exotic planning tools, although all applications do require some degree of planning. After my 25 years of teaching a course on microcontrollers, | Coding is one of the last phases when developing software-based systems. There are many methods and tools available today to assist in code development planning. Not all software applications require exotic planning tools, although all applications do require some degree of planning. After my 25 years of teaching a course on microcontrollers, | ||
Line 71: | Line 84: | ||
| Evaluation | | Evaluation | ||
- | In all lab exercises of this series, the purposes and requirements will be defined by a problem statement. In most labs, the required hardware is provided on the Basys MX3 trainer board. In some instances, additional hardware | + | In all lab exercises of this series, the purposes and requirements will be defined by a problem statement. In most labs, the required hardware is provided on the Basys MX3 trainer board. In some instances, additional hardware |
+ | |||
+ | Software development will be the focus of the design phase for this series of labs. A significant amount of effort will be needed to understand the required resources of the PIC32MX370 processor along with the functionality of sensors, actuators, displays, | ||
- | Software development will be the focus of the design phase for this series of labs. A significant amount of effort will be needed to understand the required resources of the PIC32MX370 processor along with the functionality of sensors, actuators, displays, and controls used in each lab, as well as the interconnection of these IO devices to the PICMX370 processor. This includes application specific hardware, interconnection drawings, development tools, and testing instrumentation. Part of processor resource allocation is a table that designates the processor IO pins and special functions such as timers, communications, | ||
Line 80: | Line 94: | ||
==== 6.1.2. Concepts Planning Using Partitioning ==== | ==== 6.1.2. Concepts Planning Using Partitioning ==== | ||
- | Software and hardware engineering use the [[https:// | + | Software and hardware engineering use the [[https:// |
{{ : | {{ : | ||
Line 88: | Line 102: | ||
//Figure 6.2. Control flow diagram for Lab 1a.// | //Figure 6.2. Control flow diagram for Lab 1a.// | ||
- | ==== 6.1.3. Concept Planning: Performance | + | A [[https:// |
+ | |||
+ | ==== 6.1.3. Concept Planning: Performance | ||
Using the divide and conquer approach, each element in the partitioned project must be completely tested and validated before integrating it with another element. You don’t want to design new code based on the functionality of incorrectly functioning old code. It is a waste of time. | Using the divide and conquer approach, each element in the partitioned project must be completely tested and validated before integrating it with another element. You don’t want to design new code based on the functionality of incorrectly functioning old code. It is a waste of time. | ||
After integration of all partitioned elements, system tests determine how well your design effort satisfies the stated requirements. One of the most straightforward ways is to make a table of the specified requirements to serve as a check-off list to include in your final documentation. | After integration of all partitioned elements, system tests determine how well your design effort satisfies the stated requirements. One of the most straightforward ways is to make a table of the specified requirements to serve as a check-off list to include in your final documentation. | ||
+ | |||
Line 97: | Line 114: | ||
===== 7. Problem Statement ===== | ===== 7. Problem Statement ===== | ||
- | There are two lab assignments associated with this unit. Lab 1a is very limited in scope and complexity and focuses on defining the PIC32MX370 | + | There are two lab assignments associated with this unit. Lab 1a is very limited in scope and complexity and focuses on defining the PIC32MX370 |
Line 104: | Line 121: | ||
===== 8. Background Information ===== | ===== 8. Background Information ===== | ||
==== 8.1. The Development Environment ==== | ==== 8.1. The Development Environment ==== | ||
- | The reader is expected to have acquired the basic knowledge of programming a computer in C. Bus as a review, we offer web links to an online [[http:// | + | The reader is expected to have acquired the basic knowledge of programming a computer in C. But as a review, we offer web links to an online [[http:// |
- | {{ : | + | {{ : |
//Figure 8.1. Integrated Development Hardware Diagram.// | //Figure 8.1. Integrated Development Hardware Diagram.// | ||
- | The diagram in Fig. 8.1 shows the PC with the Basys MX3 unit. The Basys MX3 has a built-in programmer/ | + | The diagram in Fig. 8.1 shows the Basys MX3 unit. The Basys MX3 has a built-in programmer/ |
==== 8.2. General Notes of Interest ==== | ==== 8.2. General Notes of Interest ==== | ||
Line 121: | Line 138: | ||
#define _SUPPRESS_PLIB_WARNING | #define _SUPPRESS_PLIB_WARNING | ||
#endif | #endif | ||
- | | + | |
- | # | + | #ifndef _DISABLE_OPENADC10_CONFIGPORT_WARNING |
- | #endif | + | # |
+ | #endif | ||
</ | </ | ||
< | < | ||
<ol start=" | <ol start=" | ||
- | < | + | < |
+ | |||
+ | **Table 8.1. XC32 (Global Options) all Options Category.** | ||
- | {{ : | + | ^ Option |
- | //Figure 8.2. XC32 Global Options Setting.// | + | | Use legacy lib | Check to use the Standard C library in the format before |
- | {{ : | + | {{ : |
- | //Figure 8.3. Disable “Use Legacy libc” to use plib.h.// | + | //Figure 8.2. Disable “Use Legacy libc” to use plib.h.// |
< | < | ||
<ol start=" | <ol start=" | ||
- | < | + | < |
==== 8.3. Microcontroller Resources ==== | ==== 8.3. Microcontroller Resources ==== | ||
- | Microcontrollers have three major resources: time access to the central processing unit (CPU execution time), program and data memory, and input and output (IO). Frequently, an application requires more of one of these three resources than the selected processor can provide. Microprocessor resource management involves compensating for a lack of one of these resources using excess capability in one or both of the other two. For example, if an application requires more IO than the processor has IO pins, the designer can implement a parallel pin multiplexing scheme that reduces the number of IO pins but requires additional memory and CPU time to execute the code. This concept will be explored when we interface the PIC32 processor with a four digit 7-segment LED display. | + | Microcontrollers have three major resources: time access to the central processing unit (CPU execution time), program and data memory, and input and output (I/O). Frequently, an application requires more of one of these three resources than the selected processor can provide. Microprocessor resource management involves compensating for a lack of one of these resources using excess capability in one or both of the other two. For example, if an application requires more I/O than the processor has I/O pins, the designer can implement a parallel pin multiplexing scheme that reduces the number of I/O pins but requires additional memory and CPU time to execute the code. This concept will be explored when we interface the PIC32 processor with a 4-digit 7-segment LED display. |
Line 159: | Line 179: | ||
The following three steps are used to launch a new project: | The following three steps are used to launch a new project: | ||
- Generate Lab 1 Project: | - Generate Lab 1 Project: | ||
- | - Open the MPLAB X application on your work station | + | - Open the MPLAB X application on your workstation |
- Start a new Microchip Embedded Standalone Project. | - Start a new Microchip Embedded Standalone Project. | ||
- | - Select Device: PIC32MX370F512L< | + | - Select Device: PIC32MX370F512L |
- Select Tool: Licensed Debugger MCU Alpha One | - Select Tool: Licensed Debugger MCU Alpha One | ||
- Select Toolchain: XC32 compiler | - Select Toolchain: XC32 compiler | ||
Line 171: | Line 191: | ||
- Right-click on the Header Files and select “New” -> “XC32 Header.h”. Name this file “config_bits.h”. | - Right-click on the Header Files and select “New” -> “XC32 Header.h”. Name this file “config_bits.h”. | ||
- Click on “Windows” -> “PIC Memory Views” -> “Configuration Bits”. | - Click on “Windows” -> “PIC Memory Views” -> “Configuration Bits”. | ||
- | - Set the options as shown in Listing | + | - Set the options as shown in Listing |
- Click on “Generate Source Code to Output”. | - Click on “Generate Source Code to Output”. | ||
- Enter “CTRL A” to highlight the text in the output window and “CTRL C” to copy the text. | - Enter “CTRL A” to highlight the text in the output window and “CTRL C” to copy the text. | ||
Line 187: | Line 207: | ||
- Declare local functions other than the function main. | - Declare local functions other than the function main. | ||
- Add a main function code as shown in Listing A.1. The return denotes an EXIT FAILURE because embedded systems code should never exit from the function main because it inherently has no place to return to. | - Add a main function code as shown in Listing A.1. The return denotes an EXIT FAILURE because embedded systems code should never exit from the function main because it inherently has no place to return to. | ||
- | - Complete the project requirements by adding header and source files as elements of building blocks. Each source file should have a header file that declares constants and software function prototypes that are used as interfaces with other project files. The project work is divided into independently testable units that can serve as libraries for other projects that use the same hardware resources. | + | - Complete the project requirements by adding header and source files as elements of building blocks. Each source file should have a header file that declares constants and software function prototypes that are used as interfaces with other project files. The project work is divided into independently testable units that can serve as libraries for other projects that use the same hardware resources. |
==== Listing A.1. Format of a Typical Main Function ==== | ==== Listing A.1. Format of a Typical Main Function ==== | ||
< | < | ||
- | int main(int argc, char** argv) | + | int main(int argc, char** argv) |
{ | { | ||
// Initialization code goes here | // Initialization code goes here | ||
Line 202: | Line 222: | ||
// this line of code. | // this line of code. | ||
} // End of main.c | } // End of main.c | ||
- | |||
</ | </ | ||
Line 208: | Line 227: | ||
===== Appendix B: Configuration Settings for the PIC32MX370F512L ===== | ===== Appendix B: Configuration Settings for the PIC32MX370F512L ===== | ||
- | ==== Listing B.1. Configuration bits settings | + | ==== Listing B.1. Configuration bits Settings |
< | < | ||
/* ************************************************************************** */ | /* ************************************************************************** */ | ||
Line 290: | Line 309: | ||
---- | ---- | ||
- | ===== Appendix C: Basys MX3A Hardware Initialization ===== | + | ===== Appendix C: Basys MX3 Hardware Initialization ===== |
- | Listings C.1 and C.2 that are provided below initialize the Basys MX3 hardware inputs. Development time will be reduced by including these two files in future projects. The hardware.h header file contains an extensive use of macro instructions. Macro instructions are text replacement compiler directives that can result in better documentation and all but eliminate [[http:// | + | Listings C.1 and C.2 that are provided below initialize the Basys MX3 hardware inputs. Development time will be reduced by including these two files in future projects. The hardware.h header file contains an extensive use of macro instructions. Macro instructions are text replacement compiler directives that can result in better documentation and all but eliminate [[http:// |
==== Listing C.1. Hardware Initialization Header File ==== | ==== Listing C.1. Hardware Initialization Header File ==== | ||
Line 334: | Line 353: | ||
/* Comment out the following define statement when programmer is NOT used to | /* Comment out the following define statement when programmer is NOT used to | ||
* allow using BTNL and BTNU as user inputs. */ | * allow using BTNL and BTNU as user inputs. */ | ||
- | # | + | # |
/* This included file provides access to the peripheral library functions and | /* This included file provides access to the peripheral library functions and | ||
Line 376: | Line 395: | ||
# | # | ||
- | /* The following macro instruction | + | /* The following macro instruction |
# | # | ||
Set_SW3_in(); | Set_SW3_in(); | ||
Line 511: | Line 530: | ||
@File Name | @File Name | ||
- | PICmx370.c | + | hardware.c |
| | ||
Line 530: | Line 549: | ||
#include " | #include " | ||
- | #include " | ||
#include < | #include < | ||
Line 577: | Line 595: | ||
| | ||
- | | + | |
| | ||
- | | + | |
} /* End of hardware_setup */ | } /* End of hardware_setup */ | ||
Line 612: | Line 630: | ||
---- | ---- | ||
- | ===== Appendix D: Essential Elements of the PIC32 Microprocessor | + | ===== Appendix D: Essential Elements of the PIC32 Microprocessor |
- | This section is not required to complete Labs 1a and 1b; however, it contains information important to forming a more complete view of microprocessor | + | This section is not required to complete Labs 1a and 1b; however, it contains information important to forming a more complete view of microprocessor |
+ | |||
+ | Digital input and output is one of the most basic functions as a microprocessor can perform. A simplified block diagram of the control of an I/O processor pin is shown in Fig. D.1. The operation of the I/O pin is configured by bit values in the following four registers: the output drain control (ODC), the output latch (LAT), the output tri-state (TRIS), and, for pins that can be used for analog inputs, the analog-to-digital input configuration (AD1PCFG). | ||
- | Digital input and output is one of the most basic functions as a microprocessor can perform. A simplified block diagram of the control of an IO processor pin is shown in Fig. D.1. The operation of the IO pin is configured by bit values in the following four registers: the output drain control (ODC), the output latch (LAT), the output tri-state (TRIS), and, for pins that can be used for analog inputs, the analog to digital input configuration (AD1PCFG). | ||
{{ : | {{ : | ||
- | //Figure D.1. Simplified block diagram for a PIC32 I/O pin.(([[http:// | + | //Figure D.1. Simplified block diagram for a PIC32 I/O pin, adapted from figure 12-1 in the PIC32 family data sheet.(([[http:// |
- | Minimally, the TRIS registers must be set to configure a processor | + | Minimally, the TRIS registers must be set to configure a processor |
- | If the bit in the TRIS register is set low to make the IO pin to function as an output, the voltage pin can be set high by writing a 1 to the appropriate bit in the LAT register. Setting the LAT register bit to a zero sets the output pin low (0V). The actual voltage at the output pin depends on the setting in the ODC register. The default configuration has all bits in the ODC register set to zero, which means the output can both source (supply output current) and sink (pull outputs low) current. If the bit in the ODC register is set high, then the output pin functions as open drain, which can sink current but not source current. | + | If the bit in the TRIS register is set low to make the I/O pin to function as an output, the voltage pin can be set high by writing a 1 to the appropriate bit in the LAT register. Setting the LAT register bit to a zero sets the output pin low (0V). The actual voltage at the output pin depends on the setting in the ODC register. The default configuration has all bits in the ODC register set to zero, which means the output can both source (supply output current) and sink (pull outputs low) current. If the bit in the ODC register is set high, then the output pin functions as open drain, which can sink current but not source current. |
- | The maximum current capability of each conventional I/O pin is 15mA (sink or source), while the combined current of all I/O pins is 200mA subject to total power constraints. I/O pins have both open drain and active source output capability. The open drain capability provided by the ODC register is useful when interfacing with switch array keypads (see [[http://store.digilentinc.com/pmodkypd-16-button-keypad/ | + | The maximum current capability of each conventional I/O pin is 15mA (sink or source), while the combined current of all I/O pins is 200mA subject to total power constraints. I/O pins have both open drain and active source output capability. The open drain capability provided by the ODC register is useful when interfacing with switch array keypads (see [[https://digilent.com/shop/ |
- | The PORT register allows the state of pin to be read regardless if the pin is configured in the TRIS register to be an input or an output. If the voltage on the pin is above the high input threshold, the PORT bit is read as a logic one. Various processor pins have different thresholds. | + | The PORT register allows the state of pin to be read regardless if the pin is configured in the TRIS register to be an input or an output. If the voltage on the pin is above the high input threshold, the PORT bit is read as a logic one. Various processor pins have different thresholds. |
- | + | If you are interested, refer to Table 30-8 of PIC32MX330/ | |
- | If you are interested, refer to Table 30-8 of PIC32MX330/ | + | |
The following listings are two functionally equivalent examples of code that uses the input state of pin RD0 to set the output on RD1. | The following listings are two functionally equivalent examples of code that uses the input state of pin RD0 to set the output on RD1. | ||
Line 639: | Line 657: | ||
{ | { | ||
// Initialization | // Initialization | ||
- | ANSELDbits.ANSD1 = 0; // RD1 set to digital | + | ANSELDbits.ANSD1 = 0; |
- | TRISDbits.TRISD1 = 0; // RD1 set to output | + | TRISDbits.TRISD1 = 0; |
- | TRISDbits.TRISD0 = 1; // RD2 set to input | + | TRISDbits.TRISD0 = 1; |
// loop | // loop | ||
Line 647: | Line 665: | ||
{ | { | ||
LATDbits.LATD1 = PORTDbits.RD0; | LATDbits.LATD1 = PORTDbits.RD0; | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 657: | Line 675: | ||
{ | { | ||
// Initialization | // Initialization | ||
- | ANSELDCLR = 0x02; // RD1 set to digital | + | ANSELDCLR = 0x02; // RD1 set to digital |
- | TRISDCLR = 0x02; // RD1 set to output | + | TRISDCLR = 0x02; |
TRISDSET = 0x01; // RD0 set to input | TRISDSET = 0x01; // RD0 set to input | ||
Line 665: | Line 683: | ||
{ | { | ||
if(PORTD & 0x01) // Read RD0 pin | if(PORTD & 0x01) // Read RD0 pin | ||
- | | + | |
else | else | ||
- | | + | |
- | | + | |
} | } | ||
</ | </ | ||
Line 675: | Line 693: | ||
---- | ---- | ||
- | ===== Appendix E: PIC32MX370F512L Processor Pin Assignments for Basys MX3A ===== | + | ===== Appendix E: PIC32MX370F512L Processor Pin Assignments for Basys MX3 ===== |
**Table E.1**. Processor IO Assignments. | **Table E.1**. Processor IO Assignments. | ||
^ CPU pin ^ Port ^ ALT ^ Function | ^ CPU pin ^ Port ^ ALT ^ Function | ||
Line 700: | Line 718: | ||
| 84 | RD7 | RPD7/ | | 84 | RD7 | RPD7/ | ||
| 80 | RD13 | RPD13/ | | 80 | RD13 | RPD13/ | ||
- | | 95 | RG14 | TRD2/RD14 | CP | " | + | | 95 | RG14 | TRD2/RG14 | CP | " |
| 93 | RE0 | PMD0/ | | 93 | RE0 | PMD0/ | ||
| 94 | RE1 | PMD1/ | | 94 | RE1 | PMD1/ | ||
Line 743: | Line 761: | ||
| 77 | RD2 | AN25/ | | 77 | RD2 | AN25/ | ||
| 88 | RF1 | RPF1/ | | 88 | RF1 | RPF1/ | ||
- | | 25 | RB0 | PGED1/ | + | | 25 | RB0 | PGED1/ |
- | | 24 | RB1 | PGC1/ | + | | 24 | RB1 | PGC1/ |
| 57 | RG2 | SCL1/ | | 57 | RG2 | SCL1/ | ||
| 56 | RG3 | SDA1/ | | 56 | RG3 | SDA1/ | ||
Line 763: | Line 781: | ||
| 63 | RC12 | CLKI/ | | 63 | RC12 | CLKI/ | ||
| 64 | RC15 | CLKO/ | | 64 | RC15 | CLKO/ | ||
+ | |||
+ | ---- | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
+ | [[{}learn/ | ||
+ | |||
+ | {{tag> |