KEMBAR78
Lecture 4 | PDF | Embedded System | Microcontroller
0% found this document useful (0 votes)
9 views82 pages

Lecture 4

The document discusses embedded systems design, focusing on the components and architecture of embedded controllers, including microcontrollers like PIC and AVR. It covers system design principles, programming in assembly language, and specific instructions for manipulating registers. The lecture also includes practical assignments related to microcontroller programming and hardware connections.

Uploaded by

Arjun Prabaharan
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)
9 views82 pages

Lecture 4

The document discusses embedded systems design, focusing on the components and architecture of embedded controllers, including microcontrollers like PIC and AVR. It covers system design principles, programming in assembly language, and specific instructions for manipulating registers. The lecture also includes practical assignments related to microcontroller programming and hardware connections.

Uploaded by

Arjun Prabaharan
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
You are on page 1/ 82

EE4360 Embedded Systems Design and

Programming

LECTURE 4

EMBEDDED CONTROLLERS –PART II


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

8/21/2024 8:28 AM 5
Embedded System Design- Step by Step

8/21/2024 8:28 AM 6
Embedded System Design- Step by Step

8/21/2024 8:28 AM 7
Embedded System Design- Step by Step

8/21/2024 8:28 AM 8
Discussion – Design and Embedded System

❑ Task : Design of an suitcase


that automatically follow
you
❑ How do you design and
develop

8/21/2024 8:28 AM 9
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

8/21/2024 8:28:41 AM 10
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

8/21/2024 8:28:41 AM 11
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

8/21/2024 8:28:41 AM Ref: http://www.microchip.com 12


8/21/2024 8:28:41 AM 13
Program
memory
Address bus –
Program memory Data Memory

Data Bus-
program Memory
Address bus –
Data memory

Data Bus-
Data Memory

8/21/2024 8:28:41 AM 14
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

8/21/2024 8:28:41 AM 15
8/21/2024 8:28:41 AM 16
Programming Microcontrollers

17
18
Assembly Language Programming

❑ Assembly program consists of set of assembly instructions


❑ Assembly instruction consists of

▪ Brackets indicate optional fields


▪ [Label]- refer to a line by code name
▪ [mnemonic]- Assembly language instruction
▪ [operands]- Mnemonic (instruction) and operands fields
performs the real work of the program
▪ [comments]- assembler ignores the comments

8/21/2024 8:28:42 AM 19
Assembly Language Programming for PIC

❑ CPU use many registers to store data temporarily


❑ To Program in Assembly, need to understand
▪ Registers and architecture
▪ Role of the registers in processing data

❑ E.g. WREG register-working register


▪ Used in all arithmetic and logic instructions
▪ Results of any CPU operation is held in WREG
▪ Majority of registers are 8 bit
❑ E.g.
D7 D6 D5 D4 D3 D2 D1 D0

❑ Note: consider PIC12, PIC16, PIC18 series in assembly


programming

8/21/2024 8:28:42 AM 20
Block diagram of PIC16F84A

8/21/2024 8:28:42 AM 21
WREG Register in PIC

❑ MOVLW Instruction
▪ Moves 8 bit data into WREG register
▪ MOVLW K ;move literal value K into WREG
▪ MOVLW 25H ;move value 25H into WREG
▪ Letter L(literal) comes first and then the letter w for WREG, destination

❑ ADDLW Instruction
▪ ADDLW K ;add literal value K into WREG
▪ ADDLW 25H ;add value 25H into WREG
▪ Add literal value K to WREG register and put the result back in WREG
▪ E.g. MOVLW 25H ; Load 25H into WREG
ADDLW 34H : add 34H to WREG
▪ Result is 59H

8/21/2024 8:28:42 AM 22
WREG Register in PIC

❑ Moving a value larger than 255 (FF in hex) will truncate the
upper bit-warning
▪ E.g. MOVLW 7F2H ; illegal 7F2H > 8bits (FFH)

❑ E.g. MOVLW 12H ; Move 12H into WREG


ADDLW 16H : add 16H to WREG
ADDLW 11H : add 16H to WREG
ADDLW 40H : add 16H to WREG

Result: WREG = 79H

8/21/2024 8:28:42 AM 23
File Register (RAM/Data Memory)

❑ Special Functional Registers (SFRs)


▪ Dedicated to special functions such as ALU status, timer, I/O ports

❑ General Purpose Registers (GPRs)


▪ Group of RAM locations
▪ Size depends on the chip
❑ E.g.

❑ Additional EEPROM is available in some PICs


8/21/2024 8:28:42 AM 24
File Register (RAM/Data Memory)

8/21/2024 8:28:42 AM 25
MOVWF Instruction

❑ Move the value of WREG (W) to destination in File register


(F)
❑ Location of File register may be in SFR or GPR
❑ E.g.

▪ PORTB, PORTC, PORTD are SFR in File register


▪ Can be connected to I/O ports in PIC

8/21/2024 8:28:42 AM 26
MOVWF Instruction

❑ E.g. Copy 99H to 0-4 locations in GPR region (data memory)

Result

8/21/2024 8:28:42 AM 27
ADDWF Instruction

❑ Add WREG and file register


▪ If D = 0, result is in WREG
▪ If D = 1, result is in file register

❑ E.g. put 22H to GP RAM locations 5,6,7

8/21/2024 8:28:42 AM 28
ADDWF Instruction

❑ E.g.

8/21/2024 8:28:42 AM 29
ADDWF Instruction

❑ In D, ‘w’ of ‘f’ can be used instead of ‘0’ and ‘1’

❑ E.g.

8/21/2024 8:28:42 AM 30
In PIC 18

8/21/2024 8:28:42 AM 31
ALU instruction with FileReg and Wreg

8/21/2024 8:28:42 AM 32
File Register Instructions using WREG or FileReg
as Destination

8/21/2024 8:28:42 AM 33
COMF Instruction

❑ Complement the contents in FileReg and place in WREG or


FileReg
❑ E.g. Simple program to toggle the SFR of PORTB
continuously

8/21/2024 8:28:42 AM 34
MOVFF Instruction

❑ Copies data from one location of FileReg to another


❑ E.g.

8/21/2024 8:28:42 AM 35
Status Register

❑ Flag register to indicate the status of arithmetic operations


❑ E.g. PIC 18- 8 bit register (flag register)

8/21/2024 8:28:42 AM 36
Status Register

❑ E.g.

❑ Only some instructions affect the flag

8/21/2024 8:28:42 AM 37
PIC Data Formats

❑ Can be hexadecimal, binary, decimal, etc.


❑ Hex

❑ Binary

❑ Decimal

8/21/2024 8:28:42 AM 38
Assembling and inking a PIC Program

1. Write the program in a text editor


2. Assembler:
▪ Converts the assembly code (*.asm) to machine code
▪ Create object file and error file
3. Linker:
▪ Assembler require this step and convert one or more object files
▪ Create a HEX file, MAP file, etc.
▪ Then hex file can be downloaded to microcontroller (PIC)

❑ MPLAB IDE can be used for PIC

8/21/2024 8:28:42 AM 39
8/21/2024 8:28:42 AM 40
Assignment Q1

❑ Explain the operation of following code with detailed register


values

8/21/2024 8:28:42 AM 41
Assignment Q1

❑ Explain the operation of following code with detailed register


values

66 H = 01100110

8/21/2024 8:28:42 AM 42
Microcontrollers

Common
Types

PIC AVR 8051 ARM

8/21/2024 8:28:42 AM 43
AVR Microcontrollers

❑ Atmel AVR 8- and 32-bit Microcontrollers

Go to Microchip web
https://www.microchip.com/en-us/products/microcontrollers-and-microprocessors

8/21/2024 8:28:42 AM 44
AVR Microcontrollers

❑ AVR EA Family

Go to web https://www.microchip.com/en-us/products/microcontrollers-and-microprocessors/8-
bit-mcus/avr-mcus/avr-ea
8/21/2024 8:28:42 AM 45
AVR – E.g.

https://www.microchip.com/en-us/product/atmega164a#document-table

8/21/2024 8:28:42 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),

8/21/2024 8:28:42 AM 47
8/21/2024 8:28:42 AM 48
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

8/21/2024 8:28:42 AM 49
ATMEL: ATmega164 Architecture- Ports

❑ Configured at the beginning of a program, e.g. C code

8/21/2024 8:28:42 AM 50
Assignment Q2
Develop the hardware connection and draft code indicating control and data registers

8/21/2024 8:28 AM

51
Register Based Configuration

❑ Basic I/O ❑ Control and status

❑ ADC registers

❑ PWM ❑ Data Registers

❑ Serial Communication

❑ Special Functions

8/21/2024 8:28 AM 52
E.g. ATmega164

❑ Refer Datasheet

8/21/2024 8:28 AM 53
Assignment Q3

❑ Critically Evaluate the use of data and control registers in


ADC section of ATmega164

8/21/2024 8:28 AM 54
Microcontrollers

Common
Types

PIC AVR 8051 ARM

8/21/2024 8:28:42 AM 55
Arm® 32-bit Microcontrollers

❑ STMicroelectronics
▪ https://www.st.com/content/st_com/en/arm-32-bit-
microcontrollers.html#:~:text=The%20Arm%C2%AE%20Cortex%C2
%AE,%2Dcore%20microprocessors%20(MPUs).
❑ TI
▪ https://www.ti.com/microcontrollers-mcus-
processors/microcontrollers/arm-based-microcontrollers/overview.html

❑ Microchip 32 bit
▪ https://www.microchip.com/en-us/products/microcontrollers-and-
microprocessors/32-bit-mcus

8/21/2024 8:28:41 AM 56
Arm® 32-bit Microcontrollers

https://www.st.com/content/st_com/en/arm-32-bit-
microcontrollers.html#:~:text=The%20Arm%C2%AE%20Cortex%C2%AE,%2Dcore%
20microprocessors%20(MPUs)
8/21/2024 8:36 AM 57
Arm® 32-bit Microcontrollers

8/21/2024 8:37 AM 58
Arm® 32-bit Microcontrollers

https://www.st.com/en/microcontrollers-microprocessors/stm32h562.html
8/21/2024 8:39 AM 59
Arm® 32-bit Microcontrollers – with Cortex M
processors
❑ The Arm® Cortex®-M group of processor cores is a series of
cores optimized for power efficiency and deterministic
operation
❑ Ref: https://www.st.com/content/st_com/en/arm-32-bit-
microcontrollers.html#:~:text=The%20Arm%C2%AE%20Cortex
%C2%AE,%2Dcore%20microprocessors%20(MPUs).

8/21/2024 8:28:42 AM 60
ARM STM32 Microcontrollers

❑ The STM32 family of 32-bit microcontrollers based on the


Arm® Cortex®-M processor
❑ https://www.st.com/en/microcontrollers-
microprocessors/stm32-32-bit-arm-cortex-mcus.html

❑ E.g. STM32F103

8/21/2024 8:28:42 AM 61
ARM Cotex based Controllers
❑ The ARM Cortex-M is a group of 32-bit
RISC ARM processor cores licensed by
ARM Limited
❑ Optimized for low-cost and energy-
efficient integrated circuits,
▪ embedded in tens of billions of consumer
devices
❑ Most often the main component of
microcontroller chips, sometimes they are
embedded inside other types of chips too

https://en.wikipedia.org/wiki/ARM_Cortex-M

8/21/2024 8:56 AM 62
ARM Cortex-M3

❑ The Cortex-M3 processor is specifically developed for high-


performance, low-cost platforms for a broad range of devices
including microcontrollers, automotive body systems,
industrial control systems and wireless networking and
sensors
❑ https://developer.arm.com/Processors/Cortex-M3
❑ https://developer.arm.com/Processors#aq=%40navigationhier
archiescategories%3D%3D%22Processor%20products%22%20
AND%20%40navigationhierarchiescontenttype%3D%3D%22Pr
oduct%20Information%22&numberOfResults=48

8/21/2024 8:28:42 AM 63
Assignment Q4

❑ Compare the facilities of ARM Cotex based MCUs with


typical AVR and PIC

8/21/2024 9:21 AM 64
Systems Control

Real-time
Real Time Embedded
Embedded
Systems Systems
Scenario

65
Real-time Systems-Introduction

Nuclear Power Plants Real-time Systems


(Data need to be processed in Control of Aircrafts/Jets
timely rate)

Surgery- robot controls Airline reservations

66
Real-time Systems -Definitions

❑ Response Time: Time between the presentation of a set of


inputs to a system and the realization of the required behavior

❑ Real-time system:
System that must satisfy explicit (bounded) response-time
constraints or risk severe consequences, including failure.
OR
Real-time system is one whose logical correctness is based
on both the correctness of the outputs and their timeliness.

67
Real-time Systems-Reactive or Embedded

❑ Reactive systems are those in which scheduling is driven by


ongoing interaction with their environment,
▪ E.g. a fire-control system reacts to buttons pressed by a pilot

❑ Embedded systems are those that are found in a system that is


itself a computer
▪ E.g., a modern automobile contains many embedded computers for fuel
injection, airbag deployment, braking, climate control,
▪ household items such as televisions, stereos, washing machines, even
toys
❑ Systems with Reactive and Embedded
▪ Aircraft, spacecraft, and industrial machines

68
Real-Time Embedded Systems

❑ Embedded system is a microcomputer system embedded in a


larger system and designed for one or two dedicated services
▪ embedded as part of a complete device that often has hardware and
mechanical parts
▪ E.g. include the controllers built inside our home electrical appliances.
▪ Most embedded systems have real-time computing constraints
❑ Compared with general-purpose computing systems that
have multiple functionalities, embedded systems are often
dedicated to specific tasks
▪ E.g., Embedded airbag control system is only responsible for detecting
collision and inflating the airbag when necessary,
▪ Embedded controller in an air conditioner is only responsible for
monitoring and regulating the temperature of a room.

69
Systems Control

Real-time
Real Time Embedded
Embedded
Systems Systems
Scenario

70
Embedded Systems: non-real-time

❑ Embedded systems can be non-real-time


▪ it is correctly designed and developed if it delivers the desired functions
upon receiving external stimuli or internal triggers,
▪ with a satisfied degree of QoS (Quality of Service)
▪ E.g. are TV remote controls and calculators
❑ Non-real-time embedded systems may have time constraints
▪ if it takes more than 5 seconds for your TV remote control to send a
control signal to your TV and then the embedded device inside the TV
takes another 5 seconds to change the channel for you, you will
certainly complain
▪ consumers expect a TV to respond to remote control event within 1
second.
▪ this kind of constraints is only a measure of system performance.

71
Embedded Systems: real-time

❑ Required to compute and deliver correct results within a


specified period of time
❑ A job of a real-time system has a deadline, being it hard or
soft.
▪ If a hard deadline is missed, then the result is useless, even if it is
correct.
❑ Consider the airbag control system
▪ Airbags are generally designed to inflate in the cases of frontal impacts
in automobiles
▪ Because vehicles change speed so quickly in a crash, airbags must
inflate rapidly to reduce the risk of the occupant hitting the vehicle’s
interior.
▪ from the onset of the crash, the entire deployment and inflation process
is about 0.04 seconds, while the limit is 0.1 seconds.

72
Real-time Systems-When?

❑ E.g.-Monthly payroll calculation?-Response time may be days or


weeks
❑ Soft real-time system is one in which performance is degraded
but not destroyed by failure to meet response-time constraints
❑ Firm real-time system is one in which a few missed deadlines
will not lead to total failure, but missing more than a few may
lead to complete and catastrophic system failure
❑ Hard real-time system is one in which failure to meet a single
deadline may lead to complete and catastrophic system failure

73
Real-time Systems-Soft/Firm/Hard

74
Real-Time System Design

75
Real-Time System Design

❑ The selection of hardware and software, and evaluation of the


trade-off needed for a cost-effective solution, including dealing
with distributed computing systems
❑ Understanding the programming language(s) and the real-time
implications resulting from their translation into machine code
❑ Maximizing of system fault tolerance and reliability through
careful design
❑ Design and administration of tests, and the selection of test and
development equipment
❑ Taking advantage of open systems technology and interoperability,
e.g., LINUX
❑ Measuring and predicting response time and reducing it

76
Real-Time Systems-Applications

77
Real-time Systems: Examples

❑ Inertial Measurement system for an Aircraft


▪ Receive accelerometer reading (x, y, z) at 10 ms rate
▪ Software will determine accelerations in each direction roll, pitch and yaw
▪ Receive temperature at 1s rate
▪ TASK: Calculate actual velocity based on accelerometer, orientation, and
other factors (40 ms rate)
▪ OUTPUTS: Display true acceleration, velocity, and position

78
Real-time Systems: Examples

❑ Monitoring system for nuclear power plant (HARD RTS)


▪ E.g. Handling three events signaled by interrupts
▪ First event: any of several security points - must respond within 1 s
▪ Second event: nuclear core has reached over temperature - must be
dealt within 1 ms
▪ Third event: operators display must update in 30 times per second
▪ To avoid complete meltdown
▪ Examples of system failure
• Fukushima Japan
• Due to Earth quake +Tsunami

79
Real-time Systems: Examples

❑ Traffic lights at a four way junction


▪ Controls traffic for auto and foot
▪ Input from sensors such as push buttons, cameras
▪ Need to operate in synchronized fashion and to react for
asynchronous events
▪ Failure to operate may cause accidents

80
Real-time Systems: Examples

❑ Production lines
▪ Computer systems control all aspects
▪ Wide range of synchronous / asynchronous events
▪ Displays at operators places, etc.

Back

Back

81
Thank you

QUESTIONS

8/21/2024 8:28 AM 82

You might also like