A Weekend ICD

 

 

By Eng. Radu Constantinescu

Virginia, 2/15/2002

 

 

Micro-controller driven applications are much more flexible and powerful than hardware. Lately, due their convenient prices, Micro-controllers could successfully replace the classical hard-wired version. Fancy features like Menus, large parameter memory and smart keys are specific to computer programs and almost cannot be achieved in the classical designs.

 

In order to develop a classical application the necessary tools are the Scope and the Multimeter. For a Micro-controller based application an Emulator is necessary to find and solve the software troubleshooting. The main inconvenience is the Emulators’ price. They are quite expensive and not too many people could afford to buy them.

 

Microchip software tools developed for the PIC Micro-controllers are well known; and they are available for free. These tools have made the PIC IC’s very popular. To overcome the natural need for a cheaper emulator the In Circuit Debugger (ICD) was build up.

 

The ICD is a poor brother of a real Emulator but the price is affordable for everybody.  Because the ICD is also a good PIC Programmer, we have a perfect tool to learn and build up other small projects too. The ICD can run the program from the target CPU step by step, can set a hardware breakpoint or can even update the target firmware without removing it from the circuit. All these useful features are based on the hardware support for In Circuit Programming and Debugging of the PIC16F87X family. These features make you loose some resources: two I/O pins dedicated for the in circuit programming and few RAM locations used by the ICD on the target CPU.

 

Microchip sells the ICD kit for $150 with or for $100 without the target CPU headers. This is a good price, but the reason why build your own ICD – as I deed - is to learn more about how it works and to gain some experience with 16F87X applications.

Building the ICD from scratch is not quite an easy job. It takes some time – let say a weekend time – patience and practical experience. My intention is to give a bit of help to the challenger that wants to start to build up the ICD on his own. I will present the project step by step. I will show how the hardware of the ICD works and how to test the circuit. And more, I will disclose how to avoid the more probable mistakes.

 

The whole circuit is built on a rectangular peace of breadboard (3.5”X2”  - RadioShack 276-147). Because the breadboard is larger I have used the rest of it for the Target Demo Board. The original Manual and schematic diagram of the ICD can be found on the Microchip web site at www.microchip.com as document DS51184 together with ETN #20 and ETN #21 notes. Reading these documents is a must in order to get familiar with the ICD.

 

The main goal of this project was to maintain the compatibility and the original features of the ICD. The power supply is built using a Wall wart adapter (8-12V) and a 7805 linear regulator. The Target Demo Board is powered from the same 7805. If it is necessary all this arrangement can be reversed and the ICD powered with 5V from the Target Board. Diode CR1 protects the circuit against reversed polarity voltage from the Wall wart adapter. The ICD generates the -/+12V and 13V voltages internally from the +5V power line.

 

The first step is to build the +5V Power Supply and test it as it is shown in Figure 1. I have used a small heat radiator for the 7805 because the Target Board is also using the +5V voltage generated by this IC. The Red LED indicates that power is ON and the Green LED indicate the presence of the +5V voltage. The voltage from the green LED is also used as Reference by the A/D so. Consequently, it is very important that its value be ~1.94V. If the voltage is different the ICD will give you wrong readings for the VDD and VPP and an error will occur. The secret is to select a green LED, which has the right voltage drop. I have used a bicolor LED, successfully. At this step is quite easy to measure the voltage over the green LED and to select the right one. Also make sure that the 7805 work properly and test the +5V supply.

 

The second step is to build the RS232 Interface as shown in Figure 2.  In order to connect the ICD to the computer Serial Port a nine Pin Male to Female cable is used (straight serial cable). This kind of cable can be found ant any Computer Store. The ICD will be equipped with a 9 Pin PCB Female connector.

 

The MAX 232A IC is used to translate the RS232 -/+12V levels to TTL +/-5V. Also the MAX232A IC has a charge pump that generates the -/+12V voltages from the +5V voltage (C5, C6, C7 and C8 are used by the charge pump). The ICD needs a +13V voltage for the VPP. I have used a different method than the original ICD to generate this voltage. The original ICD use a inductor and a transistor driven by the PIC CPU to generate the high voltage, then one linear 7812 regulator to get 13V.

 

The method used by me requires fewer components, don’t use a inductor and the voltage and all the VPP switching circuit can be checked before the PIC CPU is inserted into the socket because the MAX232A charge pump is used. The circuit uses C9, C11, D1 and D2 and, basically, is another step-up converter on top of the +10V charge pump. In order to explain how this circuit works I need to present the charge pump mechanism of the MAX232A and this is not the purpose of this article. The maximum output voltage of the circuit is Uout=2XVCC+VCC-2(Ud)= 15v-2X0.7V=13.6V (Ud is the forward voltage for the 1N4148 diode).

 

If the circuit is working OK we have +10V on Pin 2 of the MAX232A, -10V on Pin 6 and 13.5V on the + terminal of C11. If these voltages are different then please check the circuit for mistakes.

 

In third step wee need to build the VPP switching circuit and the Target Board Interface. The circuit is shown in Figure 3.  Q3 and Q4 form the switch for the 13V VPP voltage. Q2 is the reset generator for the Target Board and R16/CR2 the 5V supply for the MCLR/VPP pin of the Target CPU. It is very important to use a low voltage drop diode for CR2 as shown. Diodes VR1 and VR2 are protecting the VCC and VPP lines.

 

The voltage on pin 1 of the ICD connector must be 5V (4.8-4.9V) if no other voltages are applied to RC1 or RC5. If +5V is applied to RC1 the voltage at pin 1 of the Connector must be ~12.7V. In this case Q3 and Q4 are ON and the +13V is connected to the VPP of the target. The 13.5V voltage will drop to ~12.7v because of the (R21+R22) parallel with R24 load. The +13V voltage generator is quite sensitive and, because of that, R23 and R24 have been increased from 10K in the original design to 100K in order to reduce the load. The Target CPU don’t use the VPP voltage for programming, this voltage is used only to enter in the programming mode, so the only load for the VPP circuit are the resistors.

If +5V is applied to the RC5 pin then the voltage on pin 1 of the connector must drop to zero. In this case Q2 will be on and the target CPU will be in reset mode.

 

Please apply the +5V(VCC) voltage to the RC1 pin using a short wire and check the ~12.7V at pin 1, then remove the +5V from RC1 and apply it to RC5. Check ~0V at pin 1. Now remove the +5V from RC5 and check ~4.9V at pin 1. If the voltages obtained are different please check the circuit for mistakes.

 

The fourth step is to mount the 16F876 socket and interface circuits as shown in Figure 4. Because a 28-pin dip socket was difficult to find I have used two 14-pin sockets mounted together. Do not mount the 16F876 in the socket until all the final checks are done. The smallest mistake can destroy the IC, instantly.

The clock circuit is composed of C1, C2 and Y1. The original crystal used is 3.6864Mhz. I have used a 3.579545Mhz color carrier crystal. This gives about ~-3% error for the serial baud generator but works OK.

 

16F876 used Ports:

DRA3 is the Reference Voltage for the A/D=1.94V.

R1 and R2 form the divider for the VDD measurement applied to DRA0.

R21 and R22 form the divider for VPP measurement applied to DRA1.

RC7 and RC6 pins are used as serial interface RX and TX.

RC3 and RC4 pins are used to connect to the Target CPU at RB6 and RB7.

RC0 is not used by the ICD (is not connected to the target CPU).

The reset of the 16F876 is generated from the serial interface pin 4 and connected at pin1.

RC1 is the +VPP switch and RC5 is the Reset switch for the Target CPU.

 

Before inserting the 16F876 in the socket ALL the voltages at each pin should be checked once again, including VCC at pin 20 and GND at pin 19 and 8. The 16F876 must be programmed with the ICD software, unfortunately a new 16F876 cannot be used.

 

If everything is OK and the ICD is powered up, but not connected to the computer the Green led will blink.

 

The fifth and final step is to connect the ICD to the computer and start the MPLAB software (downloaded from Microchip web site). Please follow the steps as described in MPLAB ICD User’s Guide (DS1184).

 Once the ICD is connected to MPLAB the LED stops blinking and remains lit. At this moment the Target Board can be connected and the ICD can be used to program/debug the Target CPU.

 

MPLAB display the VDD and the VPP voltages. Because the reference of the A/D is the Green LED and the dividers were designed with +/-10% tolerance resistors a fine tune was necessary in order to get the right readings from MPLAB Screen. Disconnect the ICD from the Computer and REMOVE the 16F876 from socket. Apply +5V on pin RC1 (12), Ground on pin RC5 (16) and measure the voltage on pin 1 of the Target Board Connector and take a note, also measure the VDD voltage at pin 20 and take a note. Now disconnect the power from the ICD, replace the 16F876 in the socket and connect the ICD to power and serial cable. Reconnect MPLAB software and read the values for VDD and VPP. If the values are different adjust the resistors from the VDD and VDD dividers (R1/R2 and R21/R22). In my case VPP value was OK – 12.73V but VDD reading was 5.15V instead of 4.95V. I have added a 100K resistor in parallel with R2 and I got the correct reading of 4.95V.

 

The connector between the ICD and the Target Board must have at least 5 pins (VPP, VDD, GND, RB7, and RB6). Pin 6 is not used/connected to the Target Board. The pin numbers were kept as in the original ICD but the model of the connector can be different. I have used a UTP network style connector. The length of the wires between the ICD and the Target Board must not exceed 20 inch, otherwise the ICD will not work as expected.

 

The Figure 5 presents a minimal schematic diagram for a Target Board. The board can accommodate 28 pin 16F876 or 40 pin 16F877 (but not at the same time!). For the 28-pin socket, again two 14 pin sockets were used. The Push Button and the LED are useful to check that the Target CPU is working as expected.

The Reset circuit is modified from the original Demo Board in order to reduce the load on the VPP line by inserting the low voltage drop diode in series with the 47k resistor.

 

Building and testing this circuit took me about three evenings, so is not a quick job. I have used a plastic enclosure for the ICD in order to protect it (all the connections were realized with thin wire) and for a better look. The Target Board has a lot of free room for the applications.

The ICD is a great product from Microchip. My Project is a clone made for learning purposes, but is working exactly as the original. The original Schematic of the ICD, DS51184 publication and MPLAB software are ©2000 Microchip Technology Incorporated.

All the parts can be found at RadioShack, Jameco and the Microcontrollers at www.digi-key.com.

 

 

Figure 1, the 5V-power supply

 

 

Figure 2, Serial and VPP charge pump

 

 

Figure 3, ICD Interface and VPP switches

 

 

 

 

Figure 4, PIC MCU

 

 

Figure 5, Target Board

 

Main