How to choose a MicroController
It used to be that the number of different microcontroller chips available to the hobbyist was pretty limited. You got to use whatever you could manage to buy from the mail-order chip dealer, and that narrowed down the choice to a small number of chips.
But times have changed. Digikey lists over 16000 different line items under a âmicrocontrollerâ search. Which one should a hobbyist with no particular prior experience choose?
Here are some hints. These are particularly aimed at someone trying to pick a microcontroller to use for the first time at least partially as a learning experience, rather than someone who wants to accomplish a particular task.
Update 2009-01-28: This Instructable was recently mentioned in some popular blogs, and is getting a bunch of new readers. Be sure to read the âcommentsâ made by other readers and the responses to them; thereâs a lot of value in those commentsâŚ
Step 1
What IS a âMicrocontrollerâ ?
If you ever took a very introductory computer course, you probably learned about the major components of ANY computer:
- A Central Processing Unit or CPU. The part that actually performs logic and math
- Memory. Where the computer stores data and instructions
- Input and Output or I/O. How the computer moves data between its other components and the real world.
A microprocessor uses microelectronic fabrication techniques to shrink the CPU to a very small size; usually a single âchip.â
A microcontroller uses the same techniques to shrink the entire computer to a single chip (or very small module.) CPU, Memory, and I/O all in a little package as small as a grain of rice. Just connect up power and it starts doing its thing; computing and talking to the world. Usually the I/O on a microcontroller is aimed at âlow levelâ hardware like talking to individual switches and LEDs instead of keyboards, internets, and displays (like your desktop computer.) A microcontroller is just the thing you want, if you want to talk to individual switches and LEDsâŚ
Step 2
Show Stoppers
There are a number design considerations that might immediately reduce your number of choices a great deal.
Programability and Reprogramability:
At this point in time, I would say that a hobbyist should only consider microcontrollers that have internal flash or eeprom program memory and can be erased and reprogrammed a substantial number of times. There are also micros that can be used with external memory (adds complexity and expense), UV erasable micros (usually quite expensive due to the special packaging), one-time programmable chips (potentially usable after you have a working design, but losing their price advantage anyway), and mask-programmed chips (essentially useless.)
Peripherals:
If you want your microcontroller to have built in Ethernet, CAN, USB, or even multiple serial ports, many common choices are going to be eliminated. Some peripherals can be handy to have: UARTs, SPI or I2C controllers, PWM controllers, and EEPROM data memory are good examples, even though similar functionality can frequently be implemnented in software or external parts.
Itâs convenient if output pins can supply reasonable amounts of current for driving LEDs or transistors directly; some chips have 5mA or less drive capability.
Physical packaging:
Hobbyists are somewhat limited is the packages they are able to deal with, from a prototyping, PCB fabrication, and/or soldering. That 256 ball BGA coldfire CPU may be sweet, but itâs effectively unusable by mere mortals. Microcontrollers available in 0.1in DIP packages are much easier to deal with. Probably anything with a pin spacing smaller than 0.05in should be viewed with some skepticism.
Memory:
The size of memory may be an important consideration. Some micros have as few as 256 innstructions and 16 bytes of RAM. You can do a lot in that sort of space (believe it or not), but not everything. Moreover, while you can frequently upgrade to a âbigger chipâ, some chip families have relatively small memory limits imposed by their architecture, so even the biggest chip you can get will have only 8k instructions (for example.) RAM (data memory) is usually scarce in microcontrollers; some algorithms require substantial RAM to be implemented in a straightforward manner, and it may be worthwhile looking for a micro with a lot of RAM (or external RAM expansion capabilities) if thatâs the sort of thing you had in mind. (For instance, implementing TCP/IP networking protocols in a micro whose total RAM space is less than used by a typical ethernet packet is likely to be ⌠interesting.)
Step 3
Thoughts about Architectures
The âarchitectureâ of a microcontroller refers to the philosophy of the internal implementation, sort of. It includes details like how many âregistersâ there are, and how âgeneral purposeâ those registers are, whether code can execute out of data memory, whether the peripherals are treated like memory, registers, or yet something else, whether there is a stack and how it works, and so on.
You will hear people talk about how some architectures are better than others. I suppose this is true. But Iâm going to claim that it is largely irrelevant for the typical hobbyist. If you wish to avoid the architectural quirks of a particular family of microcontrollers, you can use a high level language. If youâre willing to program in assembler, youâre at a level of interest where learning and overcoming the quirks is party of the stuff you should be learning. Besides, weâre not talking here about evaluating some new architecture that some company is proposing. All of the chips I mention in this instructable have been around long enough that theyâve proven that their architectures are good enough for MANY real applications.
Here are some architectural âfeaturesâ you may read about and some explanation of what they mean.
CISC/RISC. Complex Instruction Set Computer. Reduced Instruction Set Computer.
In the old days, CPU designers were getting clever and wanted their CPUs to support high-level language features in hardware, leading to cobol-like string manipulation instructions that accepted arguments in blocks of 8 registers. IIRC, it was Berkeley and IBM who noticed that compiler writers didnât really know how to USE such complicated instructions from a compiler, the amount of silicon real estate used by these instructions was getting large, and in fact the hardware implementation sometimes wasnât as fast as doing the same thing in software anyway. So they said âI bet we can make the CPU go a lot faster if we leave out these complex instructions and dedicate the silicon to more registers or cache memory or somethingâ, and thereby invented the RISC CPU. Nowadays âRISCâ is widely used by marketing departments to mean âwe donât have very many instructionsâ, even if the rest of the architecture isnât very much like the original RISC researchers had envisioned.
Harvard Architecture.
In a Harvard architecture, the instruction memory and the data memory are separate, controlled by different buses, and sometimes have different sizes. For microcontrollers, the instructions are usually stored in âread onlyâ memory, and data is in RAM or registers. An example is the
PIC microcontroller, where instructions are in 12, 14, or 16 bit wide flash, and data is in 8bit
wide RAM.
Von Neuman Architecture.
In a von Neuman Architecture, data and instructions share memory space, so you could do things like dynamic compilation to generate instructions in RAM and then execute them. The TI MSP430 is an example of a von Neuman architecture.
Accumulator based
In an âaccumulator basedâ architecture, there is usually one âspecialâ register where most of the actual computation (math, logic, etc) occurs. Some effort has to be spent to get operands into the accumulator and results back out to where you need them. The opposite is a processor with âgeneral purposeâ registers, where any of several registers can be used for math/etc.
Load/Store
A load/store architecture typically means that operands to ALU operations have to be in registers, so that you have to load them from memory beforehand and store them back when operations are complete. The opposite typically allows operations between a register or
accumulator and a memory location directly. RISC architectures tend to be load/store, since a lot or the CISCness of CISC processors shows up in implementing complex âaddressing modesâ for accessing the memory operands. In a RISC architecture, all that complexity only has to be implemented in the load and store instructions (if at all.)
Registers
Memory Mapped I/O
Step 4
Thoughts about Hardware Tools
Minimally, youâll need some sort of programmer to load the program into the microcontroller.
These vary wildly in cost. Itâs pretty common for manufacturers to offer some low-cost programmer so that people can âevaluateâ their microcontrollers without risking too much cash (or requiring director level approval đ âlow costâ used to mean âless than $500â (which happens to be a common âexpensableâ limit), but the number has been going down. I think you can find manufacturer supplied development tools for most of the microcontrollers mentioned here for
$50 or less.
Cheaper tools can be bought from third parties, or built yourself. If you donât mind the possibility that bugs in your tools might cause more problems than bugs in your code.
Maximally, production gang programmers, In circuit emulators, logic analyzers, oscilloscopes, lab-bench power supplies⌠You can spend as much money as youâve got, probably.
Step 5
Thoughts about Software Tools
All of the microcontrollers mentioned here have some level of standard tools (at least an assembler) provided by the manufacturer. Most have âIntegrated Development Environmentsâ (IDE) that allow integrated use of an editor (that you wonât like) with the assembler, some compilers, and a simulator (of perhaps limited value.) Some have significant additional support from the open source movement.
Tools from manufacturers arenât always great, but you appreciate them more after youâve tried to use a microcontroller that doesnât have any such tools availableâŚ
Step 6
The $100 Paradox
If your budget extends as far as $100 for the computing hardware, itâs worth noting that you
have bought your way into an interesting realm of âbang for buck.â
âAboutâ $100 will buy:
â Relatively fancy development board for most micros; covering a wide range of processors and performances (including PC compatibles, for instance.)
â brand new Low end palmtop (ie Palm Z22)
â used last-generation desktop system (go two generations old and you can probably get a display too.)
It WONâT buy much in the way of custom development, if youâre paying for it.
Now a palmtop makes a lousy motor controller. But if you âneedâ the color display and touchscreen, it might be easier (and cheaper) to add motor control electronics to a palmtop than it is to add a display to a bare microcontroller. Especially since the palmtop comes with a development environment for making the display DO thingsâŚ
Step 7
Microchip PIC Microcontrollers
The Microchip PIC microcontrollers were perhaps the first that were marketed to the hobbyist and student community, one of the first microcontrollers to be offered in a relatively small package (18 pin DIP) and one of the first to implement flash or eeprom program memory (in the PIC16C84 in 1993)
Architecture: harvard, accumulator based (mostly)
Package sizes: 6, 8, 14, 18, 20, 28, 40, ⌠100
Program memory size: 256 words (12bit words = one instruction) to 256k bytes (2 bytes=1 instruction)
Data RAM: 16 to ~3900 bytes (4096 byte address space, shared with peripheral registers.)
Special features: EEPROM, 20mA output drive, several âsub-architecturesâ
Flash memory based PIC microcontrollers curently range from vanishingly small 6-pin chips in SOT23 packages to 100pin TQFPs. The basic architecture has been extended to chips with 16bit ALUs and integral DSP functionality.
Microchip has a liberal sample policy and chips are widely available from many vendors.
Step 8
Resources for Microchip PIC
- Microchip the Manufacturer
- PICList mailing list repository of knowlege
- [http://techtrain.microchip.com/masters2004/(kgmnvafutocq2355egt11231)/downloads/classlist.htm Microchip Masters Conference 2004 Downloads] Tutorials and presentations
- [http://techtrain.microchip.com/masters2005/(kgmnvafutocq2355egt11231)/downloads/classlist.htm Microchip Masters Conference 2005 Downloads] Tutorials and presentations
- Starting with PICmicro Controllers Tutorial
- PIC Elmer 160 Another Tutorial
- WinPicProg Tutorial Tutorial w hardware designs.
- PIC vs. AVR smackdown A comparison between PIC and AVR
There are a bunch of existing Instructables that use use Microchip PICs:
Intro to PIC Microcontrollers
PIC micro Timer Code
âTouchTimerâ EggLight
Business Card PIC Programmer
Buildng the Inchworm ICD2 PIC Programmer / Debugger
Other PIC Instructables
âŚCollaborators feel free to extend this page hereâŚ
Step 9
Atmel AVR
As near as I can tell, Atmel came along and decided to steal some of Microchipâs business by offering âsimilar but betterâ chips. Some things they did right, some things they didnât do so well. But the Atmel AVR chips have also gained a lot of popularity among hobbyists, and we get to cash in on the sometimes-war between Atmel and Microchip. My subjective observation is that microchip seems to do low-end chips a bit better, and Atmel does high-end chips a bit better.
Architecture: harvard, GP register based (mostly)
Package sizes: 8, 14, 20, 28, 40, ⌠100
Program memory size: 1k byte to 256k bytes (2 bytes=1 instruction)
Data RAM: 32 to 8k+32 (32 bytes of gp registers, 0 to 8k of RAM)
Special features: EEPROM, 20mA output drive
Step 10
Resources for Atmel AVR
- Atmel the Manufacturer
- AVR Freaks Despite the amateurish name, this is a REALLY good site.
- PIC vs. AVR smackdown A comparison between PIC and AVR
- AVR Butterfly The AVR âButterflyâ evaluation board is a phenomenal value at the current price of $20.
- Another Butterfly vendor
GCC supports all but the smallest AVRs; giving you a C compiler of substantial quality for free.
- GCC and WinAVR
- Arduino is a sort of combination of some standardized hardware based on the ATmega8 or ATmega168 and a simplified development environment that hides some of the complexities of using gcc for AVRs. See also under âmodules.â
Product guides/comparison charts:
- Device list at AVR Freaks
- Atmel AVR MCU Comparison Table Non-official table contributed by skylen
Instructables using Atmel AVRs:
Getting started with AVR microprocessors on the cheap
Programmable LED
Synchronizing Fireflies
Other AVR Instructables
âŚCollaborators feel free to add additional information hereâŚ
For more detail: How to choose a MicroController using PIC16C84 microcontroller