strict warning: Only variables should be passed by reference in /sites/linuxpc.info/httpdocs/modules/book/book.module on line 559.

Microchip PIC

This is work in progress (14-2-2010).

The PIC is a family of microcontrollers developed by Microchip. On this page we will focus on the PIC18F4550 which is a microcontroller with USB support. Back in 2007 I did a lot of work on this, but due to lack of time I was forced to put it aside for a while, until now. In the meantime the development software has changed a bit, as well as the Linux distributions, so we will be going back to square one, which is a good opportunity for newcomers to join in.

First you need the microcontroller itself of course, and you need a programmer in order to program the microcontroller. You can build a programmer for yourself, as I did back then. However nowadays it is not really worth the effort as you can buy the Pickit 2 programmer for under 50 euro's, and it is often more reliable than a low cost self made programmer.

Installing the software for the Pickit 2 programmer

We will install and use pk2cmd which allows you to control your Pickit 2 programmer:

  • install the package libusb-dev:
    aptitude install libusb-dev
  • download the source of pk2cmd from http://www.microchip.com/pickit2. The software is nearly at the bottom of the page, section "Linux & Mac OS X software (Unsupported)".
  • extract it, cd to it, and build it:
    tar zxvf pk2cmdv1.20LinuxMacSource.tar.gz
    cd pk2cmdv1.20LinuxMacSource
    make linux
  • copy 2 files to the bin directory:
    cp pk2cmd PK2DeviceFile.dat /usr/local/bin
    chmod 644 /usr/local/bin/PK2DeviceFile.dat
    According to the readme file, the dat file should be copied to /usr/share/pk2 instead, and that directory should be added to your PATH, but the solution above also works, and it is less dirty IMHO.

Now connect your Pickit 2 and verify it is working by using this command:

pk2cmd '-S#'

The required firmware version on the Pickit 2 is v2.32.00 or later, so if an earlier version is reported, it is time to upgrade the firmware:

  • download the firmware v2.32 from the website
  • unzip it:
    unzip PK2V023200.zip
  • flash the hex file:
    pk2cmd -DPK2V023200.hex
  • check if it worked:
    pk2cmd '-S#'
    
    If the firmware version reported is 2.32.00 or higher then you are okay.

Here is a list of commands commonly used:

pk2cmd '-S#' list all connected Pickit 2 devices and their firmware version
pk2cmd -Dfile replace the firmware by the contents of the specified file
pk2cmd -Ppart -R -T power on the target, part is for example PIC18F4550. The -R option is needed to release the Vpp line, which is also the MCLR (reset) on many PIC's.
pk2cmd -Ppart -W power off the target
pk2cmd -Ppart -Ffile -M program the target using specified file

Connecting the programmer to the microcontroller

The pinout of the Pickit 2 is:

1 Vpp (programming voltage)
2 Vdd (target power, often 5V)
3 Vss (Gnd)
4 PGD (program data)
5 PGC (program clock)
6 Aux (not used)

To connect the Pickit 2 to the PIC18F4550:

Pickit 2 PIC18F4550 Optional, if PIC is programmed in application circuit
1 1 pullup 10k to +5V
2 11+32 do not make this connection if using external power
3 12+31  
4 40 10k series resistor to application circuit
5 39 10k series resistor to application circuit
6 n.c.  

It is possible to use the Pickit 2 programmer as (limited) power supply for your application circuit.

Getting and building PUF

The latest release of PUF is at the time of writing from 2007, so you are probably better of using the nightly CVS snapshot which you can find here: http://gforge.enseeiht.fr/snapshots.php?group_id=10. To build, first install flex and bison, extract PUF, cd to it, then do the following:

cd device/puf
aclocal
automake
autoconf
./configure
make

The pinout of the USB connectors:

1 Vcc
2 D-
3 D+
4 Gnd

 

host, A: +-----------+
         | --------- |
         |  - - - -  |
         +-----------+
            1 2 3 4

slave, B:  ---------
         /  -     -  \
        |   2     1   |
        |   3     4   |
        |   -     -   |
        +-------------+ (chassis part)

(This document is not finished. To be continued...)