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.


  1. I just discovered the same issue where the J53 series wont program unless the pickit leads are very short..

  2. I'm so glad to see someone like you taking the time to post issues like this! I too am transitioning to the 18F27J53 from the 18F4550 type family and inside information like this is amazingly helpful. Thank you so much for taking the time to present this information!

    I'm hoping you will post some information about firmware upgrading with code compiled with C18 and MPLAB, but using a boot loader to load the firmware. I would like to avoid getting a PK3, and eliminate the need for my PK2 if possible, using a boot loader.

  3. I have an alpha version of a Bootloader that loads hex files from an SD card. See the link to the PICBoot Repository in the right hand column near the top of the page. I hope to refine it and make it much more user friendly when I have the time. Also, thanks for the nice comment.

  4. I'm having exactly the same problem with a 16F1455. Tried allsorts today with occasional success but no real consistency.
    We were using the alternative programming pins (12 & 13) on the 1455 with an olimex pickit 3 clone, my mate was doing the same using his pickit3 neither of us was having any success.
    On a completely stripped-back board, I tried using the normal programming pins (9 & 10 ?) still with no joy, but then had success using the pickit to power the board.

    This sounds like a critical sensitivity to clock skew, possibly reading back. I'm going to have a go inserting Rs & Cs in various combinations in the programmer cable to see If it makes a difference. If so I'll report back.

    1. Awesome. Would love to here what you find.


Keep it clean and civil. That's all I ask.