Difference between revisions of "Getting Started with PIC32"

From Mech
Jump to navigationJump to search
 
(72 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Follow these steps to get started with PIC32.
This page details getting started with the PIC32 board.

Please complete the software section prior to lab 1.

In lab 1, you will assemble a NU32 board, install a bootloader and create a Hello World Program.


= Software =
= Software =


MPLAB is the software used for editing, compiling, debugging code. This software creates the HEX files to download to the PIC.
This section discusses the software that must be installed on your computer. This software is only compatible with Windows.
We are going to install MPLAB (software used for editing, compiling, and debugging code), the C32 compiler (software to create the program) and the Microchip Applications Library (common source files for programming).


1. Download MPLAB IDE vX.XX Full Release Zipped Installation located near the bottom of this [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&redirects=mplab page]. You can save the zip file temporarily to the desktop; you will delete it after installation. Extract the files from the zip file to create a folder on your desktop. Double-click on the setup launcher, run it, and choose "complete setup." Let it install in the default location. (Do not install HITEC-C when prompted.) If MPLAB IDE Document Select appears, you can just close it. Now the MPLAB IDE is installed and you can delete the zip file and extracted folder from your Desktop.
Download and Install [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&redirects=mplab Microchip MPLAB] (Microchip's free IDE for editing, debugging and compiling code)


Download and Install [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en536656 Microchip C32 Compiler] (the academic version is free)
2. Download the MPLAB C Compiler for PIC32 vX.XX Academic Version located near the bottom of this [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en536656 page] (the academic version is free). Click "Run" and let it install in the default location.


Download and Install [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en537044 Microchip Applications Library] located at bottom of page. This zip file contains common source code and header files. There is a separate stack for PIC32, but it has been rumored that the PIC32 stack is going to get merged with the applications library therefore the code on this website is based on the application library stack.
3. Download the Microchip Applications Library [[Media:MicrochipAppLib_11_18_2009.zip|here]]. This zip file is the library version released on 11-18-2009. More recent versions may be downloaded [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en537044 here] but the files may not work with the code listed on the wiki. Save the zip file to your desktop and extract the files. Run the installer and install to the default. Now you can delete the zip file and extracted folder. '''Note:''' When installing this library, Microchip may prompt you to install .Net software. Click yes if this happens.

* Header files from the framework do not need to be specifically added to the project in MPLAB, but MPLAB needs to be directed to their location (see getting [[Directions for Starting New MPLAB Project]])
= Board Assembly =
* Source files from the framework do need to be added to the project

The NU32 development board you are going to assemble already has a PIC32 microcontroller soldered on the board. You will be soldering the rest of the components.

Collect the following components from the PIC32 supply bin.
[[Image:nu32_components.jpg]]

{| border="1"
! style="background:#efefef;" | Part Label
!! style="background:#efefef;" | Part Name
!! style="background:#efefef;" | Quantity
!! style="background:#efefef;" | Vendor
!! style="background:#efefef;" | P/N
!! style="background:#efefef;" | Description
|-
| A || 8.0 MHz Crystal || 1 || Digikey ||X979-ND||
|-
| B || 3.3 V Regulator || 1 || Digikey ||LD1117V33 || Input: 4.75 ~ 10 V; Output: 3.3V, 950 mA
|-
| C || Barrel Connector 2.5mm ID|| 1 || Digikey ||CP-102BH ||
|-
| D || Mini USB - B Socket|| 1 || Digikey ||WM17115-ND||
|-
| E || NU32 Board || 1 || NU || ||
|-
| F || 36 Pos Single Row Header Pins|| 2 || Digikey ||WM6536|| '''You will cut these to two rows of 29 pins for the long edges of the board. You will also need a leftover 5-pin header to mount at the short end of the board away from the USB connector. These pins will point upward, opposite the pins on the long edge of the board. This 5-pin header will be used to program the bootloader on the PIC32.'''
|-
| G || 330 Ohm Resistor || 1 || Digikey ||332XBK-ND||
|-
| H || 22 pF Capacitor|| 2 || Digikey ||478-4846-ND||
|-
| I || LEDs|| 5 total || Digikey ||
{|
|1 RED || 160-1084
|-
|4 YEL || 160-1085
|-
|or 4 GRN || 160-1086
|}
|-
| J || 10 uF Capacitor|| 1 || Digikey ||399-3548-ND|| Polarized
|-
| K || 0.33 uF Capacitor|| 1 || Digikey ||399-4299-ND||
|-
| L || 1 uF Capacitor|| 1 || Digikey ||BC1162CT-ND||
|-
| M || 0.1 uF Capacitor|| 10 || Digikey ||478-3192-ND||
|-
| N || 1K Ohm Resistor Array|| 1 || Digikey ||770-81-R1KP-ND||
|-
| O || Sub Miniature Slide Switch|| 1 || Digikey ||401-2001-ND||
|-
| P || Reset Button|| 3 || Digikey ||CKN9102-ND||
|-
| Q || 10K Ohm Resistor|| 1 || Digikey ||10.0KXBK||
|-
|}


The PIC32 is already soldered to the board.
[[Image:nu32_bare_board.jpg]]

Begin soldering components, ending with the header pins.

The capacitor labels can be hard to read, they are color coded here:
[[Image:capacitor_chart.jpg]]

Several components need to be soldered with the proper orientation.
The 10 uF capacitor needs to be soldered with the positive lead towards the PIC.
[[Image:nu32_capacitor.jpg]]

The resistor array needs to have the side with the dot facing the long end of the board.
[[Image:nu32_resistor_array.jpg]]

The indicator LEDs need to have their positive leads toward the end of the board.
[[Image:nu32_indicator_led.jpg]]

The power LED needs to have its positive lead facing the close edge of the board.
[[Image:nu32_power_led.jpg]]

The 3.3V regulator needs to have its back side facing the power jack.
[[Image:nu32_regulator.jpg]]

The finished board looks like this:
[[Image:nu32_complete.jpg]]

Note to program the bootloader onto the board, the programming cable can only be plugged into the last five header pins one way:
[[Image:nu32_program.jpg]]


= Bootloader =
= Bootloader =


'''Note: If you're in lab with the TA, you can ask the TA to install the bootloader for you and skip this step. Once the bootloader is installed on your PIC, you should not have to install it again. This step requires the Microchip ICD2 programmer.'''
An advantage of the PIC32 is that a bootloader can be installed. This means you do not need to a programmer to put new programs on the PIC. The UBW32 comes preloaded with a bootloader.

A bootloader is a program that enables you to easily install programs on the PIC32 using only a USB cable. Normally, an external programmer is needed for programming the PIC. The bootloader takes hex files created by the MPLAB compiler and programs them on the PIC. Hex files are binary representations of the c code. See the wikipedia page for Hex files [http://en.wikipedia.org/wiki/Intel_HEX here] for more information.

Follow these [[Programming HID Bootloader on PIC32|directions ]] to install a bootloader on your PIC.


= First Program =
The HID bootloader is used to put HEX files on the PIC32. The v2.4 executable can be downloaded [[Media:HID_Bootloader_v2_4.zip| '''here''']].


We are first going to test that you installed the bootloader correctly.
NOTE: occassionally, the bootloader will get stuck verifying that the program is running. (There must be a bug in the bootloader application code) It will take 90-100% of CPU. End task manually with the task manager if this happens.


- Download this HelloWorld zip [[Media:HelloWorld_PIC32_Hex.zip|file]] and extract the hex. (This code flashes all of the LEDs at a 1 second period, if you hold down the USER button the period changes)
See [[Programming Bootloader on PIC32]] for directions on how to create your own bootloader.


- Use [[Directions to Load Files to PIC32 with HID Bootloader|these directions]] to load a hex File with the bootloader.
= Linker File =


Next, we are going to make a different Hello World program from scratch.
When creating new projects to download to the PIC, you must include a linker file. If you have installed a bootloader, the linker file tells the bootloader to put the program after the bootloader memory. The required linker file is called procdefs.ld. The standard linker file is [[Media:procdefs.ld | here]] for PIC32. linker file is in the project folder. The procdefs.ld for UBW32 is different than the standard procdefs.ld for PIC32 when using the bootloader originally installed on UBW32. Make sure to use the procdefs.ld file [[Media:procdefs_UBW32.ld | here]] for UBW32.


- Follow the directions [[HelloWorld_PIC32|here]] to code and program Hello World on to the PIC32 using the bootloader.
This [http://www.paintyourdragon.com/uc/ubw32/index.html website] warns that if the procdefs linker file is not in the project the bootloader may be hosed.

Latest revision as of 20:33, 21 April 2010

This page details getting started with the PIC32 board.

Please complete the software section prior to lab 1.

In lab 1, you will assemble a NU32 board, install a bootloader and create a Hello World Program.

Software

This section discusses the software that must be installed on your computer. This software is only compatible with Windows. We are going to install MPLAB (software used for editing, compiling, and debugging code), the C32 compiler (software to create the program) and the Microchip Applications Library (common source files for programming).

1. Download MPLAB IDE vX.XX Full Release Zipped Installation located near the bottom of this page. You can save the zip file temporarily to the desktop; you will delete it after installation. Extract the files from the zip file to create a folder on your desktop. Double-click on the setup launcher, run it, and choose "complete setup." Let it install in the default location. (Do not install HITEC-C when prompted.) If MPLAB IDE Document Select appears, you can just close it. Now the MPLAB IDE is installed and you can delete the zip file and extracted folder from your Desktop.

2. Download the MPLAB C Compiler for PIC32 vX.XX Academic Version located near the bottom of this page (the academic version is free). Click "Run" and let it install in the default location.

3. Download the Microchip Applications Library here. This zip file is the library version released on 11-18-2009. More recent versions may be downloaded here but the files may not work with the code listed on the wiki. Save the zip file to your desktop and extract the files. Run the installer and install to the default. Now you can delete the zip file and extracted folder. Note: When installing this library, Microchip may prompt you to install .Net software. Click yes if this happens.

Board Assembly

The NU32 development board you are going to assemble already has a PIC32 microcontroller soldered on the board. You will be soldering the rest of the components.

Collect the following components from the PIC32 supply bin. Nu32 components.jpg

Part Label Part Name Quantity Vendor P/N Description
A 8.0 MHz Crystal 1 Digikey X979-ND
B 3.3 V Regulator 1 Digikey LD1117V33 Input: 4.75 ~ 10 V; Output: 3.3V, 950 mA
C Barrel Connector 2.5mm ID 1 Digikey CP-102BH
D Mini USB - B Socket 1 Digikey WM17115-ND
E NU32 Board 1 NU
F 36 Pos Single Row Header Pins 2 Digikey WM6536 You will cut these to two rows of 29 pins for the long edges of the board. You will also need a leftover 5-pin header to mount at the short end of the board away from the USB connector. These pins will point upward, opposite the pins on the long edge of the board. This 5-pin header will be used to program the bootloader on the PIC32.
G 330 Ohm Resistor 1 Digikey 332XBK-ND
H 22 pF Capacitor 2 Digikey 478-4846-ND
I LEDs 5 total Digikey
1 RED 160-1084
4 YEL 160-1085
or 4 GRN 160-1086
J 10 uF Capacitor 1 Digikey 399-3548-ND Polarized
K 0.33 uF Capacitor 1 Digikey 399-4299-ND
L 1 uF Capacitor 1 Digikey BC1162CT-ND
M 0.1 uF Capacitor 10 Digikey 478-3192-ND
N 1K Ohm Resistor Array 1 Digikey 770-81-R1KP-ND
O Sub Miniature Slide Switch 1 Digikey 401-2001-ND
P Reset Button 3 Digikey CKN9102-ND
Q 10K Ohm Resistor 1 Digikey 10.0KXBK


The PIC32 is already soldered to the board. Nu32 bare board.jpg

Begin soldering components, ending with the header pins.

The capacitor labels can be hard to read, they are color coded here: Capacitor chart.jpg

Several components need to be soldered with the proper orientation. The 10 uF capacitor needs to be soldered with the positive lead towards the PIC. Nu32 capacitor.jpg

The resistor array needs to have the side with the dot facing the long end of the board. Nu32 resistor array.jpg

The indicator LEDs need to have their positive leads toward the end of the board. Nu32 indicator led.jpg

The power LED needs to have its positive lead facing the close edge of the board. Nu32 power led.jpg

The 3.3V regulator needs to have its back side facing the power jack. Nu32 regulator.jpg

The finished board looks like this: Nu32 complete.jpg

Note to program the bootloader onto the board, the programming cable can only be plugged into the last five header pins one way: Nu32 program.jpg

Bootloader

Note: If you're in lab with the TA, you can ask the TA to install the bootloader for you and skip this step. Once the bootloader is installed on your PIC, you should not have to install it again. This step requires the Microchip ICD2 programmer.

A bootloader is a program that enables you to easily install programs on the PIC32 using only a USB cable. Normally, an external programmer is needed for programming the PIC. The bootloader takes hex files created by the MPLAB compiler and programs them on the PIC. Hex files are binary representations of the c code. See the wikipedia page for Hex files here for more information.

Follow these directions to install a bootloader on your PIC.

First Program

We are first going to test that you installed the bootloader correctly.

- Download this HelloWorld zip file and extract the hex. (This code flashes all of the LEDs at a 1 second period, if you hold down the USER button the period changes)

- Use these directions to load a hex File with the bootloader.

Next, we are going to make a different Hello World program from scratch.

- Follow the directions here to code and program Hello World on to the PIC32 using the bootloader.