Thursday, October 8, 2009

Standalone MON08 Device Programmer

Abraham Lincoln once said, "Give me six hours to chop down a tree and I will spend the first four sharpening the axe." In that spirit, I spend a lot of time building and refining the tools I use. So far, I've never regretted a minute of that effort, regardless of how much of a pain it was at the time.

My packing bench automation system is probably the best example of that, and I'll devote a post to it some other time, after I've added a few more of the features I've got on my list. But here's what I've been working on for a good portion of the past week:

It's a prototype of a standalone device programmer for Freescale HC08 microcontrollers, like those used in the OpenTracker+ and Tracker2. It's shown here with anMC908JL16 processor for the OT1+, which is presently the only thing it's set up to work with.

The hardware required to connect to an HC08 is actually very simple. I built my first programmer (way back before the OpenTracker 1) with parts I found in my junk box. I later upgraded to a board I bought from an outfit in the Czech Republic, and eventually to a USB pod from P&E Micro, of which I now have roughly a double handful thanks to package deals on development kits, freebies from Freescale, seminar handouts, and so on.

But all of those have required the use of P&E's programming software. Fortunately it's available for free, but they don't make it easy to find, and more importantly, they don't want you using it for automated production programming. For that, you'll need one of their $500 or $900 gadgets, or a nicer ($1200 + programming algorithms) system from one of their competitors.

I've never bothered, because with some creative use of a keyboard and mouse scripting tool I've been able to reduce the programming process to a single keystroke. Programming takes 30 or 40 seconds, much of which is avoidable overhead caused by P&E's software. It's a good job for a temp, and when the kids are out of school for the summer I can put them to work building up a stockpile of programmed MCUs.

Still, it's far from perfect. It could be much faster, and on occasion it'll choke and require some attention from a trained operator to get going again. More importantly, it requires a PC and it isn't something I can easily send off to a contract manufacturer. I'm making a major effort right now to reduce all of the post-assembly programming and testing operations to automated, standalone processes that can be easily run by anyone with minimal training - i.e., put the board in the programming fixture, press a button, and get a pass/fail result and maybe a test result printout on receipt tape.

Since I really need several of these things, and the $500 units aren't exactly what I want anyway, I decided to spend some time doing it myself. It's meant a few days at my workbench muttering and cursing - the programming process requires having the target processor boot a built-in program in ROM, then communicating with that program to load another program into RAM (which I had to write), starting that second program, and then communicating with it to actually do the erasing, programming, and verifying. And the one I/O pin you're guaranteed to have access to is not connected to any serial hardware, so it's all bit-banged. That tiny program, roughly 200 bytes, required several hours of coding and debugging. But the worst is over, and it's up and running now.

The unit shown above programs and verifies an OT1+ MCU in roughly 8 seconds. Pop the MCU in the socket, hit the button, and wait for the 'done' message. Lather, rinse, and repeat. P&E's "high speed" algorithm takes 20 seconds just to do the program and verify operation, not counting algorithm loading and user interface overhead. I haven't put any real effort into speeding up the process yet, but I think I can cut it down to 4 or 5 seconds without much trouble.

The code is still immature and doesn't elegantly handle error conditions (it just stops and displays a message, with no automatic retries or anything) but I've already added one useful feature I haven't seen elsewhere - it automatically detects when you've removed the target MCU, so it can clear the 'done' message and avoid any possible confusion when the operator gets distracted and forgets whether the chip in the socket is really done or if they just haven't pressed the button yet.

Total cash outlay for this prototype was roughly $10, including the perfboard (I hate FR-2, but the FR-4 perfboards were $30 and weren't the right size), button, ribbon cable, and connectors. Everything else I already had on hand. The green PCB is an AW-PROTO board, one of several dozen I had made for in-house prototyping of circuits build around the MC9S08AW series MCUs. I've got a big pile of those 16x2 backlit LCD modules, probably from when Electronic Goldmine or someone had a clearance sale. I actually got it mounted upside down, but I decided it doesn't really matter which way the board faces.

When the device is more mature, I may offer it as a commercial product. Might not be worth the effort required to document and support it, though. But in any case, I ought to be able to distribute a few to my overseas resellers to handle re-flashing of corrupted OT1+ and Tracker2 processors, and I'm looking forward to integrating it with the new automated OT2m test fixture that's in the works now.