Microchip's new MPLABX development environment (free download) came out of beta a few weeks ago and the PICkit3 programmer/debugger was on special offer. So I figured this was as good a time as any to pick up a PICkit3 and to get a 'hello world' program running on the PIC24FJ64GB002 and PIC32MX110F016B samples I had in my parts drawer. Both are available in 28 pin DIP packages. (Can't beat DIPs and breadboards for quick prototyping!)
Programming the 8 bit PIC range such as 12F and 16F series with the PICkit2 programmer is simple: just connect the five ICSP pins MCLR, Vdd, GND, PGD, PGC from the programmer to the corresponding pins on the chip. Nothing else is needed. The chip can then be probed and programmed. I prefer to use the command line tool. For example to verify that a chip was present:
pk2cmd -P
and then I'd upload myprogram.hex firmware with something like
pk2cmd -P -Fmyprogram.hex -M -R
and apply power at 3.3V for testing (internal oscillator must be configured if there is no external crystal):
pk2cmd -P -T -A3.3
The PIC24FJ64GB002 and PIC32MX110F016B chips are not as straight forward. My naive attempt at treating them like the 8 bit PICs didn't work. I noticed searching Microchip's forums that others were have difficulty also. Like most problems relating to programming MCUs the answer is in the datasheet. You either need to read it cover-to-cover or fumble around and experiment. I'm still not sure which approach gets you there faster, but the latter is more fun :-)
There are a few important differences when compared to the older 12F and 16F series. These chips use a dual power supply. The CPU core runs at a lower voltage (usually 2.2V) and the on-chip peripherals run off a higher voltage (usually 3.3V). The core power can be configured to be supplied from an on-chip source or externally. The on-chip supply is selected by grounding the DISVREG pin and connecting Vcap to ground via a 10µF capacitor [Reference PIC24FJ64GB004 family datasheet, section 2 "Guidelines for getting started with 16-bit microcontrollers"].
Another important difference: the chip must be powered up, even for probing and programming. This is not necessary for the 8 bit PICs that I've been using. This one threw me for a bit: MPLABX with PICkit3 kept telling me no target was connected. Finally I twigged that I should have power applied:
right-click on the project and select 'Properties', select PICkit3, select the Power category from the pull down menu, select the desired voltage (usually something close to 3.3V) and check "Power target circuit from PICkit3" checkbox.
So to summarize the setup for both chips (electrically identical, just different names/functions on some pins).
PIC24FJ64GB002
|
PIC32MX110F016B
|
Finally the configuration bits must be set just right if you want the PICkit3 in-circuit debugger to work. The syntax used to defining the configuration bits seem seems to vary from compiler to compiler. For the PIC24FJ64GB002 this is what worked for me using the Microchip C30 C compiler version 3.30c:
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & ICS_PGx2 // NB: set to correct channel & FWDTEN_OFF & WINDIS_OFF & FWPSA_PR32 & WDTPS_PS8192); _CONFIG2(IESO_OFF & FNOSC_FRCPLL & OSCIOFNC_ON & POSCMOD_NONE & PLL96MHZ_ON & PLLDIV_DIV2 & FCKSM_CSDCMD & IOL1WAY_OFF); _CONFIG3(WPFP_WPFP0 & SOSCSEL_IO & WUTSEL_FST & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPENDMEM); _CONFIG4(DSWDTPS_DSWDTPS3 & DSWDTOSC_LPRC & RTCOSC_LPRC & DSBOREN_OFF & DSWDTEN_OFF);
The configuration bits I found that worked for the PIC32MX110F016B (Microchip C32, v2.02) are:
#pragma config FPLLODIV = DIV_1 #pragma config FPLLMUL = MUL_20 #pragma config FPLLIDIV = DIV_2 #pragma config FWDTEN = OFF #pragma config FPBDIV = DIV_1 #pragma config WDTPS = PS1 #pragma config FCKSM = CSECME #pragma config OSCIOFNC = OFF #pragma config POSCMOD = HS #pragma config IESO = ON #pragma config FSOSCEN = OFF #pragma config FNOSC = PRIPLL #pragma config CP = OFF #pragma config BWP = OFF #pragma config PWP = OFF #pragma config ICESEL = ICS_PGx2 // NB: set to correct channel #pragma config DEBUG = OFF
Note that both of these chips have several programming ports. Any can be used for programming. However for debugging you must specify which port is being used in the configuration bits.
4 comments:
Hi,
just found your settings extremely useful as I was actually experiencing problems debugging my PIC24FJ64GB002 design.
On top of the settings, there is one important and completely stupid thing to remember ...
put your files, project, etc ... in a location for whihc the PATH does not contain any spaces or strange characters !!!!
Interesting that this recurring issue has still not be solved.
On XP, this is still an issue.
Jacques
Holy cow thanks! These configs worked perfect for me! for the PIC24FJ64GB002. I have been fighting to light up just a single LED but was confused on what these configs to be set at. This was very helpful. Thanks again.
You're welcome :) BTW: another one to try is the LPC1114FN28: an ARM Cortex M0 MCU in a 28pin DIP package. About $2.50 in single quantities. I've got a blog post on a minimal setup for that coming up (absolutely no external components required in this case!).
I'm not getting the syntax of the configuration bits. Is this coming from a header file ? Macros ? Can you just explain the first few lines so I can figure out how it works or where they are from ? Thanks.
Post a Comment