Saturday, November 6, 2010

Sometimes It Gets Ugly

Well it's been a while since I posted an update. I ran into a wall and figured it might be useful to somebody if I post about it instead of glossing it over. I started working on the next episode and was hooking up an SD card to the sensor platform. I had to face some realities. The code to work with the SD card was pushing the memory usage high enough as to limit some of the other features I have planned. Also, the PIC18F2455 is a 5V device and requires special circuitry to be able to interface with a 3.3v SD card. I decided it was time to look into another PIC for the project. I went to Microchip's site and really poured over the chip comparisons and decided that the PIC18F27J53 was just what we need.

Enter the PIC18F27J53

I chose this chip for several reasons. It has WAY more code space than the 2455 tipping the scales at 128KB. Ram sits at 3800 bytes. It gets even better. It is capable of full speed USB, runs at 2 to 3.6V and is a member of Microchip's XLP (extreme low power) family which makes it great for battery life. This thing can run for years in deep sleep mode on a couple of AA batteries. On top of that it has a built in real time clock and calendar. Needless to say I'm really excited about moving forward with this chip. I ordered a few and got them in the mail.

Things Go South

This is where things went south. I refactored the project to use the 27J53 and got everything compiling which was a snap since all we're doing so far is flashing an LED. I popped out the 2455 from the circuit and snapped the J53 onto the breadboard. What followed was several days of programming errors. I kept getting the error "Target Device ID (00000000) does not match expected Device ID". All of the help online seems to be for people who have the programming pins mismatched or actually are trying to program the wrong part. I didn't have either of those. Just as a sanity check I popped the 2455 back in and verified I could still program it. I searched and searched and tried everything I could thing of with no luck. Finally I found one forum entry on Microchip's site where somebody suggested that the wires connecting the Pickit 3 to the device should be less than 5 centimeters. I didn't give it much heed because the 2455 was programming fine. I was ready to ship the J53s back to the manufacturer because I thought I had a bad batch. Finally I had had enough. I ripped the entire breadboard apart and started from scratch. The only thing I changed was I repositioned the programmer header so that I could make the PGD and PGC wires about 1.5 centimeters each. Sure enough, it works now. Unbelievable.

The Good in the Bad

Another reason I wanted to share this hangup is because a bunch of good came out of it. When I was in the pit of electronic darkness I really dug in. I poured over the datasheet and errata to see if I had missed something. I learned a bunch of things about the J53 that I wouldn't have otherwise known if everything just worked and I'm sure that information will come in handy as the project progresses. There is always some good that comes out of seemingly terrible situations. Don't just throw your hands up and give up. That's for suckers that can't work through the tough problems.