Difference between revisions of "Introduction to the PIC32"

From Mech
Jump to navigationJump to search
Line 21: Line 21:
| AVDD, AVSS || positive supply and ground reference for ADC
| AVDD, AVSS || positive supply and ground reference for ADC
|-
|-
| BCLK1, BLCK2 ||
| BCLK1, BLCK2 || clocks for infrared (IrDA) comm encoding and decoding for 2 UARTs
|-
|-
| CxIN-, CxIN+, CxOUT (x=1,2) ||
| CxIN-, CxIN+, CxOUT (x=1,2) ||

Revision as of 21:47, 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.)

Pin Label Function
ANx (x=0-15) analog-to-digital (ADC) inputs
AVDD, AVSS positive supply and ground reference for ADC
BCLK1, BLCK2 clocks for infrared (IrDA) comm encoding and decoding for 2 UARTs
CxIN-, CxIN+, CxOUT (x=1,2)
CLKI, CLKO
CNx (x=0-21)
CVREF-, CVREF+, CVREFOUT
D+, D-
EMUCx, EMUDx (x=1,2)
ENVREG
ICx (x=1-5)
INTx (x=0-4)
MCLR (overbar)
OCx (x=1-5)
OCFA, OCFB
OSC1, OSC2
PGCx, PGDx (x=1,2)
PMALL, PMALH
PMAx (x=0-15)
PMDx (x=0-15)
PMENB, PMRD, PMWR
Rxy (x=A-G,y=0-15)
SCKx, SCLx, SDAx (x=1,2)
SDIx, SDOx (x=1,2)
SS1, SS2 (overbar)
TxCK (x=1-5)
TCK, TDI, TDO, TMS
TRCLK
TRDx (x=0-3)
UxCTS, UxRTS, UxRX, UxTX (x=1,2)
VDD
VDDCAP
VDDCORE
VREF-, VREF+
VSS
VBUS
VUSB
VBUSON
USBID



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 counters that can be used for a variety of counting operations (and timing operations, by counting clock ticks); analog-to-digital converter (ADC); a real-time clock (RTCC) that can maintain accurate year-month-day-time; comparators that compare which of two inputs has a higher voltage; UARTs for asynchronous serial communication (e.g., RS-232, RS-485); 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.