Selecting the right microcontroller for a project involves juggling many factors. In addition to cost, performance, power consumption, and overall size, the availability of the proper software and hardware tools is a prime consideration.
Support for the chosen platform is also very important - not just from the vendor, but from the community at large. It also helps if the chosen microcontroller has a readily available development board.
Finally, development time can be significantly reduced if the selected microcontroller has extensive, fully debugged, software libraries with well-documented Application Programming Interfaces, or APIs.
In this article, only microcontrollers that generally meet the above criteria will be presented.
All modern microcontrollers share some basic features. On top of a processing unit, they have a certain amount of flash that is used to store the application code, some SRAM, and, in most cases, some EEPROM.
They need a clock source, and this is normally provided by either an internal resistor-capacitor (RC) oscillator, or by using an external crystal for more timing-critical applications. They have some digital input/output (IO) ports, and at least one timer/counter.
Also, other than very low-end microcontrollers, most have at least one UART for serial communications. Beyond that, microcontrollers are distinguished by the amount of memory they have, the number and type of other peripherals integrated on the chip, and the speed at which they run user applications.
This is not just dependent on the raw clock speed; it also depends on the data width of the processor and any hardware acceleration features included.
Microcontrollers for embedded systems mainly fall into three categories based on the width of their data buses: 8-bit, 16-bit, and 32-bit. There are others, but these are the most popular ones.
In general, 8-bit microcontrollers are geared toward lower-end applications, and 32-bit ones are for the higher ends, with 16-bit for mid-end applications.
By far, most of the products I work on tend to incorporate 32-bit microcontrollers, but 8 or 16-bit microcontrollers can be a good choice for low-end, low-cost products.
If an application does not have very high demands on processing power, and is of relatively small size, then it can make sense to consider an 8-bit microcontroller.
For reference, most Arduinos are based on 8-bit microcontrollers. So, if you have built your early prototype using an Arduino then you may be able to use an 8-bit microcontroller in your final product.
Don’t let price alone though guide your decision, as in many cases 32-bit microcontrollers can be cheaper than 8-bit chips.
For example, the Atmega328p is the 8-bit microcontroller used the Arduino Uno. It costs a little over $1 in volumes of around 10k pieces. It runs at 20 MHz and includes 32 KB of Flash and 2KB of RAM.
On the other hand, you can purchase 32-bit microcontrollers running at 48 MHz with similar memory for only 60 cents. This is likely due to the popularity of 32-bit microcontrollers driving down their cost.
That being said, there are even cheaper 8-bit microcontrollers available that cost less than 25 cents at similar volumes.
8-bit microcontrollers should typically be considered for applications that are dedicated to just doing one job, with a limited user interface and little data processing.
8-bit microcontrollers come in all sizes from small 6-pin devices to chips with 64 pins. They have flash sizes ranging from 512 bytes to 256KB, SRAM sizes from 32 to 8KB, or more, and EEPROM from 0 to 4K, or more. A minimal system can be as simple as a single chip, with a bypass capacitor on the power supply rail.
The three most popular lines of 8-bit microcontrollers are the 8051 series, the PIC series from Microchip, and the AVR series from Atmel, now part of Microchip.
The 8051 Series
Originally from Intel, and now made by others, this microcontroller is still in common use today, embedded in lots of appliances.
While they are available as standalone devices, the 8051 is now mostly used as IP (Intellectual Property) cores that are embedded in the silicon of dedicated application-specific chips such as some wireless radio transceivers.
Very rarely would the 8051 be the correct choice to serve as the main microcontroller for your product.
The PIC Series
PIC microcontrollers are quite popular, and have wide support by both Microchip, and third parties.
Microchip provides its MPLAB® X Integrated Development Environment (IDE), which includes a C-compiler for free. Also available for free as an IDE plug-in is the MPLAB Code Configurator that generates C-code for the on-board peripherals.
This can then be integrated in the application code. There are PIC models with combinations of USART’s, SPI, I2C, ADC, USB, LIN, CAN, and other interfaces. Microchip also offers several development tools, including MPLAB PICkit 4, ICD 4, and Real ICE.
Higher-quality commercial compilers that have better code optimization are also available. Here is a quick PDF reference guide to PIC microcontrollers.
The AVR Series
Most Arduino boards are based on 8-bit AVR microcontrollers
The AVR is another series of very popular 8-bit microcontrollers. While they are in the same space as the PICs described above, and have comparable performances, they do have one big claim to fame: Arduino.
The original Arduinos, such as the Uno, Leonardo, and Mega, all use AVR microcontrollers. Due to the very wide range of available libraries for Arduinos, the AVRs merit serious consideration for 8-bit applications, even if only for proof-of-concept prototypes.
Since Arduino libraries are written in C++, they can be easily incorporated in any application written in C/C++.
Software development tools include AVR studio, or, if using Arduino, the Arduino IDE and Platform IO are both commonly used. The complier used in these IDEs is AVR GCC a free, very well supported and maintained C/C++ compiler.
Hardware development tools include the Atmel ICE and the PICkit 4. In addition, mature tools such as the STK600 and AVR Dragon are still widely available. Here is a link to a quick PDF reference guide for AVR microcontrollers.
16-bit microcontrollers are the next step up from 8-bit, while still sharing many of the same attributes. They are faster, support even more peripherals, and generally offer more memory, both flash and SRAM.
In addition to more IO pins, most of them also have hardware multipliers that are significantly faster, and use less program memory, compared to pure software implementations.
It is easy to find devices that have both ADCs and DACs, or devices with capacitive touch sensors, segmented LCD drivers, and Ethernet.
Internally, these devices also have hardware blocks typically not found in lower-end devices. These include encryption engines, Operational or Programmable Gain Amplifiers, and DMA controllers.
Although 16-bit microcontrollers can be found from various manufacturers such as Microchip (their dsPIC33 is a popular choice), NXP, Infineon, or Cypress, the TI MSP430 series will be presented here as a typical example of this microcontroller segment.
TI MSP430 Series
The MSP430 is a series of very low-power 16-bit microcontrollers that are available in many flavors. They range from general-purpose to very specialized models.
One interesting thing about the specialized variants of these microcontrollers is that it actually branches out into two extremes: very dedicated, very low-cost models, and high-end models with analog sensor interfaces and Digital Signal Processing (DSP).
An example of a high-end application is this ultrasonic flow sensor. At the low end, TI also makes MSP430-based chips that solve many very specific hardware functions. For more details, see this e-paper.
For example, want an SPI to UART interface, an I/O expander, or a UART-to-UART bridge? It’s all in there, and all for less than $0.30 for this chip.
Finally, of course, the MSP430 is supported by a number of low-cost tools and development kits.
Table 1 below shows the additional features available on some of the mainstream versions.
|Program Memory||Up to 32KB||Up to 16KB||Up to 256KB||Up to 128KB|
|Number of pins||16 to 64 in a variety of packages||48 to 64 in a variety of packages||24 to 100 in a variety of packages||56 to 100 in a variety of packages|
|Peripherals not typically available in 8-bit controllers||DAC’s, PGA’s, Transimpedance & operational amps||IR modulation logic||DMA, AES||DMA, AES|
|LCD segment drivers||--||Up 256||--||Up to 320|
32-bit microcontrollers are powerful devices with microprocessor-like features. Some of the advanced features include instruction pipelining, branch prediction, Nested Vectored Interrupts (NVI), Floating Point Units (FPU), memory protection, and on-board debuggers.
Instruction pipelining means that the processor core pre-fetches subsequent instructions ahead of time, and branch prediction pre-fetches the next instructions of both outcomes of an if-else condition, thus speeding up code execution.
NVI provides for interrupt priorities, where one interrupt can preempt a lower priority one.
FPUs can do floating-point calculations much faster than SW-implemented methods.
Memory protection ensures that application code cannot inadvertently over-write critical sections dedicated to the operating system, for example.
Finally, on-board debugging allows peeking into registers and other areas of the system to facilitate application code debugging. All of these together allow these microcontrollers to run large, fast, and robust applications.
In addition, their raw processing power means they can easily support Real-Time Operating Systems (RTOS) that, in turn, provide multitasking capabilities.
Even though there are many 32-bit microcontrollers on the market, the focus in this note will be on the ARM Cortex M-based devices, with a special mention of the ESP32 from Espressif.
ARM Holdings actually only designs processor core IPs, which they then license to various semiconductor vendors that incorporate them, along with some peripherals, into their own silicon chips. Numerous chip makers offer microcontrollers based on the Cortex-M architecture.
Two prominent vendors of ARM-based chips are Atmel with their SAM device line, and STMicroelectronics with their STM32 line of products.
The SAM devices deserve mention here due to their use in some Arduino-compatible boards. However, in general, the STM32 devices offer more choices, and should be given top consideration when designing in an embedded 32-bit microcontroller.
STM32 family of ARM Cortex M-based microcontrollers, and their intended application segments
ARM Cortex M cores come in many versions. The most popular ones are the M0/M0+, M1, M3, M4 and M7, each offering progressively higher performance. STM32 microcontrollers incorporate M0/M0+, M3, M4 or M7 cores.
Within each of the categories shown in the STM32 ARM Cortex M chart, there are many families that can be selected to more closely match a given application.
For example, the STM32 mainstream family of microcontrollers figure (above) shows the main variants available in the “mainstream” category, and their relative performance curve. Note that within each family itself, there are many variants with different combinations of peripherals and amounts of memory.
In fact, at this time, there are over three hundred STM32 microcontrollers available in this category.
STM32 hardware support: The STM32 family is supported by a wide variety of hardware tools provided both by ST Microelectronics, and third parties.
An inexpensive in-circuit debugger/programmer is the STLink V2. It is made by ST, and is available from places such as Digi-Key; however, very inexpensive clones are also available.
Both contain an STLink debugging interface. All that is needed is a computer with USB, running the appropriate software tool to evaluate the chosen microcontroller.
Discovery boards include additional external peripherals such as MEMs sensors, and capacitive touch plates. However, Nucleos have headers that are compatible with Arduino shields.
ST Discovery development board for an STM32F407 microcontroller
Before leaving this section, it is worth mentioning yet another very inexpensive development board. Commonly known as Blue Pill, this board sports an STM32F103 Cortex M3-based chip, and costs less than $2.00 from some sources.
An appealing feature of this board is that it can be made compatible with Arduino so that the Arduino IDE, or Platform IO, can be used to write and download code for quick proof of concept designs.
While the process of making it Arduino compatible is a bit involved, there are several places that sell Arduino-ready boards. Just do a search for ‘STM32duino’.
STM32 software support: STMicroelectronics provides a version of ARM’s Mbed development suite for all its STM32 product line. This includes an IDE, compiler and an extensive set of libraries.
For developers that prefer to use other compilers, ST provides its STMCube. This is code generator software that produces initialization codes for the STM32 peripherals.
With that, there is no need to fully go through the bit settings of multiple registers to set up the peripherals such as IO ports or timers, for example.
The ESP32 is a microcontroller from Espressif Systems. As shown in figure 3, it has all the features on a typical 32-bit microcontroller.
Espressif ESP32 module
However, what distinguishes this particular microcontroller from others is the inclusion of Wi-Fi and Bluetooth hardware on the chip.
That includes not just the protocol stacks, but the actual radio transceivers as well. The ESP32 is also available as a small pre-certified module with an integrated antenna.
For applications that require Wi-Fi or Bluetooth connectivity, the ESP32 deserves serious consideration. The price of the ESP32 (both discrete chip and module) are very affordably priced, especially considering the number of features and performance packed into this chip.
ESP32 functional block diagram
How to Select the Microcontroller for Your New Product - Final Thoughts
The microcontroller is arguably the most important component you must select for your product. Changing to a new microcontroller mid-project can be a nightmare, so be sure you get this choice right upfront.
Other components in a design can commonly be changed without requiring massive, system-wide changes. That is not the case with the microcontroller which serves as the core of your product.
When picking a microcontroller, you want to generally pick one that gives your product some room to grow. For example, if you determine that you require 16 GPIO pins then you don’t want to pick a microcontroller with only 16 GPIO pins.
What happens if you decide to add a new button in the future so you need another GPIO pin? If your microcontroller doesn’t give you room to grow, then you may find that seemly simple design upgrades in the future will require a massive redesign because a new microcontroller is necessary.
On the other hand, you don’t want to select more performance or features than you ever anticipate needing.
For instance, if your product simply monitors temperature and humidity then you won’t ever need an advanced 32-bit microcontroller running at hundreds of MHz. That would be overkill which will add unnecessary costs and design complexities to your product.
Instead, you need to find the sweet spot between having room to grow if needed, but yet not paying for performance or features you will never really need.