SLTF Consulting
Technology with Business Sense

 Home | Bio | Contact Us | Site Map


Small PIC12C family provides programmability and speed at a price

Scott Rosenthal
August, 1997

Recently I've been working with a device that's programmable, fairly speedy and costs roughly the same as a logic chip—specifically, Microchip's (Chandler, AZ (602) 786-7200) new PIC12C508. I began thinking about its true nature, is it a PLD in disguise, a small ASIC or a "real" micro-controller? Or is it another step on the evolutionary path of the embedded world? The answer, I believe, is a bit of each. But as with most things in life, a little bad always comes with the good. The PIC12C is a neat part, but it has its quirks.

What's a PIC12C?

The PIC12C family presently consists of two devices: the 12C508 and the -509. The main difference is the amount of memory. The -508 comes with 512 words of program memory and 25 bytes of RAM, whereas the 509 increases program memory to 1024 words and RAM to 41 bytes.

While most microcontrollers provide enough pins to expand their memory busses, the PIC12C has just eight in either a through-hole or surface-mount package. At its heart resides a RISC processor that uses only 16 instructions, but the device also integrates an oscillator, watchdog timer (running from a separate oscillator) and a power supervisor with a reset generator. Of the eight pins, two handle power and ground. The other six serve for I/O, or you can attach an external crystal to two of them, leaving four I/O pins. The PIC12C runs at 4 MHz, yielding an execution speed of approximately 1 µsec/instruction (branches take 2 µsec). The chip also includes a Sleep mode that reduces current consumption to a measly 8 µA.

The device's biggest selling point is its cost. The OTP version sells for a little over a dollar in singles! For development purposes, one version selling for roughly $10 comes packaged as a windowed part that you can erase and reburn.

The beauty of these parts comes from trying to figure out where you can use something that's programmable, fairly speedy and costs roughly the same as a logic chip. Some of my examples include a battery-powered logic-debounce and qualification circuit, a simple analog-signal input to time-delay output, a light dimmer, a closed-loop ac motor controller, a reset controller and a device-configuration register. One thing apparent from this list is that a PIC12C easily takes on some of the low-level chores designers previously might've implemented exclusively with analog circuits. Once developers see how versatile these parts are, their manufacturing departments will start wondering how they’re going to manage the production process for getting the different programs for various designs into the different PIC12Cs throughout systems.

Tell me it ain't so

Just as the embedded world provides opportunities for many different designs, it also involves numerous design tradeoffs, and the PIC12C presents no exception. All its potential flexibility comes at the price of quirkiness. You’re thinking, "What do you expect for a dollar?" The answer is, of course, everything—but short of that lofty goal, the following lists of problems with the device might save you some of the headaches my staff encountered with projects involving the device.

Starting with some obvious peculiarities, first, this microcontroller uses an internal 2-level hardware stack. When I first saw this spec, I was instantly transported back to 1973 and my first microprocessor, the 8008. It also used a hardware stack, but it had seven levels. It's roughly 24 years later, and it seems I've taken a step backward. Anyway, with a 2-level stack it's difficult to build nicely structured software because you can't have more than two calls in a call stack. One solution around this stack limitation is to throw away program memory and use macros to implement some simpler subroutines an application might need.

Another peculiarity is that you must locate all program subroutines in the bottom of memory, and you can't make a subroutine call above address 0FFh. This program memory allocation isn't difficult to accomplish, but a programmer must remember to do it.

Being a RISC processor, the PIC12C has a very limited instruction set. In fact, one of its 16 instructions (6% of the total) is a NOP. Nuances programmers find while learning such a small set present some challenges. The biggest issue we've discovered is the lack of a logical shift instruction. The chip performs an arithmetic shift, meaning that the Carry bit is really a ninth bit in the shift. To perform a logical shift without the carry requires you to clear (or set) the Carry bit before each shift.

For developers only

The remaining peculiarities involve the windowed part. You wouldn't use this erasable device in production, but it's handy for development. It does, though, bring along a unique set of problems.

One of the PIC12C applications at my company involved a battery-powered circuit. The design goal was to keep current consumption below 14 µA. We initially reached this level with a combination of Sleep mode and watchdog resets. Then suddenly we couldn't get there anymore—it started drawing more than 300 µA! We were running the same code but saw a different circuit effect. We called Microchip and heard that running the PIC12C without a cover over the window drives up current consumption. We covered the window and consumption dropped back down to acceptable levels.

Next, we found that occasionally a PIC12C appears to program as expected but just won't work properly in circuit—but sometimes the same chip, programmed again, works fine. Again, with Microchip's help, it turns out that if you program the windowed part without a cover it might seem to program correctly but not run properly. Now, we place the label over the window before programming, an approach that cures both this problem and high-current consumption.

Later we discovered yet another glitch with the windowed part. This programmable part issue really isn't a problem with the part itself, but just one of those things that you don't think about. Most engineers cut their teeth erasing memory chips, which they plop into an eraser and 10 to 30 min later out the chips come, fresh for a new program. The PIC12C parts also emerge from an eraser ready with a clean slate except they require twice the dosage of UV energy for erasure. By erasing them like a memory chip, the chips won't always program correctly, or one might even stop working after a short time. The table shows some recommended erasure times for different types of erasable parts.

Probably the strangest quirk was the oscillator's calibration value. An internal RC circuit sets up the system clock. Apparently, due to manufacturing tolerances, variability from part to part is too large for a "precision" device. So Microchip includes with each device an oscillator value that adjusts operational speed to be near the 4-MHz specification. The only problem is Microchip stores this value in high program memory. So the first time you work with a windowed part, everything seems to work fine. Then, after you erase the part and reprogram it with your next try at perfection, things don't seem to run very well.

What we found is that the UV erasure also removes the oscillator calibration value! Of course, the value isn't recorded on the body of the part, so we had to determine the proper calibration value for each erased part. Now each time we plan to program one of these parts, we also program the oscillator value by hand. While tracking this value painfully affects the development process, it has no effect on production OTP parts. Please, Microchip, write the value on the body along with the part number! PE&IN

The author would like to thank Tad Klopcic of MicroSol for his assistance with this column.

About Us | What We Do | SSM | MiCOS | Search | Designs | Articles

Copyright © 1998-2014 SLTF Consulting, a division of SLTF Marine LLC. All rights reserved.