Unit 1 - Notes
Unit 1: Introduction to Embedded Systems
1. Definition of an Embedded System
An Embedded System is a computer system—a combination of a computer processor, computer memory, and input/output peripheral devices—that has a dedicated function within a larger mechanical or electronic system. It is "embedded" as part of a complete device often including hardware and mechanical parts.
Unlike a general-purpose computer (like a PC), which is designed for a wide variety of tasks, an embedded system is designed to perform one or a few specific tasks, often with real-time computing constraints.
Key Characteristics:
- Task-Specific: Designed to perform a dedicated function or a predefined set of functions. For example, the system in a microwave oven is designed only for controlling the microwave.
- Tightly Constrained: Subject to design constraints on performance, power consumption, cost, size, and reliability.
- Reactive and Real-Time: Many embedded systems must react to events in the external environment within a specific time frame.
- Hard Real-Time: Missing a deadline is a total system failure (e.g., an airbag deployment system).
- Soft Real-Time: Missing a deadline results in degraded performance but not a complete failure (e.g., a video streaming device).
- Microprocessor/Microcontroller-Based: The core of the system is a processor or controller that executes the control logic.
- Minimal or No User Interface: Many systems operate without a traditional user interface (e.g., no screen or keyboard). They may have simple LEDs, buttons, or operate autonomously.
- High Reliability and Stability: Expected to run for long periods without failure or reset.
Examples of Embedded Systems:
| Category | Examples |
|---|---|
| Consumer Electronics | Digital cameras, smart TVs, microwave ovens, washing machines, smartwatches |
| Automotive | Anti-lock Braking System (ABS), Engine Control Unit (ECU), infotainment systems |
| Industrial Control | Programmable Logic Controllers (PLCs), robotics, process control systems |
| Medical Devices | Pacemakers, patient monitoring systems, infusion pumps |
| Networking | Routers, network switches, firewalls |
| Aerospace & Defense | Avionics systems, missile guidance systems, satellite communication systems |
2. Embedded System Architecture
The architecture of an embedded system is typically centered around a microcontroller or microprocessor. It consists of three main components: Hardware, Application Software, and a Real-Time Operating System (RTOS) (optional).
Core Components:
-
Processor (The "Brain")
- Microcontroller (MCU): The most common choice. It is a self-contained system on a single chip, including a processor core, memory (RAM and Flash), and I/O peripherals. Examples: PIC, AVR, ARM Cortex-M series.
- Microprocessor (MPU): Contains only the processor core (CPU). Memory and peripherals are external components, making the system more complex but also more flexible and powerful. Examples: Intel Core series, ARM Cortex-A series.
- Digital Signal Processor (DSP): Specialized processor for high-speed mathematical operations required for processing signals (audio, video).
- FPGA (Field-Programmable Gate Array): An integrated circuit that can be configured by the developer after manufacturing. Used for high-speed, parallel processing tasks.
-
Memory
- ROM (Read-Only Memory): Non-volatile memory used to store the program code (firmware).
- Flash Memory: The most common type of ROM in modern MCUs. It is electrically erasable and programmable.
- EEPROM (Electrically Erasable Programmable ROM): Used to store small amounts of non-volatile data that needs to be updated occasionally (e.g., configuration settings).
- RAM (Random-Access Memory): Volatile memory used to store variables, data structures, and the program stack during runtime. Data is lost when power is removed.
- SRAM (Static RAM): Faster and more expensive than DRAM. Used for CPU caches and internal MCU RAM.
- DRAM (Dynamic RAM): Slower but denser and cheaper. Used as main memory in larger systems.
- ROM (Read-Only Memory): Non-volatile memory used to store the program code (firmware).
-
Input/Output (I/O) Peripherals
These are hardware modules that connect the processor to the outside world.- Timers/Counters: Used for generating delays, creating periodic events, measuring time, or generating Pulse-Width Modulation (PWM) signals for motor control or dimming LEDs.
- Communication Interfaces:
- UART (Universal Asynchronous Receiver/Transmitter): For serial communication (e.g., RS-232, connecting to a PC).
- SPI (Serial Peripheral Interface): A fast, synchronous serial protocol for communicating with sensors, memory chips, etc.
- I²C (Inter-Integrated Circuit): A two-wire serial protocol for connecting multiple devices (sensors, displays) on a shared bus.
- CAN (Controller Area Network): Used in automotive and industrial applications for robust communication.
- USB, Ethernet: For higher-speed communication.
- Analog-to-Digital Converter (ADC): Converts analog signals from sensors (e.g., temperature, light) into digital values the processor can understand.
- Digital-to-Analog Converter (DAC): Converts digital values from the processor into analog voltage signals.
- General Purpose I/O (GPIO): Pins that can be configured as digital inputs (to read buttons) or digital outputs (to drive LEDs).
-
Buses
A set of parallel wires connecting the components.- Address Bus: Carries the memory address that the processor wants to read from or write to.
- Data Bus: Carries the actual data between the processor and memory/peripherals.
- Control Bus: Carries control signals (e.g., read/write commands, clock signals, interrupts).
3. Challenges and Design Issues in Embedded Systems
Developing an embedded system involves balancing several competing constraints.
- Hardware-Software Co-design: Hardware and software components are developed simultaneously. Decisions in one domain directly impact the other. For example, choosing a cheaper processor might require highly optimized software to meet performance goals.
- Real-time Performance: The system must often respond to events within a strict deadline. This requires careful software design, interrupt handling, and sometimes a Real-Time Operating System (RTOS).
- Power Consumption: Many systems are battery-powered and must operate for long periods. This requires low-power components and using software techniques like sleep modes to conserve energy.
- Cost Sensitivity: The per-unit cost of an embedded system is critical, especially for high-volume consumer products. The Bill of Materials (BOM) must be minimized.
- Limited Memory and Performance: To keep costs low, embedded systems often have limited RAM and Flash memory, and a less powerful processor. Code must be highly efficient and have a small memory footprint.
- Reliability and Safety: Systems used in medical, automotive, or industrial applications must be extremely reliable and fail-safe. This involves robust error handling, fault tolerance, and adherence to safety standards (e.g., ISO 26262 for automotive).
- Security: With the rise of IoT, embedded systems are increasingly connected and vulnerable to attacks. Security measures like secure boot, data encryption, and authentication are becoming essential.
- Time-to-Market: There is intense pressure to get products to market quickly. This drives the need for efficient development tools, reusable software components, and rapid prototyping platforms.
4. CISC vs. RISC
Processor architectures are broadly classified into Complex Instruction Set Computer (CISC) and Reduced Instruction Set Computer (RISC). Most modern microcontrollers are RISC-based.
CISC (Complex Instruction Set Computer)
- Goal: To complete a task in as few lines of assembly code as possible. This was achieved by creating complex instructions that could perform multiple operations in a single step (e.g., load from memory, perform an arithmetic operation, and store back to memory).
- Characteristics:
- Large number of instructions.
- Instructions have variable lengths.
- Multiple clock cycles required to execute a single instruction.
- Many complex addressing modes.
- Emphasis on hardware to execute complex commands.
- Example: Intel x86 family (used in PCs).
RISC (Reduced Instruction Set Computer)
- Goal: To speed up execution by using a small set of simple, highly optimized instructions that can be executed very quickly (ideally in one clock cycle).
- Characteristics:
- Small, fixed number of instructions.
- Instructions have a fixed length, which simplifies decoding.
- Most instructions execute in a single clock cycle.
- Uses a "load-store" architecture: data must be loaded into registers from memory before being operated on, and stored back after.
- Emphasis on software and compiler to combine simple instructions to perform complex tasks.
- Heavily pipelined.
- Example: ARM, MIPS, AVR, RISC-V (used in most MCUs and mobile devices).
Comparison Table
| Feature | CISC (Complex Instruction Set Computer) | RISC (Reduced Instruction Set Computer) |
|---|---|---|
| Instruction Set | Large, complex instruction set | Small, simple, and reduced instruction set |
| Instruction Format | Variable length | Fixed length |
| Execution Time | Multiple clock cycles per instruction (high CPI) | Single clock cycle for most instructions (low CPI) |
| Memory Access | Memory-to-memory operations are common | Load-Store Architecture (register-to-register) |
| Addressing Modes | Many complex addressing modes | Few simple addressing modes |
| Pipelining | More difficult to implement effectively | Easy to implement; a key design feature |
| Compiler Complexity | Simpler compiler; complexity is in the hardware | More complex compiler; relies on code optimization |
| Hardware vs. Software | Emphasis on hardware | Emphasis on software and compiler |
| Examples | Intel x86, VAX | ARM, MIPS, AVR, PowerPC, RISC-V |
5. Fundamentals of Von-Neumann/Harvard Architectures
These architectures describe how the processor accesses memory. The key difference lies in the handling of instructions and data.
Von-Neumann Architecture
- Concept: Uses a single, shared memory space for both program instructions and data.
- Mechanism: A single bus (address bus and data bus) is used to fetch both instructions and data. The CPU can either fetch an instruction or read/write data from memory at one time, but not both simultaneously.
- Pros:
- Simpler hardware design and control unit.
- More efficient use of memory space.
- Cons:
- Von-Neumann Bottleneck: The single shared bus creates a performance bottleneck. The processor's speed is limited by the rate at which it can fetch instructions and data from memory.
+-----------------+
| CPU |
+--------+--------+
| (Shared Address/Data Bus)
V
+-------------------------------+
| Single Memory |
| (Instructions + Data) |
+-------------------------------+
Harvard Architecture
- Concept: Uses separate memory spaces and separate buses for program instructions and data.
- Mechanism: The CPU can fetch an instruction from the program memory and access data from the data memory at the same time.
- Pros:
- Faster execution due to simultaneous instruction and data fetching, eliminating the Von-Neumann bottleneck.
- Ideal for applications where high-speed data processing is required (like DSPs).
- Cons:
- More complex hardware design (requires two sets of buses).
- Can lead to unused memory if the instruction and data memory spaces are not balanced.
+-----------------+
| CPU |
+--------+--------+
/ \
(Instruction Bus) | | (Data Bus)
V V
+-----------------+ +-----------------+
| Instruction | | Data |
| Memory | | Memory |
+-----------------+ +-----------------+
Modified Harvard Architecture
Most modern microcontrollers (especially ARM Cortex-M) use a Modified Harvard Architecture.
- Concept: They have a Harvard architecture at the core level (separate instruction and data buses connecting to caches or tightly coupled memory) for high performance.
- Implementation: However, they present a single, unified address space to the programmer. A special bus matrix manages access, allowing instructions to be treated like data (e.g., for self-programming) and data to be placed in program memory. This combines the performance benefits of Harvard with the flexibility of Von-Neumann.
6. Types of Microcontrollers (MCUs)
Microcontrollers can be classified based on several criteria.
1. By Word Size / Bus Width
This refers to the size of the data bus and the internal registers.
- 8-bit MCUs:
- Process data in 8-bit chunks.
- Simple architecture, low cost, and low power consumption.
- Examples: Microchip PIC16/PIC18, Atmel AVR (used in Arduino), Intel 8051.
- Use Cases: Simple control applications, IoT sensor nodes, basic consumer electronics.
- 16-bit MCUs:
- Offer a balance between the performance of 32-bit and the low cost/power of 8-bit MCUs.
- Better performance and precision for arithmetic operations than 8-bit.
- Examples: Microchip PIC24, Texas Instruments MSP430.
- Use Cases: Low-power applications requiring more computational power, such as portable medical devices.
- 32-bit MCUs:
- The current industry standard for a wide range of applications.
- High performance, large memory addressing capability, and complex peripherals.
- Examples: ARM Cortex-M series (STM32, NXP Kinetis, aTmel SAM), Microchip PIC32.
- Use Cases: Complex applications requiring real-time operating systems (RTOS), advanced communication (USB, Ethernet), graphics, and signal processing.
2. By Instruction Set Architecture (ISA)
- CISC MCUs: Less common today, but historically significant. (e.g., Intel 8051).
- RISC MCUs: The vast majority of modern MCUs are RISC-based for better power efficiency and performance. (e.g., ARM, AVR, PIC).
3. By Memory Architecture
- Embedded Memory MCUs: Most common type. The Flash memory, SRAM, and peripherals are all on the same chip. This reduces cost, size, and power consumption.
- External Memory MCUs: These MCUs have an external memory controller to interface with external RAM and Flash chips. Used for applications that require more memory than can be integrated onto a single chip.
7. Selection of Microcontrollers
Choosing the right MCU is a critical design decision that impacts the entire project. The selection process involves balancing technical requirements with business considerations.
Key Selection Criteria
Technical Requirements:
-
Processing Power (Performance):
- Word Size: 8, 16, or 32-bit? Does the application involve 32-bit math?
- Clock Speed (MHz/GHz): Higher speed means more instructions per second.
- Core Architecture: An ARM Cortex-M4 (with FPU for floating-point math) is much more powerful than a Cortex-M0+, even at the same clock speed.
- Special Features: Does the application need a DSP or a Floating-Point Unit (FPU)?
-
Memory Requirements:
- Flash (Program Memory): How much space does your application code, libraries, and any stored data require? Always plan for future updates (e.g., if you need 40KB, choose a 64KB or 128KB part).
- RAM (Data Memory): How much memory is needed for variables, stacks, and heaps? If using an RTOS, this requirement increases significantly.
-
Peripherals and I/O:
- List all required interfaces: How many UART, SPI, I²C ports? Do you need USB, Ethernet, CAN?
- Analog Requirements: How many ADC channels are needed? What resolution (10, 12, 16-bit) and speed? Is a DAC required?
- Timers/PWM: How many timers and PWM outputs are needed for motor control, etc.?
-
Power Consumption:
- Crucial for battery-powered devices.
- Check datasheets for current consumption in different modes: Active, Sleep, and Deep Sleep/Standby.
- Consider the MCU's ability to run peripherals in low-power modes.
Business & Development Requirements:
-
Cost:
- Per-Unit Cost: What is the price of the MCU in the volume you plan to manufacture?
- Total System Cost: A slightly more expensive MCU with integrated peripherals might eliminate the need for external components, reducing the overall BOM cost.
-
Availability & Sourcing:
- Lead Time: How long does it take to get the MCU from the supplier?
- Longevity: Will the manufacturer support this part for the lifetime of your product?
- Sourcing: Is the part available from multiple distributors? Avoid single-source components.
-
Development Ecosystem:
- Tools: Are good quality, affordable compilers and debuggers (e.g., JTAG/SWD probes) available?
- Software Support: Does the manufacturer provide good documentation, libraries (HAL - Hardware Abstraction Layer), example code, and application notes?
- Community: Is there a strong online community for support (forums, blogs)? This is a huge advantage for ARM-based MCUs.
-
Physical Package & Environment:
- Package Type: Does the IC package (e.g., QFP, BGA, QFN) fit your PCB size and manufacturing capabilities?
- Operating Temperature: Does the MCU meet the required temperature range (e.g., consumer, industrial, or automotive grade)?