c & c++ - pic-programmer

Contact
PC-compilers
last-news
PIC-microcontroller
=> pic projects
=> pic-programmer
=> pic-compiler
AVR-microcontroller
Supports
weakly newsletter
c++
Counter
DS1821Thermostat Programmer
pic-asm-foundations
free links downloads
free downloads
mikroc library
PWM software
Home



 



 

What is a PIC programmer ?

A pic programmer is a circuit which interfaces the PC to the microcontroller using the PC's parallel,serial or USB port. It can write data to the microcontroller and read it back for verification.

The pic programmer translates digital logic levels from the PC to suitable logic levels for the microcontroller - most levels are ok as they are, but for 'normal' (or high volt) programming of a pic microcontroller the following voltage at the MCLR pin is needed:

  • Minimum : Vdd + 3.5V
  • Maximum : 13.5V

source : PIC application note ICSP (DS30277)

 Note: the maximum input voltage to the pin is (MCLR) 14V.

 The 13.5 volt level complicates the interface circuit since the voltages from the parallel port or USB port are not that high. Typical digital logic levels are nominally 5v so usually these programmers require use of an external power supply to generate the higher voltage.

 The serial port generates higher voltages and this fact is used by programmers such as a JDM pic programmers.

 To program older pic devices you need a high voltage programmer.

The programmer should isolate the microcontroller so you can test the microcontroller program while the programmer is still attached.

How does a pic programmer work ?

All pic programmers work the same way (except the bootloader - see later) - they generate a serial data stream using two signal lines clock and data. Another pin controls the programming voltage (at MCLR) and two others supply power and ground.

 Another program running on the PC (the programming software) takes the hex file generated from your compiler translating it into a serial data stream. This is routed to your programmer through the correct interface (Serial,Parallel or USB). From there the programmer presents the signals to the microcontroller.

After all the data is sent, a serial configuration word is sent, and voila - the microcontoller is programmed ready for use.

 Serial or parallel programmer

Serial or Parallel programmers describe the PC interface used not the programming method - all pic microcontrollers are programmed serially. Serial programmers connect to the Serial port and Parallel programmers connect to the parallel port.

The signals used at the parallel port interface still generate serial data - this is why a parallel port programmer is no faster than a serial port programmer.

 

In fact the speed of programming is determined by the pic programming algorithm and is much slower than any of the PC interfaces. In general programming a Flash pic device is quite slow (16F877A 30 seconds).

 

Programming seems slow when you make minor code changes and want to see the result quickly but compare this to old style EPROMs - you used to remove the chip from the board and put it under a UV light for 30 minutes!  

LVP

A method called LVP (or Low Volt Programming) is available for newer PIC devices - as it suggests you don't need the higher voltage. The disadvantage is that you loose one pin which may be ok for larger 40 pin devices but probably not for 18 pin devices. It would depend on your circuit requirements.

 Note: You can only change from LVP to HVP (High Volt Programming - normal ICSP programmer) if you have an HVP programmer. The parts that are LVP capable are factory shipped with LVP enabled. So always pull the PGM line low with 10k (approx.) when first programming (with HVP).  

Bootloading

There is one other way of programing a pic device and this is using a piece of software called a bootloader. This method is only usable on the newer devices that can re-program parts of their own FLASH memory.

 It is a small program that typically monitors the USART receive data line (RX) and activates itself if there is any activity on this line within a set time period after reset e.g. one second from power up.

 When activated it accepts data from the Rx line using it to program the rest of the FLASH memory i.e. it does not overwrite itself. When all data has been loaded and programmed it starts up the new program or boots (starts up) and loads hence Bootloader.

 interestingly it is called a bootloader referring to a legend about Baron Münchhausen who was able to pull himself up by his boot straps; an impossible task. The process of booting (bootstrapping or starting a system) also seems like an impossible task if you ask the question how can I load and start my program if there is no program in the device to load and start my program!

The answer is that you use a simple piece of software to load the more complex one. This simple program then transfers control to the new program. In a PC this is the BIOS bootstrap code. For the PIC micro you program the bootloader code using a pic programmer.

Why use a bootloader ?

Since you need a normal pic programmer (or High Volt programmer) to get the bootloader into the microcontroller in the first place why bother with it?...

 Answer 1: It is faster than serial programming using ICSP.

Answer 2: You can load code into a fully built system.

 The bootloader lets you use any interface (depending on how you program the microcontroller) to load code. Its main use is in finished equipment where software updates are needed (without opening the box up and plugging in a pic programmer). Equipment that normally uses an RS232 port could be bootloaded through that port. All you would need is a serial cable and hyperterminal (available in Windows).  

bootloader advantage

  • No programming hardware - simple programming. 

bootloader disadvantage

Uses up some resources - less Flash memory available for main program.

  • You have to use a microcontroller that can re-program its own flash memory

    There are tons of pic programmer circuits.

    This is a list of some of the programmers available as circuits that you can search for on the web.
    • JDM Programmer (Ludipipo)
    • Conquest programmer
    • TAFE Programmer
    • TAIT 'Classic' Programmer
    • Parallel TAIT programmer
    • Fun-card Programmer
    • SCHAER Programmer
    • ProPic II Programmer
    • STK200 Programmer
    • AN589 Programmer
    • WILLEPRO Programmer
    • Fluffy2 Programmer
    • DL2TM Programmer
    • ER1400 Programmer

    The above list shows programmer types supported by
    ICPROG [opens new window]

    There are many more circuits! but - they all do more or less the same thing
     

    What you really need in a programmer.

    There are several elements to a programmer but the most important is the ICSP connection.

     Possible programmer features...

    • ICSP connection.
    • Stand alone programmer - DIL socket.
    • Stand alone programmer - ZIF socket.
    • Serial port powered.
    • USB port powered.
    • Power brick powered.

    Don't buy a Serial port powered programmer if you use a laptop as its output power may not be good enough to operate the programmer (laptops like to make power savings to save their batteries!).

    Some also use only +/-5V outputs as this level is still within the RS232 standard (although it will not work over large distances). The minimum high and low voltage for receiving RS232 is +/- 3V (normally the transmitter generates +/- 12V). The manufacturers get away with this as most uses of RS232 are short distances on the desk. For a programmer it means there may not be enough voltage to create the 13V for the Vpp signal!

    Note: If you want to program chips by removing them from the target board you will want a stand alone programmer. To save money you could buy one with a DIL socket - just make sure to remove the chip using a chip extractor and not your fingers and thumb otherwise you may end up using your thumb as a rather nice pin cushion - believe me it hurts. Perhaps the ZIF (Zero Insertion Force) socket is a better choice!  

    If you have not got a chip extractor then use a screwdriver - alternately lever up each end of the chip - don't just lever one end up as you will bend all the pins at the other end.

    The single most important feature you need in a pic programmer is the pic ICSP connection.

    ICSP - In Circuit Serial Programmer.

    This is a set of connections that let you program the pic microcontroller while it is in your circuit - there is no need to remove the chip just program it.

     This is the most convenient way of developing a prototype (apart from bootloading - see earlier) as all of the hardware once connected is just left as it is on the bench i.e. no removing of chips between programmer and prototype.

     You can also connect the ICSP wires to a solderless plug block breadboard so this is also quite an easy way to develop circuitry but be careful where the Vpp wire is placed (13V) - not all the pins can withstand this voltage so make sure it is at the MCLR pin.  

    If you buy a programmer with just ICSP then you can program most PIC devices.

     Usual connections for ICSP:

    • VPP - Programming voltage (usually 13V).
    • VDD - POWER (usually 5V).
    • VSS - GROUND.
    • PGD - DATA usual port and connection RB7.
    • PGC - CLOCK usual port and connection RB6.
    • PGM - LVP ENABLE usual port and connection RB3.

       

      Build your own parallel port programmer.

      To be honest I got fed up with the amount of circuits available as there are so many to look at and I also wanted something that was going to work. I decided to follow the one recommended by microchip themselves. It follows the AN589 application and gives you a programmer with an ICSP output connection.

      Note: Not all the controls from the parallel port for this circuit are used by ICPROG - but this does not matter. It performs well if you add a transmission line terminator - a capacitor and resistor!.

      See the following link for building your own parallel port programmer circuit including the transmission line terminator which allows it to work using a six foot parallel port cable.
       

      Recommendations

      If you want to build your own pic programmer and have a PC with a spare parallel port then use a parallel port programmer. This is the easiest route as it is the programmer that is most likely to work and it's easy to debug.  

      If you do not want to build your own then the preferred programmers are parallel port or USB port programmers. With Serial port programmers (based on JDM types) there is a chance they won't work fully depending on your PC hardware.  

      Always choose a pic programmer with an ICSP connection.

    PIC Programmer Circuit diagram

    Click on the following diagram to open it as a PDF document.
     

     

    ein Bild

     
     

    Disclaimer : If you build this circuit you must double check each connection to the parallel port cable to avoid damage to your computer. This includes checking for shorts between each pin at the parallel port on your circuit. For initial testing it is best if you use a spare (old computer). Building this project is your own responsibility and I can not be held responsible for any damage to your computer.

    Modifications

    It has a few modifications that are useful and easy to do:

    • Transmission line termination - lets it work over a long cable.
    • LM317 voltage regulator to get 13.5 volts and protect the circuit
    • Power supply steering diode (stops you reverse connecting the supply).
    • Changed LM340-5 to 3pin 100mA LM78L05.
    • ICSP connector.
    • An LED to show that power is applied.
    • Changed 74LS244 to 74HCT244 because I had one handy!
    • Standard 10k resistors instead of 2k - just easier if they are all the same.

    Circuit notes

    Transmission line termination

    The transmission line termination lets you use the pic programmer circuit at the end of a long cable - I am using a normal parallel cable ~6 feet long. If you want to know more about transmission line terminations then follow this link.

    When I first tried to use it I got all kinds of random results so it is worth adding the termination.

    Power supply regulators

    The LM317 saves you needing an accurate bench power supply - you can use a dc power block - anything that supplies more than about 16V dc. If you don't use a 317 it's just too easy to accidentally apply the wrong voltage by turning the dial on a bench supply and frying your microchip. Using the 317 lets you put up to 35V into it (you shouldn't but you can).

    Note: the LM317 and LM78L05 are standard components and are easy to find.

    To save using odd resistor values I used a 10k and a 1k to set 317 output voltage. The equation for the LM317 is:

    Vo = 1.25 * (1+R2/R1)

    Vo = 1.25 * (1+10k/1k) = 13.75V

    To drop it down a bit (in case the resistor tolerance pushes the voltage higher (you can not go over 14V for MCLR) I used a series silicon diode to drop about 0.6V bringing the Vpp voltage to approximately 13V.

    5V power supply

    Following on from this is the 5 volt regulator which is only used to power the LS244 buffer. Its just not worth using a Zener diode supply as the actual voltage at the Zener varies with the load (it's voltage is only specified for a constant current through it) you then need a transistor to isolate the Zener so its just easier to use the three pin regulator.

    Note: The pin out of the LM78L05 is different to its larger counterpart the LM7805.

    It is not a good idea to power the board from the programmer as :

    • The 5V regulator should be designed for the target board i.e. heatsinking etc.
    • You could get more noise into your circuit.

    If you want to power your board from the programmer then change the 78L05 for a 7805 which can supply up to 1A but for higher current it will need a heatsink.

    Buffer

    The pic programmer circuit is a bit wasteful as it only uses two gates from the eight available in the LS244 but it's a cheap part anyway.

    Q1,Q2 and Q3 can be replaced with any standard general purpose transistors (two npn and one pnp).

    Software

    You can use ICPROG with this pic programmer circuit. It erases, programs and verifies your pic microcontrollers.

    ICPROG also controls resetting the microcontroller at the end of verify so after programming and verifying the program will start.

    ICPROG is a good choice for programming software as it has many programming algorithms for many devices (not just PIC microcontrollers) and it is FREE. It also specifically supports this type of pic programmer circuit i.e. the AN589 pic programmer circuit.

    Note: Double check the settings in ICPROG e.g. the HS setting for oscillator selection - otherwise you may find your microcontroller just sits there doing nothing!

    Details of pic ICSP and how to use it for pic microcontrollers.

    PIC ICSP stands for In Circuit Serial Programming and describes the serial programming interface for PIC micros.

    ICSP gives you a convenient way of programming PIC Micros without removing the chip from the development or production board.

    All you need is a programmer that provides the ICSP connector (usually a six or four pin molex connector).
    Note: Programmers that are labelled Serial or Parallel both send serial data to the PIC microcontroller through the PIC ICSP circuit. The 'Serial' or 'Parallel' description refers only to the interface used from the PC to the PIC ICSP circuit.

    Here is the ICSP circuit I use : 

    ein Bild 

  • PIC ICSP Signals

    ICSP provides 6 connections from the pic ICSP programmer to your board as follows :

     

    VPP (or MCLRn) Programming voltage (usually 13V).
    Vcc Power (usually 5V).
    GND Ground (zero volts).
    PGD - Data usual port and connection RB7.
    PGC - Clock usual port and connection RB6.
    PGM - LVP enable usual port and connection RB3/RB4.

    Note: With the connections made in this order on the connector it will not matter if the connector is placed the wrong way round as GND and VCC are then applied to clock and data. If VCC and GND had been at opposite ends of the connector then there would be a problem.

    VPP Signal

    Vpp connects to the reset input of the pic microcontroller labelled MCLR. During programming or verify this signal is raised to the programming voltage (13.5V) - or VCC+3.5V. This signals to the microcontroller that programming/verification is about to start and for older parts, supplies current.

    Note: Older pic micros used this line to directly power the programming circuit that updates the Flash memory. So this connection had to supply some current. With the newer parts that allow LVP (Low Volt programming) the programming voltage is generated internally so the Vpp signal from the pic ICSP is only used as an indicator i.e. it doesn't have to supply current.

    VDD/VCC Signal

    This connection may supply power to your board - usually using a 5V regulator (probably a 7805). This is ok for some use as you can develop a prototype board without needing any other power supply (just a power brick that plugs into the pic programmer circuit).

    The only problem with it is that the programmer circuit is not designed for your circuit (does it have a heatsink) and it can also introduce noise to your circuit. If the programmer uses a 78L05 then you will only get 100mA maximum current output.

    GND Signal

    The ground reference - 0V.

    PGC and PGD Signals

    These are the signals that do the work. Data (PGD) and clock (PGC) transmit data to the pic micro. First data is sent either high or low voltage (0/1). After a suitable time the clock is strobed low to high - rising edge clocking the data into the microcontroller.

    PGD is also the line driven by the pic micro during verify i.e. it is bi-directional.

    PGM Signal

    The purpose of this pin is to hold PGM low so the microcontroller does not enter LVP mode. It will usually be done using a pull down resistor e.g. 10k.

    Note: If you program the microcontroller with LVP mode off then this signal will have no effect.

    Note: PIC microcontrollers ship with LVP enabled - so if you use a brand new chip you can use it in LVP mode. The only way to change the mode is by using a high voltage programmer.

    What circuit do you need on your target board

    Note that the diagram from pic ICSP application note 'DS33023A' specifically goes out of its way to not design it for you saying RB6 and RB7 should be isolated but this depends on your circuit! This is not very helpful so I have included the circuit I use on my development board (See the diagram shown earlier):

    To ensure you can program and verify correctly two 10k resistors isolate the programmer (and RB6 and RB7) from the rest of the circuit i.e. they stop signals at the other side from interfering with RB6 and RB7 during programming. If you don't use the isolation resistors then loading or driving the pins can stop programming all together.

    For example if you put an LED on RB6 (PGD) that draws 20mA when on. The output voltage (when the output is on) will be pulled so low that the pic ICSP programmer will not be able to read back the desired voltage i.e. it will give a verification failure.

    PIC Programming using ICSP and ICPROG.

    This page shows you how to use ICSP for PIC programming giving some ICSP connection diagrams and it also shows how to use ICPROG - the PC software for programming a PIC Micro.  

    ICSP (In Circuit Serial Programming) is the serial interface used by the PIC micro to download a program into the PIC micro's program memory.  You can also program the internal EEPROM as well.  




    ein Bild
     

    PIC ICSP connections

    This section shows connection pins for PIC programming.
     

    12F675 : ICSP PIC Programming connections:


     

    16F88 : ICSP PIC Programming connections:


    ein Bild
     

    16F877A : ICSP PIC Programming connections:


    ein Bild
     

    ICPROG for PICMicro

    ICPROG is a free windows program that you can use for PIC Programming. It interfaces using either the serial or parallel port on a PC, via programming hardware, to the ICSP pins on the PIC micro.

    You can download ICPROG here [opens a new window].

    ICPROG uses the hex file generated either from an assembler such as MPASM or a compiler such as MikroC.

    When you first start ICPROG this is the screen you see for selecting the hardware for the PIC programmer; I have selected AN589 programmer - a parallel port programmer.

     

    ein Bild
     


    After this the main program screen is displayed.  Don't be put off by all the address program code area.  The important controls are the Open button and the buttons with ICs underneath.

     Select DeviceTo  use it for PIC programming select the device from the menu Settings-->Device--Microchip PIC - Here I have chosen a PIC16F877A. The Device menu also shows a lot of other devices that you can use with. ICPROG.
     
    Note the screen changes to accommodate the chip features (here EEPROM oscillator, program 'Write enable' and chip configuration bits).


      Hardware checkYou can check to see if ICPROG is communicating with your hardware by using the menu option Settings-->Hardware check.  This lets you toggle the state of individual ICSP signals and the VCC power.  

    Note you'll need an oscilloscope or multimeter to check the signal state.
     

    Load Hex file

    The next thing to do with the PIC software is programming the PIC by loading up the hex file (unless you have a 12F675 that has an oscillator calibration value that you will want to keep -in this case do a read first).

    Note: You have to select the device manually it is not defined in the hex file.  Although ICPROG stores the current device in use between sessions you have to select a new device manually when you start a new hardware project

    Note: Fuses and oscillator settings are controlled from the hex file so all you need to do is check that they match your settings in the compiler or assembler.


    Hit the open button to load your hex file.

    Note how the oscillator, write enable and fuses have changed (controlled from the hex file):  

    Erase device


    ein BildThe next PIC programming action is to erase the device by hitting the erase device button.  It sends a command to the PIC which erases the whole device including protection bits (in newer devices).  Old devices used to be un-usable after you had set the protection bits!

    So this command quickly erases the chip.

    Note: You don't have to use the erase button as the program button will overwrite the chip contents anyway.  It is sometimes useful if you want to convince yourself that the program is actually programmed into the device correctly.
     

    Program device


    ein BildThe program device button does just that it programs the contents loaded from the hex file (in ICPROG memory) into the program memory of the PIC micro.  If there is any EEPROM in the chip then it programs this as well. Finally it programs the configuration word.

     

    Verify device


    ein BildThe verify device button reads back the entire contents of the chip ensuring that it matches the hex file (loaded into ICPROG).

    Note: Depending on settings in Settings-->Options-->Programming verification may automatically happen at the end. Once you get used to ICPROG and your hardware works reliably you may only want to do a verify if something does not work otherwise it takes more time up.
     

    Read device


    ein BildThe read device button reads back the entire contents of the chip into the currently selected buffer (shown at the bottom of the ICPROG window). So you can save the hex file or compare it to the contents of another buffer.

    These are the only controls you need for successful PIC programming using ICPROG.

     

     

  • Today, there have been 14 visitors (31 hits) on this page!
    This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
    Sign up for free