ESE101: Picking a Processor Platform

I’ve covered quite a bit in ESE101 so far. It started with a fictional microcontroller and now you understand how a microcontroller uses instructions, registers, and memory to get its job done.

The fictional microprocessor was good enough for introducing the basics, but it’s time to move on to a real microcontroller. Read on to learn more about the microcontroller I’ve chosen, and more interestingly why I chose it.

TL;DR: I chose the TI MSP430 architecture for the rest of ESE101, specifically the MSP430F5529 chip in the MSP-EXP430F5529LP LaunchPad development kit.

Pretty much any microcontroller can run pretty much any program you want, given enough time. So why would you choose one over the other? To misquote 19th century poet Elizabeth Barrett Browning, “How do I select a microcontroller? Let me count the ways.”

Here’s a fun exercise to get started: Digi-Key is basically Amazon for electronic components. Go to Digi-Key, bring up their microcontrollers, and stare in amazement at the vast number of options. Really, go stare at it. I’m looking at it right now, and I see 60936 options. Scroll left-to-right across the top of the page to see how many manufacturers, clock speeds, IO, memory sizes, and other options are available. In case you don’t click through, here’s the three full screens of options I see as I scroll all the way across the options:

What does it all mean? Here’s a few of the common things we care about when choosing a microcontroller.

Architecture

There are many different embedded microcontroller architectures (aka “families”). Some of the most common ones are:

  • ARM: This British company is the biggest name in the microcontroller business. ARM chips come in many sizes and configurations, from the smallest chip that runs a Fitbit, to the main processor in your iPhone, all the way up chips that run servers. ARM doesn’t sell its chips directly, though. Instead, other companies like Silicon Labs, ST, NXP, TI, and many others license the basic design from ARM, add their own special sauce, and sell it themselves.
  • AVR: This architecture, created by Atmel, powers most Arduino designs.
  • PIC: Microchip’s PIC has been around since 1976 (happy 40th birthday!) and it’s still going strong. Microchip recently bought Atmel but the AVR and PIC architectures are likely to remain separate.
  • 8051: Intel invented the 8051 in 1980. This was my first microcontroller, and despite its awkward architecture, I’ve got a soft spot for it.
  • MSP430: Texas Instruments created the MSP430 as a low cost and low power microcontroller.

As with any other topic, Wikipedia has a much larger list of different microcontrollers.

If you use the same microcontroller architecture for a project or two, you’ll start to become familiar enough with it that you might prefer using it on future projects too. Don’t underestimate the value of the time you’ve spent and the learning you’ve done. Switching to a new microcontroller architecture costs you time and bugs while you learn the new architecture.

Performance

Some microcontrollers have high frequency clocks (200-500+MHz), but many run much slower (10-100Mhz). A faster clock roughly translates to doing more work in less time. How much does your microcontroller need to do each second?

Microcontrollers come in 4-bit, 8-bit, 16-bit, 32-bit, and even 64-bit variants. “32-bit” means that registers are each 32-bits wide, and most instructions can operate on 32-bit arguments. In general, more bits means more data can be processed in a given time.

Also, a microcontroller’s instruction set can help it perform more work in less time. For instance, a microcontroller with a dedicated instruction that gives the square root of a number will run the square root operation much faster than a microcontroller without a dedicated instruction. The microcontroller without a dedicated square root instruction requires that you run a square root algorithm in software, which can easily take much longer (and use more memory) than a dedicated square root instruction.

Memory

The amount of RAM and flash memory on a microcontroller will determine how much software you can write, and therefore how much it can do. Rule of thumb: when you choose a microcontroller family that meets your other criteria, then buy the specific chip in that family with as much RAM and flash as you can afford. You can buy cheaper chips with less memory in the next version of your product.

You will always be glad to have more memory.

I’ve worked on projects that ran out of memory and spent days and weeks combing through the code and data trying to save a byte here or a couple bytes there. It’s an interesting intellectual exercise, and I’ll admit it’s even kinda fun, up to a point. But it’s so much better to just have enough memory to start with.

Cost

As you can see in the Digi-Key search, you can pay anywhere from $0.30 to $100+ for a chip. That’s a huge difference! Generally you’ll pay more for higher performance, lower power, or more specialized applications. Typical costs in systems I’ve worked on are between $0.50-$10 per chip. It’s also possible to buy directly from a vendor rather than through Digi-Key, so prices can be lower than you see at Digi-Key, but at least you get a rough idea of the range of costs.

Power

Some microcontrollers are designed for low power applications, some are not. As with cost, power consumption varies widely. If your embedded system will plug into a wall with A/C power then power is not a huge concern. But if you need to run your device for a year on a tiny coin-cell battery then power will be a priority for you when choosing a microcontroller.

(Aside: Embedded guru Jack Ganssle has an excellent article about low power design. Actually, go read anything on Jack’s site - he’s a good writer with a ridiculous amount of experience in embedded systems. He also did a great interview on the Embedded FM podcast.)

Software Support and Ecosystem

How many compiler options do you have for a particular microcontroller? Is there an IDE? Are the compilers/IDE free, or how much do they cost? Does the chip vendor have a bunch of example code for the chip? Does the example code look like it was hacked together by interns, or does it look professional?

How easy will it be to get answers for the problems that you’ll have? (You will have problems, no matter which microcontroller you choose. Even if the chip and example software have zero bugs, we humans will create bugs of our own.) Try searching google for “<your chip> SPI problem” to see how much help is out there for problems you may encounter. (SPI is the name of a common communication peripheral.) Compare the number of results for the different chips you’re considering. Also browse the vendor’s support forums.

Do you need a networking stack? A graphics driver? A filesystem? Make sure that software exists for your chosen platform.

Peripherals

Peripherals are the parts of a microcontroller that interface with the outside world. (It’s also a great book by William Gibson, but I digress.) Examples of peripherals are I2C, SPI, UART, timers, GPIOs, and USB. We’ll talk about these in later posts.

Look at your system’s requirements to figure out what peripherals your microcontroller needs to have. Do you need USB? What speed USB? Do you need a flash memory card? Do you need to talk to 10 sensors using SPI? Do you need 20 GPIOs to control circuits on your circuit board?

Physics

I use “physics” to mean the physical aspects of a microcontroller. What temperature and humidity does it need to withstand? Expect to spend more for chips that can survive in extreme environments.

How big can the chip be? What type of circuit board assembly process will you be using? Some chip packages can be easily be soldered onto a circuit board by hand, and some require specialized circuit board assembly equipment.

Availability

Your company or product may have requirements about how many chips are needed per year, or the speed new chip orders can be delivered, or how long a chip will be available for purchase. Many companies have operations departments whose job is figuring out these supply and availability issues.

Now What?

There’s a lot to consider when choosing a microcontroller. If you’re overwhelmed by all these options you can use this method:

This is sort of a joke, and sort of not. “If it ain’t broke, don’t fix it” is a good rule of thumb.

Get To The Point, Already

As I said before, I chose the MSP430 for the rest of this series. I chose it because of these reasons, in roughly this order:

  • Cost: I don’t care about per-chip cost for ESE101, instead I wanted a development kit that was reasonably cheap. My goal was less than $20. A “dev kit” or “evaluation board” is a circuit board that includes everything you need to get started using a chip. The MSP430 has a wide range of dev kits called “LaunchPads” which are all $18 or less. The particular dev kit I chose is $13.
  • Availability: I wanted anyone to be able to order the MSP430 dev kit easily. TI sells it directly on their website and there are plenty of distributors who sell it all over the world.
  • Software Support: TI has a ton of software around the MSP430 ecosystem, including an Arduino-like system called Energia and a more traditional compiler + IDE called Code Composer Studio. Both are free.
  • Memory: The particular MSP430 dev kit I chose, the MSP-EXP430F5529LP, has the most memory of the MSP430 dev kits: 128KB flash and 8KB RAM. This is enough memory to do interesting work.
  • Architecture: Not a consideration for learning.
  • Performance: No preference: most microcontrollers are fast enough for learning on.
  • Power: No preference.
  • Peripherals: No preference: all but the smallest microcontrollers have enough peripherals to be good for learning on.
  • Physics: No preference.

Those are all good reasons that pointed me to the MSP430. But the single biggest reason I chose it is a reason I haven’t mentioned yet.

Learnability

Since the goal of ESE101 is to teach you about embedded software and systems, my top priority in choosing a microcontroller was to choose one that is relatively easy to learn as a first microcontroller. The MSP430 microcontroller is simple, and yet useful. It has 16 registers and 27 instructions. You can get a basic overview on Wikipedia in a few minutes. (Don’t worry, we’ll cover it all here.)

I found the MSP430 to be easier to explain than other microcontrollers; I hope you agree once we’re done!

Acquiring a Dev Kit

If you want to follow along the rest of ESE101 with actual hardware please buy the MSP430F5529 LaunchPad Evaluation Kit here: http://www.ti.com/tool/msp-exp430f5529lp#buy

Alternatively, Adrian Fernandez at TI has very generously supplied some dev kits to give away for free to people interested in following along here. We’ll have a contest to choose the winner. To enter you must send an email to ese101@embedded.fm and include:

  1. Say why you’re learning embedded software.
  2. Pick an integer between 1 and 10000, inclusive.

The contest begins when this post is published. The contest ends on Tuesday, April 5 at 11:59pm Pacific Time. All email must be received by then. Python’s random number generator will pick a random number between 1 and 10000, inclusive, and the guesses closest to it get the dev kits.

I’ll contact the winners for shipping info after the contest. Your email will only be used for this contest, and then it will be shredded, burned in a fire, and the ashes will be dumped at sea.

See you next week when we dive into the actual dev kit!