EE4360 Embedded Systems Design and
Programming
LECTURE 3
EMBEDDED CONTROLLERS
By
Prof. Buddhika Jayasekara
Model Design: A System?
❑ A system is a mapping of a set of inputs into a set of outputs
❑ Inputs: Digital data from hardware devices and other software
systems (connected to sensors, cameras, etc. through ADCs )
❑ Outputs: External hardware devices like actuators, displays, etc
(through DACs)
System
2
System of Systems
Sub System2
Sub System1
System
Sub System N Sub System3
3
Embedded Systems
➢ A system, which is controlled by a controller embedded
within it
Can be defined as:
❑ Special-purpose computer system designed to perform one or a
few dedicated functions, sometimes with real-time constraints
❑ Microprocessor based system that is embedded as a subsystem
in a larger system
❑ Combination of computer hardware and software, either fixed
in capability or programmable, that is specifically designed for
a particular application device
4
Embedded System Design- Step by Step
7/17/2024 10:17 AM 5
Embedded System Design- Step by Step
7/17/2024 10:17 AM 6
Embedded System Design- Step by Step
7/17/2024 10:17 AM 7
Embedded System Design- Step by Step
7/17/2024 10:17 AM 8
Embedded Systems: Components
❑ Processor: Microprocessor/ Microcontroller / DSP
❑ Memory (On-chip and Off chip)
❑ Sensors
❑ Actuators
❑ Converters (A-D and D-A)
❑ Communication path with the interacting environment
7/17/2024 10:17:18 AM 9
Microcontrollers
❑ Contains
▪ Simple processor
▪ Program memory
▪ Data memory
▪ Analog/Digital input/outputs
▪ Interfacing peripherals
▪ Counters and timers
▪ Needs to be powered, and
needs a clock signal
7/17/2024 10:17:18 AM 10
Systems Control: Background
❑ Open-loop control systems:
▪ Current state and the model is used by the controller
▪ No feedback
▪ Successful if the controller has a good prior knowledge about the behavior
❑ E.g.
▪ Irrigation Sprinkler system-programmed to turn on at set times (not measure
moisture content as a feedback)
▪ Bread toaster
11
Systems Control: Digital Control
❑ Digital Control Systems
▪ Real world signals are analog
▪ Processing in Digital format
▪ Need Analog to Digital Converters (ADCs)
▪ Digital to Analog converters (DACs)
❑ Block Diagram
12
Controllers for Digital Control-Hardware
❑ Digital Computer-software programs
❑ Microcontrollers
▪ Small computer on a single IC containing a processor core, memory,
and programmable Input/output peripherals
▪ Used in automatically controlled products and embedded systems
▪ E.g. automobile engine control systems, implantable medical devices,
remote controls, power tools, toys, industrial automation
▪ PIC microcontrollers, ATMEL
13
Controllers for Digital Control-Hardware
❑ Digital Signal Processors (DSPs)
▪ Specialized microprocessor with an architecture optimized for the fast
operational needs of digital signal processing
▪ Large number of mathematical operations need to be performed quickly
and repetitively on a set of data, i.e. audio, video data
▪ E.g., Texas Instruments-C6000 series, DSPICs-dsPIC33 family, etc.
14
Controllers for Digital Control-Hardware
❑ Programmable Logic devices (PLDs)
▪ Used to build reconfigurable logic circuits
▪ Combination of a logic device and a memory device
▪ As Field-programmable Gate Arrays (FPGAs)
15
Controllers for Digital Control-Hardware
❑ Programmable Logic Controllers (PLCs)
▪ Digital computer used for industrial applications such as automation,
electromechanical processes, factor assembly lines, etc.
▪ Designed for industrial conditions, e.g., temp ranges, immunity to
electrical noise, resistance to vibrations, etc.
▪ Can handle multiple inputs and outputs
▪ Used for discrete and continuous controls
▪ E.g., Siemens S7 family
16
Processor-Instruction sets – CISC and RISC
❑ CPU has a set of instructions that it recognizes and responds
❑ Complex Instruction Set Computer (CISC):
▪ Many instructions and considerable sophistication
▪ lead to slow operation
❑ Reduced Instruction Set Computer (RISC):
▪ limited instruction set
▪ leads to fast operation
Prepared by Dr. AGBP Jayasekara 17
Memory Types
❑ Volatile Memory:
▪ Only works as long as power is supplied
▪ Can be used as memory for temporary data storage
▪ Simple semiconductor technology and is easier to write
▪ Commonly been called RAM (Random Access Memory)
▪ Data Memory
Prepared by Dr. AGBP Jayasekara 18
Memory Types
❑ Non-volatile:
▪ Memory that retains its stored value even when power is
removed, e.g. desktop hard disk
▪ In an embedded system , non-volatile semiconductor
memory is used
▪ Sophisticated semiconductor technology is applied
▪ More difficult to write to electrically, e.g, in terms of time
or power taken, or complexity of the writing process
▪ Non-volatile memory is used for holding the computer
program
▪ ROM (Read-Only Memory)
▪ Program Memory
Prepared by Dr. AGBP Jayasekara 19
Memory Organization
❑ To interact with memory:
▪ Address of the memory location
▪ Actual data that belongs in the location
❑ These are connected on two sets of interconnections
▪ Address bus
▪ Data bus
❑ Data bus and address bus need to reach every memory area
❑ Two architectures
▪ Von Neumann architecture
▪ Harvard architecture
Prepared by Dr. AGBP Jayasekara 20
Memory Organization: Von Neumann architecture
❑ One address bus and one data bus
❑ Same address and data buses serve both program and data
memories
❑ Input/output interconnected in the same way
Prepared by Dr. AGBP Jayasekara 21
Memory Organization: Von Neumann architecture
❑ Simple and logical, and gives a certain type of flexibility
❑ Addressable memory area can be divided between program
memory and data memory
❑ Disadvantages:
▪ Same data bus for all areas of memory, e.g. cannot take
different word sizes
▪ If one area is using the memory, another can’t
▪ E.g. if the CPU is accessing program memory, then data
memory must be idle and vice versa
Prepared by Dr. AGBP Jayasekara 22
Memory Organization: Harvard Architecture
❑ Greater flexibility in bus size with a little more complexity
❑ Program memory and data memory have their own address
and data buses
Prepared by Dr. AGBP Jayasekara 23
Memory Organization: Harvard Architecture
❑ Data and program memories can be accessed simultaneously
❑ Address and data buses can be in different size
❑ Disadvantages:
▪ Reinforces the distinction between program and data
memory, even when this distinction is not wanted
▪ E.g., when data is stored in program memory as a table, but
is actually needed in the data domain
Prepared by Dr. AGBP Jayasekara 24
PIC 12 Series- 12F508/509
❑ Simple PIC microcontroller
❑ 8/14-Pin, 8-Bit Flash Microcontrollers
❑ Small in size
Main Components
▪ Core (containing the CPU)
▪ Program memory
▪ Data memory (or RAM)
▪ Data paths
▪ Peripherals
7/17/2024 10:17:18 AM Ref: http://www.microchip.com 25
7/17/2024 10:17:18 AM 26
CPU/Core
❑ CPU consists of
▪ ALU (the Arithmetic Logic Unit): Performs
arithmetic and logical operations
▪ Working register (W Reg): results of any CPU
operation is held in the Working register
▪ Status register : used to carry extra information
about the result of the instruction most recently
executed, e.g. result is zero, negative or positive
▪ Multiplexer (MUX): selects from two sources
which data is presented
7/17/2024 10:17:18 AM 27
Data and Program Memory
❑ Data memory:
▪ 25 bytes for the PIC12F508 or 41 for the PIC12F509
▪ RAM memory locations ‘file registers’ or ‘registers’
❑ Program memory:
▪ 512 12-bit words for the PIC12F508 or 1024 for the PIC12F50
❑ Harvard Architecture
❑ Two address buses
▪ one for program memory
▪ other for data memory and all peripherals
❑ Two data buses
▪ one for program memory
▪ one for data memory and peripherals
7/17/2024 10:17:18 AM 28
Program
memory
Address bus –
Program memory Data Memory
Data Bus-
program Memory
Address bus –
Data memory
Data Bus-
Data Memory
7/17/2024 10:17:18 AM 29
PIC-Harvard Architecture
❑ Data bus for data memory and peripherals
▪ 8-bit, and serves primarily the data memory, the General-Purpose
Input/Output (GPIO) and the Timer
❑ Address bus for data memory (RAM addr)
▪ Derived from the address multiplexer (addr MUX), which selects the
address from one of two sources
❑ Address bus for Program Memory arises from Program
Counter
▪ 12-bit and can address 212 memory locations, or 4096 locations
▪ Only 512 or 1024 words, we recognize that the address bus is larger
than necessary for this memory size
❑ Data bus from program memory
▪ 12-bit program bus
▪ 10:17:18
7/17/2024 CarriesAMthe instruction words from the memory to the ‘Instruction 30
Program
memory
Address bus –
Program memory Data Memory
Data Bus-
program Memory Address extracted from
Address bus –
Instruction word Data memory
Data from
instruction word
Data Bus-
Instruction Data Memory
7/17/2024 10:17:18 AM 31
PIC-Harvard Architecture
❑ As the PIC is a RISC computer, each instruction word must
carry not only the instruction code itself, but also any address
or data information
❑ ‘Instruction Reg’ receives the instruction word and then
divide the components
▪ May carry address information -‘Direct Addr’ bus to address
multiplexer (Addr MUX)
▪ May carry a data byte that is to be used as literal data for the execution
of that instruction - to the multiplexer (‘MUX’), which feeds into the
ALU
▪ Instruction data feeds into the ‘Instruction Decode and Control’ unit
7/17/2024 10:17:18 AM 32
PIC-Harvard Architecture
❑ Power Supply- pins VDD and VSS respectively
▪ ‘Power-on Reset’ function detects when power is applied
❑ MCLR input can be used to place the CPU in a Reset
condition and to force the program to start again
❑ An internal clock oscillator (‘Internal RC OSC’) is provided
▪ External oscillator connections can be made using input/output
❑ The oscillator signal is conditioned for use through the
microcontroller in the ‘Timing Generation’ unit
❑ The Watchdog Timer is a safety feature, used to force a reset in
the processor if it crashes.
7/17/2024 10:17:18 AM 33
7/17/2024 10:17:18 AM 34
Assignment Q1
Consider capabilities of PIC16F87X microcontroller based on
specifications given in the data sheet
List the main components of the microcontroller based on the
architecture.
Illustrate the Harvard Architecture by using simplified diagram.
Indicate bus sizes on the same sketch.
7/17/2024 10:17:18 AM 35
7/17/2024 11:06 AM 36
Programming Microcontrollers
37
Programming
38
Programming
39
40
Microcontrollers
Common
Types
PIC AVR 8051 ARM
7/17/2024 10:17:19 AM 41
Microcontroller-Manufacturers
Architecture
❑ Peripheral Interface Controller (PIC) by Microchip
Ref: http://www.microchip.com/
❑ ATMEL
▪ Atmel AVR 8- and 32-bit Microcontrollers
▪ 8051 instruction set
▪ E.g. - ATmega48 Ref: http://www.atmel.com
▪ ARM Processor-based Solutions
❑ Freescale
Ref: http://www.freescale.com
▪ 8 – 16 bit MCUs
❑ Texas Instruments
Ref: http://www.ti.com
▪ 16 – 32 bit MCUs
7/17/2024 10:17:19 AM 42
ATMEL AVR Microcontrollers
❑ Atmel AVR 8- and 32-bit Microcontrollers
Go to ATMEL web
http://www.atmel.com
7/17/2024 10:17:19 AM 43
ATMEL AVR Microcontrollers
❑ Atmel AVR 8- and 32-bit Microcontrollers
Go to ATMEL web
http://www.atmel.com
7/17/2024 10:17:19 AM 44
ATMEL AVR Microcontrollers
❑ E.g. ATmega164
Go to ATMEL web
http://www.atmel.com
7/17/2024 10:17:19 AM 45
ATMEL: ATmega164 Architecture
❑ Atmel ATmega164 is a register-based architecture
❑ Operands of an operation are stored in registers located
with the CPU
▪ Before an operation is performed, the computer loads all necessary data
for the operation to its CPU
▪ result of the operation is also stored in a register
▪ minimizes slower memory accesses
❑ Instruction set based on the RISC concept
▪ Complement of very simple and efficient basic operations
▪ 131 RISC type instructions- most single cycle
▪ to simplify hardware and instructions for the purpose of increasing the
overall performance
7/17/2024 10:17:19 AM 46
ATMEL: ATmega164 Architecture
❑ ATmega164 has external connections for
▪ power supplies(VCC, GND),
▪ external time base input pins to drive its clocks (XTAL1 and XTAL2),
▪ Processor reset (active low RESET),
▪ four 8-bit ports (PA0- PA7, PB0-PB7, PC0-PC7, and PD0-PD7),
7/17/2024 10:17:19 AM 47
ATMEL: ATmega164 Architecture
❑ four 8-bit ports
▪ as general purpose digital input/output ports, or they may be used for
the alternate functions
❑ Contains
▪ a timer subsystem
▪ an analog-to-digital converter, an analog comparator
▪ an interrupt subsystem
▪ a timing subsystem
▪ memory components
▪ extensive serial communication
7/17/2024 10:17:19 AM 48
7/17/2024 10:17:19 AM 49
ATMEL: ATmega164 Architecture
Non Volatile and Data Memories
❑ Three main memory sections:
▪ flash electrically erasable programmable read only memory
(EEPROM),
▪ byte-addressable EEPROM for data storage
▪ Static random access memory (SRAM)
❑ Static random access memory (SRAM)
▪ Volatile
▪ can be written to, and read from, during program execution
▪ ATmega164 is with 1K (actually 1120) bytes of SRAM
▪ A small portion (96 locations) of the SRAM is set for the general
purpose registers used by the CPU and also for the input/output and
peripheral subsystems
▪ During program execution, RAM is used to store global variables,
support dynamic memory allocation of variables, and to provide
allocation for the stack
7/17/2024 10:17:19 AM 50
ATMEL: ATmega164 Architecture
Non Volatile and Data Memories
❑ Programmable Flash EEPROM
▪ nonvolatile
▪ used to store programs
▪ It is called bulk programmable since it can be erased and programmed
as a single unit, e.g. a global variable within a program
▪ ATmega164 -16K bytes of onboard
▪ In-system programmable
❑ Byte Addressable EEPROM
▪ Used to permanently store and recall variables during program
execution
▪ Nonvolatile
▪ Useful for logging system malfunctions and fault data during program
execution
7/17/2024 10:17:19 AM 51
ATMEL: ATmega164 Architecture- Ports
❑ Four, 8-bit general purpose, digital input/output (I/O) ports
designated PORTA, PORTB, PORTC, and PORTD
❑ Registers
▪ Data Register PORTx —- used to write output data to the port.
▪ Data Direction Register DDRx —- used to set a specific port pin to
either output (1) or input (0)
▪ Input Pin Address PINx —- used to read input data from the port
7/17/2024 10:17:19 AM 52
ATMEL: ATmega164 Architecture- Ports
❑ For input, the pin may be selected for either an input pin or to
operate in the high impedance (Hi-Z) mode
▪ In Hi-Z mode, the input appears as high impedance to a particular pin
7/17/2024 10:17:19 AM 53
ATMEL: ATmega164 Architecture- Ports
❑ Configured at the beginning of a program, e.g. C code
7/17/2024 10:17:19 AM 54
ATMEL: ATmega164 Architecture
Internal Systems
❑ Time Base
▪ Microcontroller is a complex synchronous state machine
▪ Each program instruction issues a series of signals to control the
microcontroller hardware
▪ controlled by a precise time base called the clock
▪ ATmega164 may be clocked internally using a user selectable resistor
capacitor (RC) time base, or it may be clocked externally
▪ may choose an internal fixed clock operating frequency of 1, 2, 4 or 8
MHz
▪ for a wider range of frequency selections, an external time source may
be used
7/17/2024 10:17:19 AM 55
ATMEL: ATmega164 Architecture
Internal Systems
❑ Timing System
▪ complement of timers
▪ generate a precision output signal,
▪ measure the characteristics (period, duty cycle, frequency) of an
incoming digital signal,
▪ generate precision delays,
▪ implement a real time clock, or count external events
▪ ATmega164 is equipped with two 8-bit timer/counters and one 16-bit
counter
7/17/2024 10:17:19 AM 56
ATMEL: ATmega164 Architecture
Internal Systems
❑ PWM Channels
▪ PWM signal is characterized by a fixed frequency and a varying duty
cycle
▪
▪ ATmega164 is equipped with three separate timers to support six
channels of PWM
▪ PWM signals are used in applications including controlling the position
of a servo motor, DC motor speed control, or generating an analog DC
output signal
7/17/2024 10:17:19 AM 57
ATMEL: ATmega164 Architecture
Internal Systems
❑ Serial Communication
▪ Universal Synchronous and Asynchronous Serial Receiver and
Transmitter (USART)
▪ Serial peripheral interface (SPI)
▪ Two-wire Serial Interface
❑ Analog to Digital Converter
▪ eight channel analog to digital converter (ADC) subsystem
▪ ATmega164ADC has 10 bit resolution, which means that an analog
voltage between 0 and 5
▪ Voltage resolution of approximately 4.88 mV
7/17/2024 10:17:19 AM 58
ATMEL: ATmega164 Architecture
Internal Systems
❑ Analog comparator
▪ used as a threshold detector or used to clean up a corrupted digital
signal
❑ Interrupts
▪ normal sequence of instructions must be interrupted to respond to
higher priority events inside and outside the microcontroller
▪ When these higher priority events occur, the microcontroller must
temporarily suspend normal operation and execute event specific
actions called an interrupt service routine
▪ employed to continuously monitor the status of an ongoing event while
the microcontroller is processing other activities
7/17/2024 10:17:19 AM 59
ATMEL: ATmega164 Architecture
Physical and Operational Parameters
❑ As a system designer, it is important to know the various
physical and operating parameter options available
❑ Packaging
▪ 40-pin plastic dual in line package (PDIP)
▪ a 44-lead thin quad flat pack (TQFP) package
▪ a 44-pad quad flat non-lead/micro lead frame (QFN/MLF) package,
▪ 44 pin DRQFN package
7/17/2024 10:17:19 AM 60
ATMEL: ATmega164 Architecture
Physical and Operational Parameters
❑ Power Consumption
▪ operates at supply voltages from 1.8 to 5.5 VDC
▪ E.g. actively operating at 1 MHz from a 1.8VDC power source, the
current draw is 0.4 mA
▪ Different modes- power down mode only 0.1 mA
❑ Operating speeds
▪ ATmega164 operates with a clock speed from 0 to 20 MHz
▪ the system designer must determine the optimal speed of
microcontroller operation for a given application
▪ The microcontroller’s power consumption is directly related to
operating speed, i.e, the faster the operating speed of the
microcontroller the higher its power consumption
▪ This becomes especially critical in portable, battery-operated embedded
systems applications.
7/17/2024 10:17:19 AM 61
ATmega164P
7/17/2024 10:17:19 AM 62
ATxmega16A4U
7/17/2024 10:17:19 AM 63
Assignment Q2
❑ list main components of a microcontroller ATmega164P
microcontroller based on specifications given in the data sheet
( a copy of the relevant summary is given).
❑ List the main I/O ports
❑ Evaluate how you could configure I/O and properties in
software. Consider an example C code.
7/17/2024 10:17:19 AM 64
Thank you
QUESTIONS
7/17/2024 10:17 AM 65