Embedded MCUs are purpose-built for use in various specific applications and rely on embedded peripherals, various communications protocols, conventional operating systems (OS) or specialized real-time operating systems (RTOS), middleware, application software, and development environments. While MCU stands for microcontroller unit, it could also be interpreted as mission controller unit since these devices are optimized for specific applications or missions. No designer would think of using an 8-bit central processing unit (CPU) in a desktop computer. However, billions of 8-bit MCUs are still used in highly important and specialized control functions every year.
One thing that makes MCUs special is that they are at the same time ubiquitous and mostly invisible. MCUs are found in applications that require repetitive operations such as microwave ovens and traffic lights and in a wide variety of well-defined control applications involving sensors and other inputs. It’s estimated that the average U.S. house has over five dozen MCUs in various devices, and an automobile with advanced driver assistance systems (ADAS) can have over twice that number.
An MCU contains one or more CPUs (processor cores) along with memory, input/output (I/O) peripherals, real-time clocks (RTC), timers, and other functions (Figure 1). For example, the analog/digital converters (ADCs) convert analog inputs (such as from sensors) into digital values that the CPU can use. In contrast, the digital/analog converters (DACs) perform the reverse function and take the processor’s digital outputs and convert them to analog values to support various system functions. A real-time clock (RTC) and one or more universal asynchronous receiver/transmitters (UARTs) convert parallel signals into serial ones and serial ones into parallel ones. Additional peripherals such as I2C interfaces, pulse-width modulators (PWMs), and so on are included to support specific application needs.
MCUs are used because they are cost-effective and compact. Integrating the processor, memory, and various peripherals on a single chip and testing them as a unit may increase the cost of a chip, but it produces a reduced solution size, generally decreases the overall cost of the system, and improves both quality and reliability compared with a collection of individual functional elements.
Interrupts make the difference
Interrupts are critical elements that make MCUs special compared with the CPUs found in desktop computers, servers, and similar computing platforms. MCUs are typically used to provide real-time (not necessarily high speed, but predictable) responses to events in an embedded system. Certain events will have priority, and when they occur, an interrupt is sent that tells the processor to suspend its current activity and perform the processing required by the interrupt source before restarting on the original processing tasks. Sources of interrupts are application and device-dependent and can include an input signal from a button being pushed (Figure 2). This sensor input changes states, an internal timer alert, etc. For example, in a battery-powered wireless Internet of Things (IoT) node, an interrupt is used to wake up the processor to handle sensor readings, receive an incoming transmission, or perform another task.
In some applications, a GPIO input may change on a somewhat regular basis due to an external stimulus. Instead of using an interrupt, the system can periodically check the GPIO value. Periodic checking is called polling. While polling appears to be a simple technique, it can be challenging to implement. There can be too long a lag between the changed state in the GPIO value and its detection or the system may miss the change altogether. While a shorter polling interval will produce more reliable and faster detection, it consumes processing resources since most checks will result in negative results.
Interrupts can be much more efficient and can occur due to devices internal to or external to the MCU. An interrupt from an external sensor, switch, or other device is called an “attached interrupt” since it is generated by a device attached to an interrupt request (IRQ) pin on the MCU. Interrupts from internal peripherals such as UARTs, timers, and so on are called “peripheral interrupts.” Interrupts can serve a variety of purposes, including:
Performance of routine tasks: some applications need the MCU to do routine tasks at predetermined intervals, such as monitoring physiological signals in medical devices, blinking a status LED at a predetermined rate, etc. In these cases, a timer peripheral in the MCU can provide an interrupt to perform the task at the required interval.
Task completion alerts: Completing an intermediate task such as an A/D conversion may be important to the performance of some control function by an MCU. Sending a tack completion interrupt enables the MCU to continue its routine activities until the intermediate task has been completed. Then the interrupt would immediately send the MCU into the related interrupt routine before returning to its normal activities.
Safety-related or emergency actions: In cases where a system fault occurs or a dangerous condition is identified by an external sensor; an interrupt can force the MCU to take appropriate actions to protect the system and any people in the vicinity.
In many applications, there are multiple possible sources of interrupts. The interrupt controller on the MCU intercepts all incoming interrupts and forwards them to the CPU in the correct order based on their relative importance. In some applications, interrupts can be disabled while certain tasks are being implemented, and the interrupt controller will ignore interrupts accordingly and not forward them to the CPU.
MCU architectures can generally be described by the relative complexity of the instruction set, such as reduced instruction set computing versus complex instruction set computing, and the execution hardware design; Harvard versus Princeton.
Reduced instruction set computing (RISC) architectures have simplified instructions executed in a single clock cycle. RISC architectures are commonly found in MCUs and can only handle simple instructions. RISC-V is an emerging variation on RISC that is rapidly gaining adoption. RISC-V is an open standard instruction set architecture (ISA) based on RISC design principles. Unlike most other ISA designs, the RISC-V ISA is provided under open-source licenses that do not require fees to use. A growing number of RISC-V MCUs are available.
Complex instruction set computing (CISC) employs instructions that can take multiple clock cycles to complete on a RISC machine. CISC instructions operate directly on the computer’s memory banks and do not require the programmer to call any loading or storing functions explicitly. In CISC, the emphasis is on hardware, with small code sizes and high clock frequencies. RISC emphasizes the software and the RISC instructions need fewer transistors of hardware space than CISC instructions, leaving more room for general-purpose registers. Because all instructions execute in a single clock cycle, pipelining is possible with RISC cores.
Harvard vs. Princeton
Another way to classify MCUs is by their internal bus structure. In a Harvard architecture, separate buses access the instructions and data. A common bus is used for both in a Princeton (also called von Neumann) architecture (Figure 3). Each architecture has advantages and disadvantages, and both are used in MCUs. The Princeton architecture is used over Harvard much of the time since it’s less costly to implement, but the Harvard has the advantage of being faster.
Since the Harvard architecture has separate buses for instructions and data, the CPU can access instructions and read/write data simultaneously. In addition, the word widths of the instruction and data memories are independent. The costs for these performance advantages are that more electrical connections are needed, and two memories are required.
The lower-cost Princeton architecture has its advantages: The memory controller gets data and instructions in the same manner (potentially from one memory), making the controller simpler, lower in cost, and faster; Data from I/O devices and memory are also retrieved in the same way, further simplifying the implementation, and; Fewer electrical connections contribute to lower cost. The Princeton architecture is inherently sequential, limiting overall performance. Since the CPU is typically much faster than the data bus, the CPU can be idle waiting for data (this is called the von Neumann bottleneck).
MCUs are generally inferior to the CPUs found in computers and servers in terms of raw computing power. But while they are lacking in raw power, MCUs are optimized for embedded systems where a wide mix of analog sensors, valves, motors, and various human-machine interface (HMI) technologies can be found. A typical MCU can have several dozen GPIOs and will be able to respond to interrupts as needed to implement real-time control functions. MCUs can include various peripherals, including ADCs, DACs, PWM controllers, timers, and even integrated wireless communications capabilities. And a typical MCU costs much less than a CPU found in a computing platform.
Embedded Control Solutions, Microchip
Essentials of Microcontroller Use Learning about Peripherals: GPIO, Renesas
What it Takes to do Efficient and Cost-Effective Real-Time Control with a Single Microcontroller, Texas Instruments