0% found this document useful (0 votes)
13 views39 pages

Understanding Embedded Systems Architecture

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views39 pages

Understanding Embedded Systems Architecture

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Embedded Systems

Session 2: From Concept to Core Architecture


The embedded systems landscape

The Arduino Platform

The Anatomy of a microcontroller

Outlines The lifecycle of a microcontroller


program

Electrical Fundamentals

Digital I/O
1. The Embedded Landscape:
Microprocessor vs. Microcontroller
The brain of general-purpose
computers (PC, Server)
Microprocessor Key Focus: Speed, maximum
(μP) – throughput, complex instruction sets

The Generalist Architecture: CPU core is central


component

Integration: Requires external


components (chipset, RAM, ROM, I/O)

OS: Typically runs complex OS


(Windows, Linux, macOS)

Use Case: Maximum computational


power and flexibility
Miniature, self-contained computer on
Microcontroller a single chip
(μC) –
Key Focus: Cost-efficiency, low power,
real-time control
The Dedicated
Specialist Integration: CPU, memory
(Flash/RAM/EEPROM), I/O on same die

System-on-a-Chip (SoC) design

OS: Often bare-metal or lightweight


RTOS

Use Case: Dedicated control (washing


machines, medical devices)
Microprocessor vs. Microcontroller

Feature Microprocessor (μP) Microcontroller (μC)

Integration CPU only, needs CPU, Memory, I/O on


external chip

Primary Goal High speed, power Low cost, low power,


real-time

Memory Large external (GBs) Small internal (KBs)

Clock Speed GHz range kHz to MHz range


2. The Arduino Platform:
Our Primary Tool
Brain: ATmega328P (8-bit AVR
Arduino: microcontroller)

The Hardware Power: Onboard regulators (7-12V


DC → 5V/3.3V)
Platform
Connectivity: USB-to-Serial
converter (CH340/ATmega16U2)

Bootloader: Pre-loaded software


for easy code upload

I/O Headers: Standardized 2.54mm


pin headers for GPIO access
3. Anatomy of a Microcontroller:
The ATmega328P
Harvard vs. Von
Neumann

Von Neumann: Single shared


bus for instructions and data
→ Bottleneck: Cannot fetch
instructions while accessing
data
Harvard Architecture
(ATmega328P):
• Separate buses for
program (Flash) and data
(SRAM)
• Advantage:
Simultaneous instruction
fetch and data access
• Result: One instruction
per clock cycle possible
Von-Neumann Case Study: MIPS
Von-Neumann Case Study: MIPS
Von-Neumann Case Study: MIPS Pipelining
Von-Neumann Case Study: MIPS Pipelining
Flash Memory (32KB):
 • Stores compiled
program and bootloader
 • Non-volatile, slow write,
fast read
SRAM (2KB):
 • Runtime variables,
stack, heap
 • Volatile, very fast
read/write
EEPROM (1KB):
 • Persistent
configuration/calibration
data
 • Non-volatile, slower
access, ~100K write cycles
CPU and Peripherals
CPU Components:
• ALU: Arithmetic and logical
operations
• Register File: 32 general-
purpose 8-bit registers (R0-R31)
• Program Counter (PC):
Address of next instruction
Key Peripherals:
• GPIO: General Purpose
Input/Output pins
• Timers/Counters: Delays, PWM,
time measurement
• UART/USART: Serial
communication
• ADC: Analog-to-Digital
Converter
Atmega 328p Ports

The Arduino UNO is based on the AVR (Atmega328p) microcontroller which has 3 digital
IO ports (PORTB, PORTC, and PORTD). Each port has up to 8 pins numbered from 0 to 7.
And there are 3 registers to control each digital IO port which we’ll discuss in the next
section.
ATmega328 Port Registers

The ATmega328 microcontroller, commonly found in Arduino Uno boards,


utilizes three main types of port registers for controlling its General Purpose
Input/Output (GPIO) pins:

•Data Direction Register (DDRx):


•This register determines the direction (input or output) of each pin within a
specific port.
•DDRx can be DDRB, DDRC, or DDRD, corresponding to Port B, Port C, and
Port D, respectively.
•Writing a 1 to a bit in DDRx configures the corresponding pin as an output.
•Writing a 0 to a bit in DDRx configures the corresponding pin as an input.
ATmega328 Port Registers

•Port Data Register (PORTx):


•This register is used to set the output state of pins configured as outputs
and to enable/disable internal pull-up resistors for pins configured as inputs.
•PORTx can be PORTB, PORTC, or PORTD.
•When a pin is configured as an output (DDRx bit is 1), writing a 1 to the
corresponding bit in PORTx sets the pin high, and writing a 0 sets it low.
•When a pin is configured as an input (DDRx bit is 0), writing a 1 to the
corresponding bit in PORTx enables the internal pull-up resistor for that pin,
while writing a 0 disables it.
ATmega328 Port Registers

•Port Input Pin Register (PINx):

•This register is used to read the current logical state of the pins within a specific
port.
•PINx can be PINB, PINC, or PIND.
•Reading from PINx provides the actual voltage level present on the physical pin,
regardless of whether it is configured as an input or output. This is crucial for reading
the state of input pins.
The Arduino Software Ecosystem

IDE: Cross-platform editor with standard build


process
Abstraction Layer: Arduino Core library (C++)
Example: digitalWrite(13, HIGH);
→ Compiles to complex register operations
(DDR, PORT)
Program Structure:
• setup(): Runs once at startup (initialization)
• loop(): Runs continuously (main control routine)
Arduino Registers Access

Let’s say we’d like to set the Arduino pin 10 to be an output pin and
directly write to it HIGH and LOW.

Too fast
4. The Life of a
Microcontroller Program
The Compilation and
Upload Process
1. Sketch → C++: IDE adds headers and
prototypes
2. C++ → Machine Code: AVR-GCC
compiler creates .hex file
3. .hex File: Executable machine
instructions with checksums
4. Upload: IDE sends .hex via USB-to-Serial
5. Bootloader: Writes new program to
Flash memory
Execution - The Fetch-Decode-Execute Cycle

Reset Vector: PC loaded with


program start address
Fetch: CPU retrieves instruction
from Flash at PC address
Decode: Instruction analyzed
(ADD, JUMP, WRITE_TO_PORT,
etc.)
Execute: CPU performs operation:
• ALU calculations
• SRAM read/write
• Hardware register
manipulation
PC updated to next instruction
Harvard Architecture: Often
completes in single clock cycle!
(considering the pipelining)
Pipelining in AVR
5. Electrical Fundamentals
for I/O
Digital Signals and Logic Levels

Digital systems: Logic HIGH (1) and


Logic LOW (0)
5V ATmega328P voltage mapping:
• Logic HIGH: ~5V
• Logic LOW: ~0V (Ground)
Technical Specifications:
• VIH (Input High): Minimum voltage for
HIGH (≥3V for 5V system)
• VIL (Input Low): Maximum voltage for
LOW (≤1.5V for 5V system)
Noise Margin: Dead space for electrical
interference protection
Current and Power Considerations
ATmega328P is severely current-
limited!
Maximum: 40mA per pin,
recommended safe: 20mA
Total chip limit: ~200mA combined
Sourcing: Current flows OUT of pin
(HIGH → Load → GND)
Sinking: Current flows INTO pin (VCC
→ Load → Pin LOW)
→ Sinking is generally more robust
Ohm's Law: R = (Vsupply - Vload) /
Idesired
Always use current-limiting resistors
for LEDs!
6. Digital Input and Output (I/O)
Digital Output (Controlling the World)
Digital Input (Sensing the World)
The Problem of Floating Inputs

Floating Input: Pin connected to nothing/inactive


device
Problem: High-impedance buffer acts like
antenna picks up: Random noise, static, nearby
signal coupling
Result: Pin voltage floats unpredictably between
VIH and VIL
Consequence: Random, rapid HIGH/LOW
transitions
System behavior becomes completely unreliable!
Solution - Pull-up and Pull-down Resistors

Pull-up Resistor (10kΩ to VCC):


• Default: Pin pulled HIGH
• Active-LOW: Switch closes → Pin reads
LOW
Pull-down Resistor (10kΩ to GND):
• Default: Pin pulled LOW
• Active-HIGH: Switch closes → Pin reads
HIGH
ATmega328P Internal Pull-ups:
• pinMode(pin, INPUT_PULLUP);
• Preferred method - eliminates external
components!
7. Case Study:
Traffic Light System
Summary and Next Steps
Today's Coverage:
• Microprocessors vs. Microcontrollers
• ATmega328P architecture and memory
• Harvard Architecture efficiency
• Digital logic levels (VIH, VIL) and current handling
• Floating inputs and pull-up/pull-down resistors
• Register manipulation (DDR, PORT, PIN)
Next Session:
• Analog Input (ADC)
• Timers and PWM (Pulse Width Modulation)
Questions

Alaa E. Abdel-Hakim

You might also like