w. Making a PIC32 programmer considerations

Making a programmer for PIC16 and PIC18 microcontroller families is almost trivial compared to a PIC32 programmer. The list of key check points for making a successful PIC32 programmer is rather long (Read ICSP Programmer for PIC32 microcontroller family and/or JTAG PROGRAMMER FOR PIC32 FAMILY on how to make your own ICSP or JTAG programmer for PIC32 microcontrollers):

1. PIC32 microcontrollers (µC) cannot be programmed directly. You have to copy new program machine codes and data to µC RAM and then instruct µC to program them into its flash RAM.

2. The programming procedure is relatively complex due to JTAG communication protocol. It is true that PIC32 µC also support ICSP (in-circuit serial programming), but it is not the same “ICSP” as in PIC18. It is rather an interface to µC JTAG modules. It makes programming even more difficult. If you are working on your own PIC32 programmer, you may opt for JTAG interface, which is much faster and it is easier to implement. ICSP support is mainly intended for existing commercial µC programmers that enable SW upgrades. However, ICSP PIC32 Programmer based on PIC32MX270F256B microcontroller is now available.

3. It is difficult to erase the chip configuration words, if code protection is enabled. There are certain tricks to erase them on the internet. EJTAG ease command may also fail to execute after the configuration words are programmed into a PIC32 µC, if JTAG programming interface is used and the clock source specified in configuration words is not provided. The only way to overcome this obstacle is to use ICSP programming (see paragraph 8).

4. PIC32 µC incorporate 32-bit MIPS central processing unit (CPU) core which is much more sensitive to electrical operating conditions than 8-bit Microchip CPU cores. There is also a unique feature that may let you think that you already have a working PIC32 circuit with external clock source, but you would be wrong. PIC32 will automatically switch to internal 8 MHz clock source, if configuration words are not programmed, or if the external clock source is not stable enough. This would let you think that everything works ok, but in the end you would not be able to explain why USB port fails to connect to a PC, for instance. The only option is to write your own program to switch to an external clock source, instead of programming the configuration words. This would also enable you to erase and reprogram µC easily.

5. If you opt for external clock source to enable off-circuit JTAG programming, it is worth to note that the requirements for it are much stricter than requirements for PIC16 or PIC18 clock source. A much higher stability is required no matter which of the three options you choose. Using just a quartz crystal and two small capacitors may seem the most convenient option, but it is rather difficult to determine the capacitor values. They can be approximated with the following equation: CL = (C1 * C2) / (C1 + C2) + CS, where CL represents crystal load capacitance, C1 and C2 are the capacitances of the two capacitors and CS is serial (parasite) capacitance of a printed circuit board board (PCB) connections to the PIC32 OSC1 and OSC2 pins. CL should be provided by crystal manufacturer. CS is initially presumed to be from 5 pF to 10 pF. C1 and C2 are usually chosen to have the same value, which usually spells the best results. Therefore one can easily approximate them: C1 = C2 = 2(CL-CS). The final selection of C1 and C2 should be determined and verified by an oscilloscope.

You may also opt for a crystal resonator that already has inbuilt C1 and C2 capacitors. It has to be positioned as close to OSC1 and OSC2 pins as possible to make CS negligible. The third option is to use a suitable crystal oscillator. It is important to verify the oscillator stability and supply voltage requirement. PIC32 µC require a 3.3 V oscillator. Though an oscillator implementation may require more connections on a PCB, OSC2 pin is not required and can be used as a regular port B output or input.

6. There are various PIC32 programmer’s and reference documentations, but the crucial data are dispersed through Microchip and MIPS manuals and reference books. The PIC32 reference book is divided into around 30 *.PDF files, which sometimes makes it difficult to search for a certain term. If you intend to make a successful PIC32 programmer you should study MIPS documentation first and then use Microchip documentation as reference that enables you to support specific µC.

7. Another major obstacle on your way of making a PIC32 programmer is obtaining the programming executive (PE). Its operation is briefly described in the Microchip documentation though there are no direct references on where to download PE, or how to build one. Even when you find a PE code, it may still not fully support your µC. Only the PE version may tell you, if it is the right one for your needs, but there are not version notices or released information supplied with PE. PEs are distributed only as parts of different programming examples. It is true that you can program µC even without PE, but it is impractical due to communication overhead that greatly slows down the µC programming.

8. Programming configuration bytes at the end of the boot memory may cause difficulties for reading back a microcontroller's memory via JTAG interface:

"If using the 4-wire interface, the oscillator source, as selected by the Configuration Words, must be present to access flash memory. In an unprogrammed device, the oscillator source is the internal FRC allowing for flash memory access. If the Configuration Words have been reprogrammed selecting an external oscillator source then it must be present for flash memory access."

The only general solution for this problem is to use 2-wire ICSP programming, as it is used on Microchip PICkit3 programmer, or to provide a JTAG interface on the circuit. There is also an option of using a combination of a 2-wire and a 4-wire interface, were the 2-wire interface is only used for the operations that cannot be accomplished using the faster 4-wire interface. See the latest Microchip PC32MX programming specification DS00061145P for details.

ALSO READ:

- How to make a 32-bit PIC32MX250F128B (PIC32) microcontroller to work on USB 2.0

- ICSP Programmer for PIC32 microcontroller family