circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

Issue 147 October 2002
12, 16, 18 Hike!
Dashing for Flash


by Jeff Bachiochi
Whether you’re gearing up to participate in the Microchip 2002 design contest or getting ready to follow the action from your favorite recliner, now is the perfect time to tune in for Jeff’s pre-game analysis.

Start PIC18F252 Instruction Set Reset Serial Port In-Circuit Sources & PDF

IN-CIRCUIT

The PIC18Fxx2 parts offer a few additional and significant features: in-circuit serial programming (ICSP), in-circuit debugging (ICD), and low-voltage in-circuit serial programming (LVICSP).

ICSP is a five-wire connection to the micro: SCLK, SDATA, Vdd, VSS, and MCLR (Vpp). The micro automatically enters ICSP mode at power-up if SCLK and SDATA are held low while Vdd rises and MCLR is raised to VPP. The serial format consists of 20-bit instructions, with the first 4 bits identifying a command, and the following 16-bit data to be acted on.

Nine out of the 10 commands are table read and write commands for moving data in and out of code memory. The tenth command (core command) allows actual microcontroller instructions to be executed by the micro. This allows register setup for the table commands. Note that the low-voltage programming (LVP) bit in the CONFIG4L register can only be cleared in ICSP mode. Clearing the LVP bit will prevent the LVICSP mode from being used; therefore, additional programming can only be done in ICSP mode.

For the micro to power-up in LVICSP mode (LVP bit must not be equal to zero), an additional signal PGM is used (this brings the programming connection to six wires). If the PGM signal is held high while the micro is powering up with the same signal requirements as ICSP mode above (with the exception of MCLR requiring Vcc instead of VPP), the micro will enter LVICSP mode. The format usage is the same as ICSP mode, but the difference is that the programming voltage VPP isn’t needed.

The ICSP interface makes an ideal connection to do helpful debugging. In fact, a special debugging mode is built in to the PIC18Fxx2 devices. Clearing the BKBUG bit in the CONFIG4L register enables this mode. Background debugging using Microchip’s in-circuit debugger (ICD) uses the ICSP interface and requires a 10-byte RAM space, two stack levels, and 512 bytes of code space on the target microcontroller to perform its magic.

ICD2

I’ve been using Microchip’s ICD1 for a long time now. Because I’m a crash-and-burn kind of guy, using Microchip’s integrated development environment (IDE software) in conjunction with a flash memory part and the in-circuit debugger really lets me develop in a designer-friendly way (see Photo 2). With this setup, I get to interrogate registers within the working device. This allows me to learn about the foolish mistake I’ve made that’s causing a crash.

The design of the ICD2 integrates a DB9 for those of you who still require RS-232 serial. In addition, the ICD2 has an alternate USB interface. Your target connection is through an RJ-11 jack. Designing an RJ-11 into your PCB will literally make interconnections a snap.

I wish I had an ICD2 available for my SmartMedia project. I guess that’s one of the downsides of trying to stay on the cutting edge. Now, with support for the PIC18Fxxx parts, the ICD2 is destined to be one of those must-have items.

To use the debugger, you must make sure that your application doesn’t use any of the resources required for the debugger. With the resources available to the PIC18Fxxx parts, this is hardly a problem. The debugger resources use only minimal upper RAM and program memory, in addition to two levels of stack. When your code is written and compiled using the IDE, you can transfer the hex file to the target device either with or without the debug code.

Without the debug code, the target can run your application at reset. With the debug code, you’ll be ready to run or step through your application.