Micro Controllers

If you want to build a simpit and you don’t have a big piggy bank, you spread your purchases out over a long time, or you build rather than buy. If you are both possessed of a very small piggy bank and even smaller patience, you’re pretty much stuck in the build-it-yourself camp.

If you’re in the build-it-yourself camp, there is phenomenal value to be had in micro controllers. For a very few dollars/euros/pounds you can buy an 8-bit computer with memory and I/O that’s capable of executing at 20+ MHz. 

Now, just in case you’re jaded by today’s multi-GHz PCs, recall that the first PC was an 8-bit machine with a 4 MHz clock! Today’s micro controllers allow those in the know to apply little chunks of processing power throughout a project. They are, in essence, “universal glue” you can use to paste different parts of your simpit together.

Micro controllers

Above, a PIC16F628 (flash programmed, serial I/O, 2K program memory) and a PIC16C745 (UV erasable, USB, 8K program memory, analog in)

And this will let me do what???

At the low end are some micro controllers that fit in an 8-pin DIP, and have five I/O lines. You might use this to dim your cabin and panel lights. Use two I/O lines to monitor two momentary contact switches, one for “brighter” and one for “dimmer”. These allow you to increment or decrement a variable in firmware that sets the duty cycle of pulse outputs on the remaining I/O pins. These outputs control some power FETs that control current applied to your cabin and panel lights.

Mid range micro controllers have larger packages, more I/O pins, memory, speed, and options. You might use one to interface a set of throttles to your computer. Another could multiplex drive 7-segment LED displays. Another could take the place of an expensive keyboard emulator, and interface your overhead panel switches to your PC.

Mid range devices offer a variety of I/O options. You can choose between RS232C, I2C, CAN and USB, to name a few.

High-end devices get bigger and better. With more I/O pins, more memory and faster execution, you might choose to build an interface to your PC’s parallel port, or to develop an Ethernet interface for each of your ‘pit’s major sub-systems.

Often the limitation of what can be done with micro controllers is not the capabilities of the micro controller, it’s the mindset of the designer. Until you work with them awhile, it’s a little hard getting used to the idea of committing what is essentially a fully functioning computer to resolve a relatively mundane problem. Who would have thought, twenty-five years ago, of using a 4 MHz, 8-bit computer to dim panel lights?

PICs and AVRs

Two of hobbyists’ favorite manufacturers of micro controllers are Microchip, maker of the PIC series, and Atmel, maker of the AVR series. This is not to say that there aren’t other excellent devices available. It’s just that Microchip and Atmel have made it so very easy to get started using their products. The devices themselves are inexpensive, development software is freely available, and documentation is only a few web clicks away. As an added benefit a large, supportive hobby user community has sprung up.

Both families can be purchased through a variety of vendors, including Digikey, Mouser and Jameco.

Random tidbit: OTP, UV or Flash?

As you browse the catalogs, you will notice there are OTP, UV erasable and flash micro controllers. Prices vary widely, but you need to understand the differences.

OTP stands for one time programmable. The chip has a non-reversible programming mechanism. OTPs are cheap, but you better get it right the first time as you can’t erase it.

UV erasable chips have a little window on top of their package. The memory on the chip can be erased by exposing it to ultra violet light for several tens of minutes. The chips are relatively expensive because of the complex packaging. Further, you must have a UV EPROM eraser to make use of this feature.

A flash device incorporates an electrically erasable memory (“EEPROM” or “flash” memory). Flash micro controllers can be erased by the same device programmer used to program them. A flash device is the most convenient to use but not the least expensive. Still they are less expensive than UV erasable devises.

Resources – Getting started

The Atmel and Microchip websites both offer device documentation and application notes. There’s no question that you’ll need this information, but by itself it may not be enough. If you aren’t already somewhat familiar with microprocessors, a more graduated introduction may be of value. One option is the PICKit2 starter kit from Microchip that comes with software, a device programmer and several tutorial lessons.

PICkit 2

A much more detailed and indepth option is Myke Preko's book,  Programming and Customizing PICmicro Microcontrollers, 2nd ed. It covers all aspects of the devices. It’s both a tutorial and a reference.  I recommend it.

Another book of potential interest is Designing Embedded Hardware by John Catsoulis. It doesn’t have the detail as Predko’s, but it covers more than just the PIC family.

You don’t actually have to buy a book to get started. Nigel Goodwin has put together quite a nice website with a number of introductory PIC-based projects. Working through them should give you a good start, quite likely enough to make sense of the information available through the manufacturers.

Resources – Software

The availability of free development software is a tremendous benefit. Both Microchip and Atmel offer IDEs (integrated development environments) for their products. True, these aren’t the full-blown IDEs with all the bells and whistles, but they’re pretty darn good, nonetheless. The IDEs include an editor, an assembler and a simulator.

Writing in assembly is more time consuming, but allows very tight control of execution time, a feature that is quite important in some applications.

There are also some “lite” versions of high-level languages that are free. These versions do not offer the full functionality of the purchased versions, and may be limited in program size. For example, PICC Lite from HI-TECH Software is an ANSI standard C compiler for the PIC family.

Resources – Device Programming Hardware

Both PICs and AVRs support in circuit serial programming, “ICSP”. This functionality places a good portion of the device programming hardware and firmware on the chip. It provides the ability to update a product’s firmware without physically disassembling the product. It also means that these devices are very easy for the hobbyist to program. Some very simple device programmers have sprung up.  

The PICKit2 from Microchip is a low cost way to get started. It comes with a demo board and a PIC16F690. The demo board can accept a number of other PIC micro controllers for programming. It's a versatile little unit.

PICkit 2

Not all PIC micro controllers have pinouts compatible with the PICKit2 demo board. For these, you can use a proto-board and a few wires.

PICkit 2

The PICKit2 programs a respectable number of the microchip PIC family. However, it will not program them all. It seems to support only the newer devices. For example, it will recognize and program a PIC16F628A, but not a PIC16F628-20.

All things considered, however, the Microchip PICKit2 is an excellent tool for working with PIC micro controllers. It comes with two CDs filled with the Microchip IDE, a lite version of the PICC compiler, data sheets and tutorials. It's available for US$50 plus shipping from www.microchip.com 

If you'd prefer to build a device programmer yourself, then consider the JDM programmer pictured below. It connects through an RS232C com port to your PC. It takes power from the signal levels of the port itself. As the devices being programmed are very power thrifty, very little power is needed. This is a clever design, but requires that the RS232C signals swing at least +- 6.5 volts. The programming voltage needed is about 13 volts. The programmer “makes” this voltage by bridging between a high level signal and a low level one. Some com ports do not support the true RS232C specs and may not provide enough voltage to run this programmer. Nonetheless, this is a great hobby device programmer and for the low cost can be easily tried.

DIY programmer

Schematics for the JDM device programmer are available from the JDM homepage. Several versions of this programmer are available in kit form through Spark Fun Electronics and Olimex.

Some years ago David Tait developed a device programmer that connects to the PC’s parallel printer port. Mr. Tait is apparently no longer so active in the PIC device programmer arena, but you will still read of "Tait variant programmers" . This has become almost a synonym for "parallel port programmer".

If you bought the 2nd edition of Predko’s book, you got a printed circuit board for a parallel port device programmer. Predko optimized the design for low cost. Appropriately, he calls it the “El-Cheapo” programmer. You can find details about it on Predko's website.

A current designer of parallel port interfaced device programmers is Bojan Dobaj. His designs include the PICALL and P16PRO device programmers. Information is posted on the PICALL website, and on Nigel Goodwin’s site. (my rather casual version of a P16PRO is shown below)

DIY device programmer

DIY Electronics markets a very wide variety of kits including a handful of device programmers. The company’s website lists the full range of kits and often includes full documentation. The site also lists retail outlets for the kits.

Resources – Device Programming Software

There are several freeware and shareware applications for driving DIY device programmers. In some cases you may find that the free version is limited in the program size it will upload to the micro controller.

WinPicProg is freeware from Nigel Goodwin. It covers many of the PIC micro controllers. It is designed to drive parallel port device programmers and can be configured easily for different hardware variants. It is available from Goodwin’s site.

Myke Predko has written some code for driving the “El-Cheapo” parallel port device programmer included in his book. The code is available from the CD included with the book, as well as, from Predko’s website.

PICALL is shareware from Bojan Dobaj. It will drive the PICALL and P16PRO device programmers. It is available from the PICALL web site.

IC-Prog is freeware by Bonny Gijzin. It is extremely versatile and can be configured to drive both com port and parallel port device programmers. It is available from the IC-Prog Prototype Programmer web site.

Caveat Simmer

Before you make a decision on hardware or software for programming these devices, check to see if they support your chosen micro controller. Devices range in the amount and type of memory, as well as, in the arrangement of configuration bits. New micro controllers come out frequently, but freeware and shareware authors do not always have the time or inclination to maintain or update their applications.