pic18f4550 – first impressions

So I’ve decided to build a new circuit board to convert an old mechanical keyboard (NCD N97) from PS2 to USB. (A normal converter won’t work, as this keyboard only operates in “mode 3” which I very much doubt your average converter will know about). Initially I expected to use an Atmel ATmega32u4 or similar for this – but there’s no through-hole version of that chip, and I don’t want to have to produce a proper PCB and do surface mount soldering. (Atmel take note: I’d be using one of your chips if you did have a through-hole version!). My next thought was to embed a Teensy (or adafruit 32u4 breakout, or Teensy++) into the middle of some veroboard , but that means spending at least $20 on the chip, and I’d have a usb socket inside the keyboard which would then need to be routed to the outside etc.

A bit of googling led me to the Microchip PIC18F4550, which is available in 40pin DIP, and can be purchased from Futurlec for under $7 at time of writing. I order two, and a bunch of support bits (appropriate crystals etc).

Then I start to find that there are some fundamental differences between getting started in the PIC world compared to the AVR world (especially as a linux user who doesn’t want to spend the $$ on a proper programming tool like the PICkit 3).

It seems that the AVR-on-linux community has two big advantages – one is that there’s a nice GCC-based compiler which everyone uses, and the other is that avrdude supports a large number of different programmers, some of which are pretty easy to build. As a result, the community has pretty much a common toolset across the board. And thanks to the arduino project, you can even buy a bare chip with a bootloader on it fairly easily.

PIC-land is different. For a slightly-out-of-date view see this ladyada post. Apparently a GCC port isn’t possible, so there’s a bunch of different C compilers out there in use, most of which aren’t free. There also seems to be a dizzying variety of programming tools, most of which support a limited set of chips, seem to be rarely maintained, and only work with a small number of programmer hardware designs. On top of that, programming generally requires a 12V source (on a 18f4550 there is a low voltage programming mode, but it doesn’t seem to be widely supported and it eats a pin in the middle of an IO port). Which makes the programmer hardware more complicated. After several evenings googling and fruitlessly installing random unmaintained windows programmers (which is complicated by running windows 7 64bit, which doesn’t generally allow the sort of direct access to the parallel port these programs expected from Windows ME or whatever), I discovered that, at least for the 18f4550, the combination of Byron Jeff’s Trivial HVP Programmer circuit and the linux ‘pkp’ programmer which comes as part of PiKdev works nicely.

In addition, Microchip have their beta MPLAB X programming IDE available, which works on linux, and also have the “MPLAB C18 Lite Compiler for PIC18 MCUs” available for free-as-in-beer, along with the “Microchip Application Libraries”. The combination of these 3 allow you to build a bootloader which allows you to reprogram the chip using hid_bootloader. I’ve tweaked the bootloader slightly to suit me better; see my bootloader post.

Leave a Reply

Your email address will not be published. Required fields are marked *