Previously in this series, we’ve covered how to select components: how to select capacitors, resistors, and inductors and connectors. When choosing a microcontroller, the decision process becomes a bit more complicated. There are thousands of microcontrollers on offer and it’s a daunting task trying to choose the right one. Often enough, there are plenty of options that are right for the job. There’s also plenty that aren’t right. The trick is finding the best microcontroller that can provide for all the needs of the project and anything else that gets added later.
In this blog, we explain the most important aspects of microcontrollers, including architecture, memory size and interfaces. We will also look at some of the most popular microcontrollers on the market and evaluation boards to get you up and going.
Starting off, let’s look at the difference between a microprocessor and a microcontroller. These are often confused with each other. Microprocessors generally consist of just the Central Processing Unit (CPU), which performs all the instructions in a computer program, including arithmetic, logic, control and input/output operations. Microcontrollers contain one or more CPUs with RAM, ROM and programmable input/output peripherals. Microprocessors tend to operate at much greater clock speeds on general application tasks, like gaming, photo editing and software development, whereas microcontrollers are designed for more specific tasks in smaller embedded systems like keyboards, mice, electronic toys and vending machines.
In short, it’s easier to turn on and off an LED with a microcontroller as it has direct access to the output pin, whereas microprocessors have to communicate with the external peripherals (ICs) to control the LED.
As an example, the Raspberry Pi uses the BCM2835/BCM2836 Broadcom microprocessors and the Arduino uses the ATMEGA328p/ATMEGA2560 microcontrollers.
There are a few key questions to ask before starting:
1) What is the application?
2) 8bit, 16bit or 32bit?
3) What processor? 8051, ARM, PIC, or AVR?
4) What’s the operating voltage?
5) What package size is needed?
6) What communication interfaces are needed and how many?
7) How much memory is needed? (including program memory and data memory)
These open-ended questions need further investigation into what the application does. With so many options available, it’s important to start ruling out as many as possible at the start, focusing on key specifications.
If the design needs to perform numerous calculations, more memory may be needed. Performing an FFT on an audio signal will require more RAM, greater sampling rates and high-resolution ADCs, as well as other features. Taking a temperature reading and sending commands over UART are relatively light weight and much smaller microcontrollers can be used with less memory. The application dictates which type of microcontroller and the features. Some common applications include wearables, automotive, industrial, smart home/energy and the internet of things.
This also has an effect on the size of internal ROM and RAM memory. In the 8-bit processor again, the memory size is dictated by 8 bits, which gives 255 unique memory locations. Whereas a 16-bit microcontroller can handle up to 65,535 memory locations and a 32-bit microcontroller can handle up to 4,294,967,295 memory locations. In saying this, manufacturers have developed ways to allow smaller bit size microcontrollers to access more memory through banks of addresses and paging. This complicates the software slightly. Usually 8-bit microcontrollers tend to be lower cost, lower power and faster control, but technological advancements mean 16-bit and 32-bit microcontrollers can now compete with each other.
While the bit size is very clear when writing in assembly language, when writing in C or C++, it is not often obvious in the code, making it an important thing to remember. When using C or C++, the various data types have different sizes from one microcontroller to another. Trying to use a 16-bit unsigned integer in an 8-bit microcontroller will end up losing the most significant byte. However, using an 8-bit integer in a 16-bit or 32-bit microcontroller won’t cause any problems. The most important thing when considering the bit size is the amount of data to be processed. An 8-bit microcontroller will be sufficient when communicating with low speed buses, taking sensor measurements or even controlling a buzzer. However, it will have a lot of trouble trying to control an LCD touch screen or Ethernet interface. This is where a 32-bit microcontroller will excel.
The major differences focus around how they operate at the lower level. While 8051, AVR and PIC all have offerings in 8-bit, 16-bit and 32-bit, the ARMs generally come in 32-bit and even 64-bit. The 8051, AVR and PIC work closer with the I/O peripherals and can be lower power and faster as a result. In saying this, continuous development provides a very competitive market where it’s difficult to confirm advantages of one over the other.
The most common set is the Cortex-M “Microcontroller” profile. This group consists of the Cortex-M0, Cortex-M0+, Cortex-M1, Cortex-M3, Cortex-M4(F), Cortex-M23 and the Cortex-M33(F). The ‘F’ denotes an optional floating point unit (FPU) inside the core. Typically, microcontrollers can’t use floating points. The Cortex-M0 represents the optimised core with small silicon die size, at the lowest price. The Cortex-M0+ is an optimized version of the M0, which includes some features from the M3 and M4 cores. The Cortex-M1 is specially designed to be loaded as a softcore into Altera, Xilinx and Microsemi FPGA offerings. The Cortex-M3 is used for highly deterministic, low cost, real time applications. The Cortex-M4 is a Cortex M3 with additional DSP instructions and an optional FPU. The Cortex-M7 is a high -performance core with greater power efficiency over the M4. The Cortex-M23 is similar to the M0+ with additional Trustzone security features. The Cortex-M33 is similar to the Cortex-M4 with the additional Trustzone security features as well.
AVR32 is the 32-bit offering, which was intended to compete with ARM processors. These are not compatible with the original ARM and include additional SIMD and DSP instructions as well as audio and video processing features.
One of the nice features of most AVR models is that they can reserve a bootloader region to store re-programming code. The code can then re-program through any interface available.
The PIC32 series of microcontrollers uses the MIPS32-M4K core technology, which is a 32-bit RISC architecture. MIPS is a direct competitor to the ARM processors covering all types of applications in home entertainment, embedded and networking products, mobile, wearable and IoT devices.
The 8051 processors are widely used by Nordic Semiconductors wireless system-on-chip solutions.
Check out the Sensors section in the Common Parts Library, which shows a few examples of devices, which the microcontroller may need to communicate with.
It’s important to note the difference between program and data memory. Program memory is where the compiled code will be stored and run from and the data memory is used during run time. If a lot of processing is needed, then more data memory will be needed. If the project needs to use look up tables or store a lot of pre-defined values, then larger program memory will be needed.
Both the MSP430 and PIC16F1619 focus on low cost. The 16-bit MSP430 is a better choice for lower power, battery operated devices with numerous configurable interfaces, like an indoor/outdoor motion sensor.
The PIC16F1619 is an 8-bit microcontroller, similar in function to the MSP430. It doesn’t have as low power, but will focus on safety critical applications in home appliances and white goods. These types of appliances need to be able to safely handle all types of scenarios and reset in a clean manner if something goes wrong. For example, when the door of a dishwasher is opened, the wash cycle will stop. Then it will resume again when the door is closed.
The STM32F401 is a 32bit ARM Cortex M4 with an FPU processor as well. The 32-bit core and FPU make this microcontroller ideal for medical equipment, video and audio equipment, scanners and anything that needs to perform a lot of floating point calculations as fast as possible. It also has a direct USB interface to the microcontroller, adding a useful external interface. The PIC16F1619 and the MSP430 could not handle these applications as they cannot handle the amount of data being processed at the same time. On the other hand, the ARM Cortex M4 could easily perform most of the tasks of the MSP430 and the PIC16F1619, sacrificing both power and cost.
Cypress Semiconductors CY7C68013A takes a slightly different market angle. Using an 8051 microprocessor, the CY7C68013A has an integrated USB 2.0 interface, allowing data transfer rates of over 53Mbytes per second (maximum allowable USB bandwidth). The STM32 has a USB interface, but it’s only a low speed interface to allow basic communications. The CY7C68013A is ideal for custom USB interfaces, like an encrypted USB Key, with large data storage. Maximum bandwidth would be necessary for this type of application.
1) Are they in stock and easily available? More often than not, the perfect microcontroller isn’t easily available or can only be bought in bulk volumes.
2) What toolchain are they using? Are there online examples to leverage from?
3) Is it new? While there’s nothing better than using the latest and greatest, it also means finding all the early problems that get added to the first application note. Anything older than 3-4 months should have had plenty of testing by various different consumers in different applications.
4) Check the pinout. There’s nothing more annoying than having searched for a microcontroller with 2 UARTs and a I2C bus to find out that they’re sharing the same pins.
5) Not sure how much memory is necessary? Choose a microcontroller with more memory than is needed. Future design iterations can choose a smaller microcontroller within the same family with less memory to save cost.
6) How many general purpose input/output (GPIO) pins are needed? Always get more than is needed. Extra debug points can be catered for with extra GPIOs. It’s always easy to get a smaller microcontroller in the same family to try and cut costs. It’s much harder to go larger.
7) Purchase and use evaluation boards and development kits if using a microcontroller different to what you’re used to. The evaluation boards tend to be a little more expensive, but time and money is saved in the long run.
8) If creating a number of similar projects, consider using the same microcontroller (or a similar enough one) to save hardware and software design time.
1) STMicroelectronics STM32Nucleo-F401RE
2) Microchips Curiosity Development Board (DM164136)
3) Renesas R5F562TAADFP Microcontroller Starter Kit
4) NXP Semiconductors FRDM-KL26Z Low-cost Freedom development board for Kinetis KL16 and KL26
5) Microchip (originally Atmel) ATMEGA328P-XMINI Xplained Mini Evaluation kit for ATmega328P
6) Cypress Semiconductor CY8CKIT-030A PSoC 3 Application Processor and SOC Development Kit
[gallery size="full" ids="4655,4657,4658,4659,4660,4661"]
If you have any comments or suggestions, drop us a note in our Slack room or in comments below. Be sure to check out the other blogs in this series: how to select a capacitor, resistor, inductor and connector.