This page initially started out

We’re gathering here to discuss small and cheap microcontrollers of the 8-bit (and maybe 16-bit) variety. Even though they are obsolete, people still use them, and we’d like to understand how to program them without bleeding too heavily.

I’d like to open this up. Since eight bit microcontrollers are obsolete, and ARM-based MCUs are dirt cheap, tiny, low-power, and ridiculously fast, I’d like to include the ARMs in this “OK Corrall”.

Please excuse the “Forth flavor”. I’ve really enjoyed using Forth to program microcontrollers, and so whether or not the language fits nicely on a given architecture is something I care about, and will likely comment on.


Freescale HC08 & Freescale HCS08

The latest spin on the 6800 architecture. It’s reasonably fast, but a bit starved for registers. There are nifty low-pin-count (8 & 16 pin) packages that could go head-to-head against a smaller PIC or AVR.

The HC08 family is the first generation ’08 architecture. The CPU maxes out at 8MHz (bus cycle frequency), and some of the peripherals (serial port especially) are a bit limited.

The HCS08 family is the latest and greatest. The CPU is pipelined and its bus cycle frequency maxes out at 10MHz, 20 Mhz, or 25Mhz, depending on the subfamily. The HCS08 also adds a nifty single-wire background debug mode (BDM) interface, a BGND instruction to enter debug mode, and augments the LDHX and STHX instructions with a few helpful addressing modes.

It’s a bit confusing because the Freescale literature crows about the HCS08’s “20 (or 40, or 50) Mhz CPU” (again, depending on the subfamily), whereas the HC08 literature says that it has an 8MHz standard bus cycle. You have to look carefully to realize that the 20/40/50MHz is a clock speed and not a bus speed. The on-chip clock generator allows various dividers for bus speed; the lowest is divide by 2, hence the maximum 10/20/25MHz bus speed.

To get an idea of how fast (or slow) these processors are, instructions take from one to six bus cycles; on average an instruction probably takes two cycles. So an HC08 running full-out will execute about 4M (8 bit data) instructions per second; the fastest HCS08 will do 12.5M.

My Spoken Word project page has more details about this architecture.


Atmel AVR

The AVR architecture is a really nice fit with Forth. Lots of registers (in particular, it has enough index registers to easily cope with Forth’s two stacks), high speed execution.

There are some nice small variants. My favorite, the ATtiny84 (a 14pin DIP package, 8k of Flash) is interesting, but I was unable to get samples or buy any, so I decided to use an HC08 on a current project.

In general, the tinyAVR subfamily has some interesting members, with new parts added regularly.


Microchip PIC

This is an interesting, and infuriating, architecture. It is RISC-like, with lots of registers – the peripherals exist in the register space, rather than in a separate I/O or memory space – and wide instructions (12 to 16 bits, though the CPU is only 8 bits wide). It is not a speed demon, but is tolerably fast. It comes in loads of different packages and sub-families – this is one of the infuriating things about it. Each subfamily has a slightly different instruction set, since the width of various fields depends on the amount of on-chip RAM and peripherals.

On some days I like the PIC architecture; other days not. The variety of chips and subfamilies is a bit overwhelming – it’s as if you need a PhD in PICs to know how to proceed.

(time passes)

I’ve done some more research, and I’d like to report that it’s not as bad as I thought. I’m interested in the lower-end PICs; for more horsepower I’ll turn to an ARM. The lower-end PICs divide into three subfamilies: the 10F, 12F, and 16F. All of the 10F and some of the 12F are called “baseline architecture”. These have a 12-bit instructions, very limited RAM (64 bytes or less), and limited Flash (1kword or less). The rest of the 12F’s and all of the 16F’s are called “mid-range”, have a 14-bit instruction, and max out at 8kwords of Flash. Some of these are quite powerful and feature-packed.

The 10F’s and 12F’s are tiny and cheap. They have 6 or 8 pins, and cost around $0.50 in quantity. The 16F’s are bigger, ranging from 14 to 64 pins.

I have singled out four chips that seem interesting; all pack quite a punch for their size:

All of these will run at 20MHz; all come with 8MHz internal oscillator. At four cycles per instruction that means roughly two MIPS.

The PICkit 2 Starter Kit seems like a good way to jump in. This is a USB programmer bundled with a project board that will accept 8, 14, and 20 pin parts. The project board includes a (socketed) 16F690 – a quite capable 20 pin PIC. There is another board coming available, also compatible with the PICkit 2, that will accept 28 pin parts.

It’s also possible to buy the PICkit2 programmer without a project board, for about $36.

The PICkit 1 Starter Kit is still available, and is a bit cheaper ($36 rather than $50), but it’s not as flexible and can only program baseline and midrange parts (the 10F, 12F, and 16F families). The PICkit 2 can program practically any PIC.

For both kits the bundled programming software is Windows-only, but the source code for the firmware of both programmers is available, so using either with non-Windows programming software is a possibility.

Both kits include introductory lessons in doing things the PIC way. These make the chips quite approachable for beginners.

Except for the invisible stack pointer and the W (working) register, the PIC uses memory locations in the data space as registers. This integration yields a parsimonious instruction set. A couple of the mnemonics are badly named, but overall it’s easy to learn and remember. W can be a bottleneck, but being able to write the result of an ALU op directly to data memory helps. The PC, oddly, is visible in the data space. This makes programmed jumps possible – useful for reading from program space (see below).

The PIC has only one “pointer” register; it is 8 bits wide and it points into data space. It’s possible to use it as a sort of data stack pointer. Because the PIC is a Harvard architecture, data and program spaces are separately addressed. As it happens, the baseline and midrange PICs have no way of addressing into program space. It’s possible, though clunky, to do “table lookups” by doing a programmed jump or call into a list of “retlw” instructions, which return a value in W. It takes one instruction – 12 or 14 bits – to store one byte, so it is inefficient.

The PIC has a very Chuck Moore return stack: eight slots, circular. The stack pointer is inaccessible, and it’s not possible to push or pop data. Only call and return touch the stack. (I think the really low-end PICs have only three stack slots.)

It’s possible to register at http://sample.microchip.com/ to get free samples of practically any of their parts.


Texas Instruments MSP430

The MSP430 is a cheap, ultra low-power 16-bit RISC microcontroller from Texas Instruments, similar to a PIC or one of the Atmel chips. A bit of documentation:

This looks like a really nice architecture for Forth. It’s already 16-bit, so, unlike the 8051, you don’t have to do twice as much work for a 16-bit-wide Forth cell. It’s also small, low power, and quite fast.


ARM

There is lots to say here. The ARM architecture is quite nice. There are several nice & inexpensive ARM development boards available. (See those other pages for details.)


8051

One of the granddaddies, if not the granddaddy, of microcontrollers, and still going strong. The instruction set has a strong “bit-twiddling” flavor, rather than feeling like a general-purpose architecture. It’s a bit slow and register- and resource-starved to run Forth well, but it’s been done.

It’s still firmly in production, and new chips are being designed. Lots of manufacturers make them, each with their own quirks. One interesting thing is the proliferation of “cores”. The original Intel core took 12 clocks (1µs) to execute a 1-byte instruction. Newer cores take 6, 2, or 1 clock per instruction. So look at more than clock speed when comparing 8051s.

A bit of documentation of the 8051 family:

Some manufacturers:


Cypress PSoC

Cypress got into the mix with their own (??) simple 8-bit architecture, and a novel configurable chip that comes in tiny packages.

I know nothing about this architecture, but it looks interesting.