Difference between revisions of "Introduction to the PIC32"

From Mech
Jump to navigationJump to search
Line 1: Line 1:
[[Image:nu32_complete.jpg|thumb|500px|The NU32 board that breaks out the PIC32MX460F512L.|right]]
[[Image:nu32_complete.jpg|thumb|500px|The NU32 board that breaks out the PIC32MX460F512L.|right]]
The [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2591 Microchip PIC32] is a family of complex and powerful microcontrollers that can be purchased for less than $10 in quantities of one. This microcontroller offers many peripherals useful for mechatronics purposes, such as several channels for analog-to-digital conversion, digital I/O, synchronous and asynchronous serial communication, pulse width modulation, etc. For our purposes, the primary advantages of the 32-bit PICs over the 8-bit PICs we have used (and will continue to use) are that they are faster (max clock rate of 80 MHz compared to 40 MHz), offer more program memory (Flash) and data memory (RAM), and have significantly more computational horsepower due to the 32-bit address and data buses and single-cycle multiply for 32-bit math. The primary disadvantages are that they come only in surface mount packages, making them a bit harder to work with for fast prototyping compared to the DIP (dual-inline packages) 8-bit PICs that can be plugged into a breadboard; and that they must be powered by 2.3-3.6 V, unlike the 5 V of some DIP chips we would like to interface them with. (Of course surface-mount and lower operating voltages are vastly superior for commercial embedded products, and we will find ways to work around these issues for our prototyping purposes.)
The [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2591 Microchip PIC32] is a family of complex and powerful microcontrollers that can be purchased for less than $10 in quantities of one. This microcontroller offers many peripherals useful for mechatronics purposes, such as several channels for analog-to-digital conversion, digital I/O, synchronous and asynchronous serial communication, pulse width modulation, etc. For our purposes, the primary advantages of the 32-bit PICs over the 8-bit PICs we have used (and will continue to use) are that they are faster (max clock rate of 80 MHz compared to 40 MHz), offer more program memory (Flash) and data memory (RAM), and have significantly more computational horsepower due to the 32-bit address and data buses and single-cycle multiply for 32-bit math. The primary disadvantages are that they come only in surface mount packages, making them harder to work with for fast prototyping compared to the DIP (dual-inline packages) 8-bit PICs that can be plugged into a breadboard; and they must be powered by 2.3-3.6 V, unlike the 5 V of DIP PICs and some DIP chips we would like to interface with. (Of course surface-mount and lower operating voltages are vastly superior for commercial embedded products, and we will find ways to work around these issues for our prototyping purposes.)


Particular numbers referenced on this page refer to the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en534177 PIC32MX460F512L] chip, which is the PIC32 used on the NU32 board. The NU32 development board is shown at right. The NU32 board was designed by Andy Long to easily plug into a standard prototyping breadboard (DIP profile), allowing easy prototyping with the PIC32. The NU32 board also has a voltage regulator, a USB connector, and a few LEDs and switches to allow you to get up and running quickly with only the assembled NU32 board, a USB cable, and a PC with free software downloaded from Microchip. See the [[Getting Started with PIC32 | getting started page]]. The NU32 board was created with inspiration from the [http://www.sparkfun.com/commerce/product_info.php?products_id=8971 UBW32 board]. We wanted a board that was a little bit smaller, so we sacrificed some pins we thought unnecessary for the majority of mechatronics projects. We also wanted a board that gave students some experience soldering non-surface-mount components.
Particular numbers referenced on this page refer to the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en534177 PIC32MX460F512L] chip, which is the PIC32 used on the NU32 board. The NU32 development board is shown at right. The NU32 board was designed by Andy Long to easily plug into a standard prototyping breadboard (DIP profile), allowing easy prototyping with the PIC32. The NU32 board also has a voltage regulator, a USB connector, and a few LEDs and switches to allow you to get up and running quickly with only the assembled NU32 board, a USB cable, and a PC with free software downloaded from Microchip. See the [[Getting Started with PIC32 | getting started page]]. The NU32 board was created with inspiration from the [http://www.sparkfun.com/commerce/product_info.php?products_id=8971 UBW32 board]. We wanted a board that was a little bit smaller, so we sacrificed some pins we thought unnecessary for the majority of mechatronics projects. We also wanted a board that gave students some experience soldering non-surface-mount components.

Revision as of 20:46, 2 January 2010

The NU32 board that breaks out the PIC32MX460F512L.

The Microchip PIC32 is a family of complex and powerful microcontrollers that can be purchased for less than $10 in quantities of one. This microcontroller offers many peripherals useful for mechatronics purposes, such as several channels for analog-to-digital conversion, digital I/O, synchronous and asynchronous serial communication, pulse width modulation, etc. For our purposes, the primary advantages of the 32-bit PICs over the 8-bit PICs we have used (and will continue to use) are that they are faster (max clock rate of 80 MHz compared to 40 MHz), offer more program memory (Flash) and data memory (RAM), and have significantly more computational horsepower due to the 32-bit address and data buses and single-cycle multiply for 32-bit math. The primary disadvantages are that they come only in surface mount packages, making them harder to work with for fast prototyping compared to the DIP (dual-inline packages) 8-bit PICs that can be plugged into a breadboard; and they must be powered by 2.3-3.6 V, unlike the 5 V of DIP PICs and some DIP chips we would like to interface with. (Of course surface-mount and lower operating voltages are vastly superior for commercial embedded products, and we will find ways to work around these issues for our prototyping purposes.)

Particular numbers referenced on this page refer to the PIC32MX460F512L chip, which is the PIC32 used on the NU32 board. The NU32 development board is shown at right. The NU32 board was designed by Andy Long to easily plug into a standard prototyping breadboard (DIP profile), allowing easy prototyping with the PIC32. The NU32 board also has a voltage regulator, a USB connector, and a few LEDs and switches to allow you to get up and running quickly with only the assembled NU32 board, a USB cable, and a PC with free software downloaded from Microchip. See the getting started page. The NU32 board was created with inspiration from the UBW32 board. We wanted a board that was a little bit smaller, so we sacrificed some pins we thought unnecessary for the majority of mechatronics projects. We also wanted a board that gave students some experience soldering non-surface-mount components.

The purpose of this page is to provide a brief overview of PIC32 and NU32 hardware and programming for the beginner. Microchip provides many reference manuals, data sheets, application notes, and sample software, and there are many other helpful web resources to take you further.

PIC32 and NU32 Hardware Overview

Pinout of the PIC32MX4XX.

Our PIC32MX460F512L features a max clock frequency of 80 MHz, 512K program memory (flash), 32K data memory (RAM), multiple interrupt sources and handling routines, 16 analog-to-digital input channels, many digital I/O channels (with outputs that can be configured for open-drain), USB 2.0, two I2C and two SPI synchronous serial communication modules, two UARTs for RS-232 or RS-485 asynchronous serial communication, five 16-bit counter/timers (configurable to give two 32-bit timers), five pulse-width modulation outputs, and a number of pins that can generate interrupts based on external signals, among other features. This PIC has 100 pins, many (but not all) of which are used or broken out by the NU32 board.

To cram this much functionality into 100 pins, many of the pins serve multiple functions. For example, pin 20 can serve as a comparator input, an analog input, a change notification input which can generate an interrupt when the pin changes state, or a digital input or output. Which function a particular pin serves is determined by "Special Function Registers" (SFRs) that contain configuration bits specifying the desired use of the pin. Typically your program sets these configuration bits at the beginning of execution, and the functions of the pins are fixed while your program runs. (It is possible, though rarely needed, to change the configuration bits and change the function of pins during execution.)

more on the ports, and meaning of the abbreviations.


Block diagram of the PIC32MX4XX.

The figure at right is a block diagram of the architecture of the PIC32. The CPU interfaces with data memory (RAM) and the program flash memory (along with USB, a direct memory access controller, and an in-circuit debugger and JTAG interface that can be used for debugging purposes). It also interfaces with peripherals, which are what make microcontrollers useful for embedded control. These peripherals consist of PORTA ... PORTG, which are digital I/O ports; five counter/timers; analog-to-digital converter (ADC); a real-time clock (RTCC); comparators; UARTs for asynchronous serial communication; a "parallel master port" (PMP) for parallel communication; two I2C and SPI synchronous serial communication modules; pins for pulse-width modulation (or "output compare"); and change notification pins to generate interrupts when signals change. Note that these peripherals are on two different buses: one is a bus clocked by the system clock SYSCLK, and the other is clocked by the peripheral bus clock PBCLK. These may be the same frequency, or the PBCLK may be a lower frequency, depending on how you set clock configuration bits. The top of the figure shows the timing generation, which uses either an external crystal or timing circuit (for more accurate timing), or an internal circuit, to create SYSCLK, PBCLK, and USBCLK (which is used for USB communication). The NU32 board uses an external 8 MHz crystal oscillator to generate a SYSCLK of 80 MHz using a phase-locked loop (PLL) to multiply the frequency.


now the board


PIC32 Programming in C

Further Reading

links to microchip manuals, data sheets, books, external sources, etc.