HMV Model 328A

ICSP Programmer

One of the great things about "F" series PIC microcontrollers is that the entire program is stored in flash memory.  They are designed to work with a simple interface which enables the chip to be programmed or reprogrammed without removing it from the board.  The additional cost of including an In-Circuit Serial Programming (ICSP) Connector on a board is negligible.  It takes only seconds to program the chip.  For a board under development, the advantages are obvious.  For production devices, an ICSP Connector enables easy field updates.

To enable programming of the PIC microcontroller based boards in this project, a special serial programmer is required.

There is much documentation and code available freely on the web for PIC microcontrollers, not to mention the MicroChip website, so I won't attempt to go into too much detail here about the inner workings of PIC microcontrollers.


ICSP Board Connector

Most pins on a PIC microcontroller can be programmed as either inputs or outputs.  In addition, specific pins may perform a dedicated task, such as an analogue input or serial output.  Two pins on a PIC microcontroller are designated for the ICSP interface:

  • RB6 (Bit 6 of Port B) - Programming Clock (PGC)
    The clock source comes from the programming device.
  • RB7 (Bit 7 of Port B) - Programming Data (PGD)
    The data line is bi-directional - that is, it can both send and receive data.

The ICSP Connector also connects to the MCLR/VPP pin on the PIC microcontroller.  This pin can also be used as an external reset input, but the chip needs to be configured to enable this.

If you are prepared to dedicate these pins on the PIC microcontroller exclusively for use by the ICSP Connector, you simply connect these pins directly to the ICSP conector, along with power and ground connections.

If you want to use these pins for other things when the board is not being programmed, you can use isolating resistors on the board.

In most cases, you can use a 10K resistor in series with an input with no effect on operation.  The ICSP Connector is still connected directly to the PIC microcontroller pin and the programmer only overides the normal input signal when sending data.

ICSP Connector
HMV Model 328A
ICSP Connector
1. MCLR/VPP
2. VDD (+5V)
3. VSS (Gnd)
4. PGC
5. PGD
6. +15V*
*See text

To use RB6 or RB7 as outputs, you can use an isolating resistor followed by a buffer such as a switching transistor or a ULN2003 Darlington transistor array.  These outputs will be active whilst the chip is being programmed.  For example, in my LED Controller Board, these drive LED Circuits #9 and #8 respectively.  Another thing to bare in mind is that when the chip is unprogrammed or erased, RA6 (Bit 6 of Port A) goes high.  In the LED Controller project, this drives LED Circuit #7.  In my case, I use this as a diagnostic display to show programming progress.  When the chip is erased, the speaker turns green.  During the programming phase I get green + blue + white.  During the verification phase I get blue + white.  When designing other projects, you need to use caution when using RA6, RB6 and RB7 as outputs.  You certainly wouldn't want to use these for mission critical outputs such as activating alarms!

For an example of how the ICSP Connector is configured, refer to the LED Controller Board digital section.


Programming the PIC Microcontroller

To enable program/verify mode, pins RB6 and RB7 of the PIC microcontroller are held low (0V), whilst the MCLR/VPP pin is first pulled low to reset the device, then raised to the programming voltage (VPP), which is 12V - 14V for most PIC chips.  Note that the maximum operating voltage of most PIC chips is usually 6V - only this one pin may be raised to this higher voltage.

It should be mentioned that there is another way to program most of the newer PIC chips, known as Low Voltage ICSP Programming Mode.  As the name suggests, no special high voltage is needed to do this.  The drawback of this method is that it requires the chip to be configured to use a dedicated pin (RB3) for this sole purpose.  This method is not supported by the programmer described here.

The HMV Model 328A ICSP Programmer

This programmer is based on Microchip's Aplication Note AN589 - A PC-Based Development Programmer for the PIC16C84.

The first thing to say about this document is that it's old, written in 1997.  One big thing that has changed is that most new computer motherboards no longer include a parallel port.  In addition, operating systems like Windows XP, Windows Vista and Windows 7 make it increasingly difficult to use your parallel port for a job like this!

Ideally, you would buy a dedicated product for this purpose, with a USB interface.  But it is my understanding that you are talking at least $200.00, plus the hassle of finding the right one for this and future projects.  In my case, my GigaByte GA-EP31-DS3L motherboard includes a parallel port and I am running Windows XP.  Whilst I am aware that it is a bad idea to lock yourself off to older operating systems and hardware, the thought of being able to build an interface for under $10.00 won out at the end of the day!

There are many websites with designs for cheap programmers, many based on the AN589, whilst some are based around the now even more obsolete RS232 serial port.  For what it's worth, here's my version.

The standard AN589 circuit requires an external power supply set to 13.5V for the correct programming voltage and includes a 5 volt regulator to run its own circuitry.  This version takes both +15V and +5V from the ICSP Connector itself and therefore does not require an external power supply or 5 volt regulator.  A trimpot allows you to set the exact programming voltage required for the PIC chip.

Be warned though - my ICSP Connector is non-standard, with pin 6 being used for +15V.  The first 5 pins conform to the standard ICSP Connector, but pin 6 is normally either unused or for low voltage programming (connects to RB3).  If you need to program one of my boards with a different device, you may need to remove or disconnect pin 6.  Apart from this, there are only minor differences from the original circuit.

Obviously, this interface relies on both +5V and +15V being available on the board you are using.  If you are working on a project which runs off (say) a 3V battery, you would need to temporarilly power the thing from a 5V source for this type of interface to work and you would probably be better off to stick with the original design.


ICSP Programmer with Parallel Port Interface
ICSP Programmer with Parallel Port Interface
ICSP Programmer Board
As you can see, the board for this project is quite simple.

HOW IT WORKS

 

The serial data line and clock signals coming from the parallel port are buffered by IC1 - a 74HCT244 tri-state buffer IC.  When these outputs are disabled, this has no effect on circuit operation and the ICSP Programmer can be left connected during the development phase.  On the board under development, 10K isolating resistors in series with RB6 and RB7 have no effect on normal operation and these pins could be configured as either inputs or outputs.  When IC1 is enabled, this takes priority since it is connected directly to RB6 and RB7.  Data lines D2 and D5 from the parallel port are used to enable the IC1 outputs.

To read data back from the chip, RB7 (PGD) is also connected directly to the parallel port ACK input.  In this case, pin 10 of IC1 would be disabled.  The programming clock source (PGC) is always generated by the host software via the parallel port.

R1, RP1, R2 and Q1 derive VPP from the +15V rail.  Q2, Q3 and Q4 form the equivalent of a tri-state output, only this switches between 0V and VPP.  In a similar way to RB6 and RB7, at 10K resistor isolates the MCLR pin from the rest of the circuit on the board under development.


 

Programming Software

First of all, you need to develop your code using something like the MPLAB Integrated Development Environment, available as a free download from Microchip.  You write your code in either assembly language or C.  You then "build" your project, which produces a hex file ready to download to your chip.  You can simulate the operation of your project in the MPLAB environment.  It includes syntax error checking and de-bugging tools.

To get your hex file into your chip using the ICSP Programmer, you can use IC-Prog Prototype Programmer, available as a free download.  One thing this website doesn't make clear is that you also have to download the IC-Prog NT/2000 driver to get around the limitations imposed by Windows on access to your parallel port, otherwise IC-Prog will crash on startup.  This file should be placed in the same folder as ic-prog.exe.  There is no mention of support for Windows 7.

Although there are lots of settings in this program, there is not a lot you have to do apart from selecting the type of programmer you are using (AN589) and the type of chip you are using.  You then load your hex file.  Most of the other settings are done automatically when you load a hex file produced by MPLAB, which includes chip configuration settings.  Once your hex file is loaded, you simply click the Program icon.

One thing to note here is that if the programmer is connected when the main computer is started or reset, this will also reset the board under development.  In addition, Windows will initiate a second reset while it is loading and initiating drivers.


Testing the ICSP Programmer

Before using this device, you need to test it.  Since it relies on power from the board under development, the best thing to do is remove the PIC chip.  Also remove IC1 from the ICSP Programmer.  (Like all good developers, you did put these on sockets, didn't you?).  Don't connect the parallel port yet.

Power up the board and confirm you have both +5V and +15V present in the right places on the ICSP Programmer.  Also confirm that there is no voltage present on any of the parallel port pins.

If all is well, install IC1, connect the parallel port to the computer and fire up IC-Prog.  In the menu, select Settings|Hardware Check.  This allows you to toggle the state of the various ICSP signals.  Monitor TP1 and check that it switches between 0V and VPP.  Adjust RP1 so that VPP = 13V.  Also confirm that PGD and PGC are operating correctly.