Microprocessors and Microcontrollers
A microprocessor (MPU) is a general-purpose central processing unit (CPU) fabricated on a single IC. It contains the arithmetic logic unit (ALU), control unit, and registers, but no memory or peripherals on-chip. It is designed to fetch instructions and data from external memory and communicate with external devices over a system bus. It is optimized for computational throughput and runs under an operating system.
A microcontroller (MCU) is a complete computer system on a single chip. It integrates a CPU core with on-chip memory (program memory—typically flash—and data memory—typically SRAM), peripherals (timers, counters, serial interfaces, ADCs, GPIO ports), and often a clock generator and power management. It is optimized for dedicated control tasks, typically running a single application with no operating system (or a small real-time operating system, RTOS).
The one-line summary: a microprocessor is a component of a computer; a microcontroller is a complete computer on a chip, designed to control things rather than to run general-purpose software.
A microprocessor is like a high-performance engine that needs a chassis, fuel tank, and transmission (memory and peripherals) bolted on before it can do anything useful. A microcontroller is like a complete, self-contained vehicle sized for a specific job. The analogy holds for the integration story, but note that the dividing line has blurred: modern high-end MCUs contain 32-bit cores with caches, and modern SoCs (system-on-chip) integrate CPU cores with memory controllers and peripherals on a single die, occupying territory between the two categories.
Microprocessor Architecture
Core Functional Blocks
A microprocessor is organized around three functional units:
- Arithmetic Logic Unit (ALU): Performs arithmetic operations (add, subtract, increment, decrement, multiply, divide) and logical operations (AND, OR, XOR, NOT, shifts, rotates). It also sets condition flags (zero, carry, sign/negative, overflow) that feed conditional branching.
- Control Unit (CU): Decodes instructions and generates the control signals that coordinate the ALU, registers, and bus interface. It sequences the fetch–decode–execute cycle. In modern processors, the control unit is often implemented as microcode and/or hardwired logic, and may include instruction pipelining and branch prediction.
- Register File: A small, fast array of registers used for temporary data storage and addressing. Key architectural registers include:
- Program Counter (PC) (also called Instruction Pointer, IP): holds the address of the next instruction to fetch.
- Instruction Register (IR): holds the currently decoded instruction.
- Accumulator (ACC): a primary operand register in accumulator-based architectures.
- Stack Pointer (SP): points to the top of the call/return stack.
- Status/Flags Register: holds condition flags and control bits.
- General-purpose registers: used for operands and addresses.
The System Bus
The microprocessor communicates with external memory and I/O over three buses:
- Address bus: unidirectional, driven by the MPU, carries the address of the memory location or I/O port being accessed. Its width determines the addressable memory space (\(2^n\) locations for an \(n\)-bit address bus).
- Data bus: bidirectional, carries instructions and data. Its width determines the word size and directly affects throughput.
- Control bus: carries control and status signals—read/write strobes, clock, interrupt requests, bus grant/request, reset, and ready/wait signals.
The bus width and clock frequency together determine much of the MPU's performance, although architecture (pipelining, cache, superscalar execution) often matters more than raw clock speed.
The Instruction Cycle
The fundamental operation of any processor is the instruction cycle, typically decomposed as:
- Fetch: The PC is placed on the address bus; memory returns the instruction word on the data bus; the instruction is latched into the IR; the PC increments.
- Decode: The control unit interprets the opcode and determines the operands and the operation to perform.
- Execute: The ALU or other functional unit performs the operation; results are written back to registers or memory; flags are updated.
- Memory access / Write-back: For load/store instructions, data memory is accessed; results are committed.
In a modern pipelined processor, these stages overlap across multiple instructions, so the effective throughput is roughly one instruction per clock (or more, with superscalar execution), even though each individual instruction takes multiple cycles to complete. Pipelining hazards—data hazards, control hazards, and structural hazards—are the central challenge of processor design and are mitigated by forwarding/bypassing, branch prediction, and out-of-order execution.
Memory Organization
- Von Neumann architecture: A single memory space holds both program instructions and data, accessed over a shared bus. This simplifies the design and permits flexible memory allocation, but creates the von Neumann bottleneck: instruction fetches compete with data accesses for bus bandwidth.
- Harvard architecture: Separate memory spaces (and often separate buses) for program and data. This allows simultaneous instruction fetch and data access, improving throughput, and is common in digital signal processors (DSPs) and many microcontrollers. The cost is greater hardware complexity and less flexibility in partitioning memory.
Modified Harvard architectures—used in many modern MCUs and processors—have separate instruction and data caches/buses at the core level but a unified main memory, combining the throughput benefit with the flexibility of a single address space.
Microcontroller Architecture
The Integrated System
An MCU integrates, on a single die:
- CPU core (often a RISC core; see §4)
- Program memory: typically flash (allows in-system reprogramming), sometimes OTP or ROM in cost-sensitive parts
- Data memory: typically SRAM
- Non-volatile data storage: EEPROM or flash emulation for configuration and calibration data
- Timers/counters: for delays, event counting, PWM generation, and input capture
- Serial communication peripherals: UART/USART, SPI, I\(^2\)C, CAN, USB, and increasingly Ethernet and wireless radios
- Analog peripherals: ADC (successive-approximation, delta-sigma, or pipeline), DAC, comparators, and operational amplifiers in some families
- GPIO ports: general-purpose digital I/O with configurable pull-ups, drive strength, and alternate functions
- Clock generation: internal RC oscillator, PLL, and provisions for external crystal/ceramic resonator
- Interrupt controller: prioritizes and vectors peripheral and external interrupts
- Watchdog timer: resets the MCU if software fails to service it, a critical reliability feature
- Power management: sleep/stop/standby modes that gate clocks and power to unused blocks
- Debug interface: in-circuit debugger/programmer (e.g., JTAG, SWD, ICSP, or proprietary interfaces)
The Memory Map
In most MCUs (especially ARM Cortex-M and many 8-bit families), peripherals are memory-mapped: each peripheral's control, status, and data registers occupy specific addresses in the same address space as memory. Software accesses them with ordinary load/store instructions, and the peripheral's registers behave like memory locations. This is a crucial concept for embedded programming: configuring a timer or reading an ADC is done by writing and reading specific memory addresses (usually via named register definitions in a vendor header file).
Some architectures use separate I/O address spaces (e.g., x86 port I/O, or AVR's IN/OUT instructions), but memory-mapped I/O is the dominant approach in MCUs.
Reset and Startup Sequence
On power-up or reset, the MCU:
- Holds the CPU in reset until the clock stabilizes and supply is valid.
- Loads the reset vector—the initial PC value—from a fixed address (often the first word of flash).
- Executes startup code that initializes the stack pointer, zeroes or initializes data memory, copies initialized data from flash to RAM, and configures the clock system.
- Jumps to the
main()function.
This sequence is why the vector table—the table of interrupt and reset vectors—is a central feature of MCU architecture: it defines where execution begins and where each interrupt handler is located.
Interrupts
MCUs are fundamentally event-driven systems. An interrupt is a hardware signal that causes the CPU to suspend the current program, save context (at minimum the PC and status register), jump to a designated interrupt service routine (ISR) , execute it, and return to the interrupted program. Key concepts:
- Interrupt latency: the time from the interrupt request to the first instruction of the ISR. Critical for real-time control.
- Interrupt priority and nesting: higher-priority interrupts can preempt lower-priority ISRs.
- Vector table: maps each interrupt source to its handler address.
- Masking: individual interrupts can be enabled/disabled; a global interrupt enable bit exists on most cores.
Interrupts are what make an MCU suitable for real-time control: the processor can respond to an external event (a button press, a timer overflow, a serial byte arriving) within microseconds without polling.
RISC vs. CISC Architectures
The instruction set architecture (ISA) of a processor is broadly classified as RISC (Reduced Instruction Set Computer) or CISC (Complex Instruction Set Computer).
| Aspect | RISC | CISC |
|---|---|---|
| Instruction count | Few, simple, fixed-length instructions | Many, complex, variable-length instructions |
| Instruction format | Regular, fixed-length (ease of decode) | Irregular, variable-length |
| Addressing modes | Few | Many |
| Operand model | Load/store: ALU operates only on registers; memory accessed only by explicit load/store | ALU can operate directly on memory operands |
| Cycles per instruction | Typically 1 (in a pipelined design) | Often multiple |
| Register count | Large register file | Fewer registers |
| Control unit | Hardwired | Often microcoded |
| Pipelining | Naturally suited | Harder to pipeline |
| Code density | Lower (more instructions per task) | Higher (fewer, denser instructions) |
| Typical examples | ARM, RISC-V, MIPS, AVR, PIC | x86, 8051 (somewhat), 68k |
Important nuance: the RISC/CISC boundary has blurred. Modern x86 processors decode CISC instructions into RISC-like micro-operations internally, and modern RISC cores have added complex instructions (e.g., SIMD, DSP extensions, and bit-manipulation instructions). The MCU world is overwhelmingly RISC today: ARM Cortex-M, RISC-V, AVR, and PIC are all RISC-based. The classic 8051 is a CISC-ish accumulator machine but remains in production because of its enormous installed base and low cost.
Comprehensive Comparison
| Parameter | Microprocessor (MPU) | Microcontroller (MCU) |
|---|---|---|
| On-chip memory | None (or only small caches) | Program flash, SRAM, EEPROM |
| On-chip peripherals | None (or minimal) | Timers, UART/SPI/I²C, ADC, GPIO, etc. |
| External bus | Wide address/data/control bus exposed | Often no external bus (or a limited one) |
| Clock speed | High (hundreds of MHz to several GHz) | Moderate (typically 1 MHz–500 MHz; often tens of MHz) |
| Power consumption | High (watts to tens of watts) | Low (milliwatts to microwatts; sleep modes to microamps) |
| Cost | Higher (plus cost of external memory/peripherals) | Low (cents to a few dollars) |
| Board complexity | High (requires memory, clock, power, and peripheral chips) | Low (often a single chip plus decoupling and a crystal) |
| Software model | General-purpose OS (Linux, Windows), large applications | Bare-metal or RTOS, single dedicated application |
| Arithmetic width | Typically 32/64-bit | Typically 8/16/32-bit |
| Primary optimization target | Computational throughput and flexibility | Integration, low cost, low power, deterministic I/O |
| Typical applications | PCs, servers, workstations, smartphones (as SoC cores) | Appliances, automotive ECUs, industrial controllers, IoT nodes, toys |
| Examples | Intel Core i7, AMD Ryzen, ARM Cortex-A series | ARM Cortex-M (STM32, nRF52), AVR (ATmega328P), PIC, MSP430, ESP32, RISC-V MCUs |
Note on SoCs: A smartphone application processor is a system-on-chip—an MPU-class core (Cortex-A) integrated with memory controllers, GPU, and peripherals on one die. It behaves like an MPU (runs a full OS, needs external DRAM and flash) but has MCU-like integration. Understanding the MPU/MCU distinction is about design intent and system role, not strictly about what is on the die.
Key Parameters
When selecting or evaluating an MPU/MCU, these parameters matter:
Core and Performance
- Architecture and width: 8/16/32/64-bit; RISC vs. CISC; specific core family (Cortex-M0+/M3/M4/M7/M33, RISC-V, etc.)
- Clock frequency and DMIPS/MHz or CoreMark/MHz (standardized performance benchmarks). CoreMark is the de facto embedded benchmark; DMIPS (Dhrystone MIPS) is older but still quoted.
- Pipeline depth, caches, and tightly-coupled memory (TCM) for deterministic performance.
- DSP and floating-point support: single-precision (FPU) or double-precision; SIMD/DSP extensions (e.g., ARM Cortex-M4/M7 DSP instructions, Helium/M-profile vector extension).
Memory
- Flash size and organization (sectors, erase granularity, endurance, read-while-write capability).
- SRAM size and partitioning (main SRAM, TCM, backup SRAM).
- EEPROM (or emulated EEPROM in flash).
- External memory interface (e.g., FMC/FSMC for SDRAM, NOR, NAND).
Peripherals
- Number and type of timers (basic, general-purpose, advanced with dead-time insertion for motor control), PWM channels, capture/compare units.
- Serial interfaces: UART/USART count, SPI, I²C, CAN/CAN-FD, USB (device/host/OTG), Ethernet MAC, SDIO, I²S.
- Analog: ADC resolution, sample rate, channel count, differential inputs, DAC channels, comparators, internal op-amps.
- GPIO: count, drive strength, 5 V tolerance, alternate-function mapping, interrupt capability.
- DMA controller: channels, peripheral-to-memory and memory-to-memory transfers—critical for moving data without CPU intervention.
Power and Thermal
- Supply voltage range (e.g., 1.8–3.6 V, or 5 V-tolerant families).
- Current consumption in run mode (per MHz), sleep, stop, and standby modes.
- Wake-up time from low-power modes.
- Operating temperature range (commercial 0–70 °C, industrial −40 to +85/105 °C, automotive AEC-Q100 grades up to 150 °C).
Reliability and Safety
- Watchdog timer (independent and windowed).
- Brown-out detection and power-on reset.
- Clock security system (clock failure detection and fallback).
- Memory protection unit (MPU) and error-correcting code (ECC) on memory.
- Functional safety certifications (ISO 26262 for automotive, IEC 61508 for industrial) for safety-critical parts.
Programming Environment
The Toolchain
Embedded development typically involves:
- Cross-compiler: compiles on a host PC for the target architecture (e.g.,
arm-none-eabi-gccfor Cortex-M,avr-gccfor AVR). - Assembler and linker: the linker script defines the memory map—where code, data, stack, and heap are placed in flash and RAM.
- Debugger/programmer: hardware probe (ST-Link, J-Link, PICkit, etc.) connected via JTAG, SWD, or a proprietary interface, allowing in-circuit debugging (breakpoints, single-stepping, register/memory inspection) and flash programming.
- IDE or editor + build system: vendor IDEs (STM32CubeIDE, MPLAB X, Atmel Studio/Studio 7) or open-source workflows (VS Code + PlatformIO, CMake + GCC).
- Vendor HAL/LL libraries and configuration tools: e.g., STM32CubeMX for pin/clock/peripheral configuration and code generation.
Programming Models
- Bare-metal (superloop): a
main()loop that polls inputs and services tasks, with ISRs for time-critical events. Simple and deterministic but can become unwieldy as complexity grows. - Interrupt-driven: the main loop handles background tasks; ISRs handle time-critical events. Requires careful attention to volatile variables, critical sections, and ISR execution time.
- Real-Time Operating System (RTOS): a small kernel (FreeRTOS, Zephyr, ThreadX) provides tasks/threads, priority-based preemptive scheduling, inter-task communication (queues, semaphores, mutexes), and timing services. Suitable when the application has multiple concurrent, timing-sensitive activities.
- Embedded Linux: for MPU-class or high-end MCU-class SoCs, a full OS provides process isolation, filesystems, networking, and a rich driver model, at the cost of boot time, memory footprint, and non-deterministic timing.
Embedded Programming
- Memory-mapped register access: reading/writing peripheral registers via pointers or vendor-provided structs and macros.
- Bit manipulation: setting, clearing, and toggling bits in control registers, often via read-modify-write sequences or atomic bit-band/bit-set/bit-clear instructions.
volatilekeyword: tells the compiler that a variable can change outside program flow (e.g., in an ISR or hardware register) and must not be optimized away or cached in a register.- Atomicity and critical sections: disabling interrupts around shared-data updates; understanding when read-modify-write on a peripheral register is unsafe.
- Debouncing, filtering, and state machines: essential for reliable handling of mechanical inputs and communication protocols.
Applications
Microprocessor Applications
- Personal computers, laptops, and servers (general-purpose computing)
- Workstations and high-performance computing
- Smartphone and tablet application processors (as SoC cores running Android/iOS)
- Networking equipment (routers, switches) where high throughput and an OS are required
Microcontroller Applications
- Consumer: washing machines, microwaves, remote controls, toys, wearables
- Automotive: engine control units (ECUs), body control modules, ABS, airbag controllers, infotainment peripherals, EV battery management
- Industrial: PLCs, motor drives, sensors and transmitters, robotics, HMIs
- Medical: infusion pumps, patient monitors, hearing aids, implantable devices
- IoT: sensor nodes, smart meters, home automation, wearables (often with integrated wireless radios)
- Communications: modems, protocol converters, USB/serial bridges
Selection Criteria: MPU or MCU
A practical selection flow:
- Determine the system role. Is it a general-purpose computing platform with an OS, large memory, and high throughput (→ MPU/SoC)? Or a dedicated control task with hard real-time requirements, low cost, and low power (→ MCU)?
- Estimate compute and memory needs. Use benchmark data (CoreMark, DMIPS) and profile the application. Leave headroom (typically 30–50%) for future features and worst-case loads.
- Enumerate required peripherals. Count UARTs, SPIs, I²Cs, timers, ADC channels, and PWM outputs; verify the part has enough and that pin multiplexing does not conflict.
- Check real-time requirements. Interrupt latency, DMA availability, and deterministic execution (caches can hurt determinism; TCM helps) are critical.
- Evaluate power budget. Run-mode current per MHz, sleep-mode current, and wake-up time determine battery life and thermal design.
- Consider the ecosystem. Toolchain maturity, vendor HAL/drivers, reference designs, community support, long-term availability, and second-source options.
- Check environmental and regulatory requirements. Temperature grade, AEC-Q100 (automotive), functional safety certification, and RF certification (for wireless parts).
- Total cost of ownership. Unit price plus development tools, licensing, and engineering time—not just the BOM cost.
Modern Trends
- 32-bit dominance and the decline of 8-bit: 32-bit MCUs (especially ARM Cortex-M and RISC-V) now dominate new designs because they offer more performance and memory at costs approaching 8-bit parts. 8-bit MCUs persist in ultra-cost-sensitive and legacy applications.
- RISC-V: an open, royalty-free ISA that has spawned a rapidly growing ecosystem of MCU and application-class cores, offering freedom from vendor lock-in and enabling custom instruction extensions.
- Heterogeneous and multicore MCUs: dual-core MCUs (e.g., a Cortex-M4 for real-time control plus a Cortex-M0+ for housekeeping) and asymmetric multiprocessing are increasingly common.
- AI at the edge (TinyML): MCUs with DSP extensions, vector units, and dedicated neural-network accelerators (NPUs) run inference for keyword spotting, gesture recognition, and predictive maintenance at microwatt power levels.
- Integrated wireless: SoCs combining an MCU core with Bluetooth LE, Wi-Fi, LoRa, or NB-IoT radios (e.g., ESP32, nRF52) have become the default for IoT endpoints.
- Security: hardware root of trust, secure boot, encrypted flash, trusted execution environments (TrustZone for ARMv8-M), and physical tamper detection are now standard requirements for connected devices.
- Advanced packaging and chiplets: as with general ICs, MCU/MPU designs are moving toward heterogeneous integration, stacking memory and specialized accelerators with the compute die.