This article introduces what microcontrollers are and looks at some popular options.
Creating simple projects using discrete parts can be both educational and useful. However, not every circuit can do all tasks, so you may find yourself needing a microcontroller. In this article, we will learn what microcontrollers are and the main types available.
The Need for Automation
Building circuits using resistors, capacitors, transistors, and op-amps can only go so far because these are usually analog circuits. Even digital circuits built using discrete logic chips can very quickly become too large and complex! In the past, the next step after discrete logic chips was building a custom computer with a CPU, memory, and IO devices. However, such a feat is not something that should be attempted lightly as they are usually large in size and prone to errors! Thankfully, multiple manufacturers such as Microchip, Intel, and Atmel invented a device called a microprocessor. But what is a microprocessor and how are they useful in projects?
Enter the Microprocessor
A microprocessor is a single chip that contains a CPU, memory (both RAM and ROM), and IO hardware. Such chips usually contain many input and output pins that allow you to connect them to many different types of circuits, including both analog and digital. Unlike desktop computers, most microprocessors are not very powerful and have limited memory, but are incredibly tiny and easy to implement in projects.
The table below shows typical characteristics of computers against common microcontrollers (such as the PIC range).
Types of Microcontrollers
There are so many microcontrollers available on the market it is almost impossible to cover all the different types. Therefore, it is best to look at those most commonly used by hobbyists and makers alike.
PIC - Microchip
The PIC microcontroller is probably one of the most defacto chips to use and has both personal and commercial capabilities. These devices use between 5 and 6 pins to be programmed using one of the many programmers offered by microchip. The easiest one to use is the PICKIT3, which is a programmer that allows you to both program and debug your microcontroller using a PC. The PICKIT3 can provide power to your project (albeit a small amount), which can be very useful at times.
The PIC microcontrollers come in all shapes and sizes, ranging from the hobby-friendly DIP package all the way down to BGA, which makes them useful in the commercial environment. The cheapest PICs can be bought for $0.20 yet still provide many useful features. Some of the peripherals that you can expect on even the cheapest devices include...
- I2C and SPI
- Pin interrupts
The PIC come in different ranges: PIC16, PIC18, PIC24, and PIC32. The PIC16 and PIC18 are both 8-bit microcontrollers, which means that all the data internally (registers and RAM) are 8 bits wide. The PIC24 devices are 16-bit devices, while the PIC32 devices are 32-bit devices. Going up the range usually means more capabilities, speed, and memory, but not necessarily an increase in price. If you are looking to do hobby work or simple projects, stick to the PIC16/PIC18 range, since they are relativity easy to program both in assembler and C. Programming the PIC24 and PIC32 range can be more difficult for two reasons. First, they use a different CPU (MIPS), which means they have an entirely different set of instructions to the other PIC devices, and second, they contain more advanced hardware, which can be troubling if you’re new to microcontrollers.
AVR – Atmel (now Microchip)
The AVR series of microcontrollers are interesting because, on the surface, they are very similar to the Microchip PIC range. Both controllers have fantastic online support, can be used with languages like C, are cheap, and have plenty of peripherals. However, there is one feature that differentiates the two, which is something that is not often given enough attention: the CPU.
PIC CPUs are RISC-based, which means they have only have a few instructions (the PIC16 range have around 30-40 instructions). This can be beneficial for basic tasks, as it reduces the complexity of code. The AVR advertises itself as a RISC-based CPU, but devices such as the ATMEGA328 have over 100 instructions. While some may see this as difficult to learn, it actually gives the programmer a lot of power and the ability to do more complex tasks in a shorter time. The AVR CPUs also do most of their instructions in one clock cycle instead of four for the PIC, which means the AVR is four times faster than a PIC when clocked at the same speed. The AVR CPU also does not have bank switching for registers, which can be difficult to sort out in PIC devices. One factor that AVRs will fall short on is that many of their instructions work on the general purpose registers, which they only have 32 of. This means that there may be a need to constantly load data from SRAM if large amounts of data are being processed. The PIC, however, has full access to its SRAM when performing actions, but its SRAM is usually split up into 256-byte blocks, which is where bank switching comes in.
Common AVR devices include:
- tinyAVR (very small devices with limited peripherals, but cheap and compact)
- megaAVR (4–256KB program memory, extended instructions)
- XMEGA (large program memories, DMA, large pin packages)
The ST Microcontroller range provides many features seen in both AVR and PIC devices, including peripherals, speed, and memory. PIC and AVR are the two most common devices in the hobby electronics field, but this does not mean that ST devices are not suitable. Just like the PIC range, there are two distinct families for ST devices: STM8 and STM32. The STM8 devices are 8-bit microcontrollers with many features including up to 80 CPU instructions, 16-bit registers, indirect addressing, stack, and 16-bit division. However, some STM8 devices have pipelined instructions, which allows for a higher throughput (assuming no conditional branches). The STM32 devices are arguably more modern that PIC and AVR devices because they use ARM cortex cores, which opens them up to many different software libraries and compilers.
STM8 and STM32 devices are easily programmed with an ST-Link V2 programmer, which can be as low as $4. One major disadvantage of STM devices is the package they come in; they are rarely seen in hobby-friendly DIP packages. This makes them difficult to integrate into projects without the use of adaptors and jumpers. However, because of their price and surface-mount packages, they are incredibly useful in a commercial environment, which is why they are commonly found in retail products. This advantage is not only just seen in STM8 devices, STM32 devices can be available for $5 which contain a 120MHz ARM core, 512KB ROM, 128KB RAM, 144 pins, CAN, I2C, SPI, UART, and USB. While $5 may sound like a lot for a single project, consider that at this price you essentially have a little ARM computer with incredible amounts of processing power!
The last microcontroller that we will look at is the Arduino range. The Arduino has seen a massive wave of popularity in the hobby community due to its low cost, user-friendly nature, and peripheral capabilities. As it turns out, the Arduino is based off Atmega devices with one of the more common boards using the ATMEGA328. So if the Arduino uses an Atmel device, why not just use an Atmel chip on its own? There are several reasons you would use one over a single chip!
Arduino boards have USB to UART bridges (easy PC communication)
Contains a bootloader so it can be programmed via the USB port
Has fantastic software support and there are many examples online
Requires no external hardware to function (only a power supply)
Can be easily used in a project (screw mounts)
Has a shield system which allows for expansion with other boards (such as Ethernet)
The Arduino is more expensive than the chips on their own, but for what they provide they are very good for those who are new to electronics and may struggle to use an IC on a breadboard. The Arduino is often programmed in C++ using the Arduino IDE, which gives the user less control unless the user decides to program registers themselves and make adjustments that can potentially disrupt Arduino libraries. They are brilliant devices for fast prototyping, but they usually suffer in a commercial environment.
The market is flooded with so many different devices it can be a pain to keep track of them all. Some are nice to program in assembler while others are easy to use in a circuit. But the question remains, which device should you pick? This is entirely up to you, but here are a few suggestions, depending on your situation:
- For a commercial environment, avoid the Arduino. ST devices may be better suited, but the PIC and AVR are still good microcontrollers to use.
- If speed is critical, look at the AVR/ST devices. While high clock speeds are available for the PIC, they usually struggle to go beyond 16MIPS unless you go beyond the PIC18 range.
- If simplicity is needed, then use the Arduino. If the project is to be sold commercially and simplicity is needed, the PIC could be useful.
- For time-critical tasks that require complex operations, the AVR devices can be extra useful with their complex instruction set (despite what they say).
- For high-end work, consider the STM32 devices due to their ARM core and large memory spaces.