CPE 509 Lecture Note Power Point Presentation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 43

CPE 509

Introduction
to

Embedded
System

Department
1
of Computer Engineering
University of Maiduguri
CPE 509: EMBEDDED SYSTEMS

 Introduction
 Embedded microcontroller – timers, ADC,

DACs (I/Os)
 Embedded microprocessors – memory

management, Disk controllers (I/Os)


 Interaction of ES with environment

 Embedded control systems

2
INTRODUCTION:
 Embedded systems are either electronic/ electrical/
electromechanical system that contain a
microprocessor or microcontroller but are not thought
of as a computer because the computer is embedded
in the system. Embedded systems can be found in lot
of things ranging from household materials like baby
toys, mini-robots, rice cookers, bread toasters, food
processor, television and mobile phones to industrial
appliances like process controllers, power generating
stations, manufacturing industries, automobiles,
instrumentation, network routers, telecommunication
systems, air-traffic controllers, avionic system,
defense systems, medical equipments and many
more. Small in size, cheaper cost and low power are 3
for ES while computer deals in processing power.
CHARACTERISTICS OF ES

 Cost sensitivity and diversity


 Application specific software and hardware

 Wide range of skill

4
CLASSIFICATION OF EMBEDDED
SYSTEMS
 Embedded systems are classified into two
namely: embedded micro-controller and
embedded microprocessor. The first small
systems requiring a microprocessor is
deployed in use for small systems requiring
8 to 16 bit bus and usually applied for single
operation. On the other hand, embedded
microprocessor are used to refer to
microprocessors employed in large systems
of large than 16 bits bus and mainly for
industrial use with many things to control.
5
µcomputer
 This is made up of µprocessor, memory
devices, I/O devices and the bus system

6
TYPICAL MICROCOMPUTER
 µprocessor: This is called the central processing Unit (CPU). It
controls the system and processes data. When used in such a
way that it only performs one function at a time it is called
µprocessor. Moreso, if it performs only one function with the
capacity for change and made on a single chip, it is called
“single chip µcontroller”. However, it is can perform several
functions but one at a time, it is called “Expanded mode
µcontroller.
 Memory devices: these stores data, address of data, the
results of processing and the instruction to be performed on the
data called CPU programs. Basically memory are RAM and ROM
but could also include external storage.
 Input/output devices: These provides the interface between
the µprocessor and the outside world. It includes: keyboard,
monitor, mouse, speaker, µphone e.t.c.
 The bus system: This is divided into two namely; the data bus
and the address bus. They provide for flexible interconnection in 7
between the other three units of the µcomputer.
SUMMARY

8
PIC INSTRUCTION SET
 Simple instruction set: About 35 instructions
 Instruction set grouped into 3 categories:

 Byte oriented operates


 Bit oriented
 Literal and control
 Instruction; 14 bit (mid-range)

 All instructions take are cycle unless

continued test is true or PC is changed as a


result of instruction.

9
10
11
12
INSTRUCTIONS

 Byte oriented operation


 Arithmetic and logical operations
 Data movement
 Examples.
add wf f, d
Add content of w with register f, if d=0 store the result in w otherwise
store in file registers f; e.g add wf 0 x 20 location, 0 destination
 clrf f
Content of file register f are clears and Z bit (STATUS) is set;
 e.g c/rf 0 x 30 location
 movwf f
 move data from working register w to register f e.g
 mov wf 0 x 04
 decfsz f, d conditional branching
Decrement register f, place result in f or w depending on value of d; skip
the next instruction of result is zero, e.g decfsz 0 x 21, 1
 Decf f , d
decrement f, place result depending on the value of d, effects z flags e.g 13
decf 0 x 30, 0
 Literal Operations
 Immediate addressing mode
 Example
addlw k
Add literal k to register w e.g
addlw 0 x 05
 Movlw k
Move literal k into register w e.g
. movlw 0 x 21
 Move instruction for
 A constant being written in W register (MOVLW)
 For data to be copied from W register unto RAM and data from
RAM to be copied unto W register (or the same RAM location, at
which point only the status of Z flag changes).
 Instruction CLRF writes constant O in ‘f’ register and CLRW
writes constant O in register W.
14
 SWAPF instruction exchanges places of the 4-bit nibble
field inside a register
ARITHMETIC AND LOGICAL OPERATIONS
 PIC like many µcontroller supports only subtraction and
addition
 Flags C, DC, and Z are set depending on a result of addition
and subtraction.
 Since subtraction is performed like addition of a negative
value, C flag is inverse following a subtraction.
 Logic unit in PIC has capacity of performing operation
AND, OR, EX-OR, complementing (COMF) and rotation
(RLF and RRF)
 Rotate the register contents through flag C
 Bits move by one bit to the left (towards bit 7) or to the right
(towards bit 0).
 Bits which “comes out” of register is written in flag C, and
value of C flag is written in a bit on the “opposite side” of
the register.
 Example: rrf f, F(W)
15
Copy f in F or W, rotate F or W right through the carry
bit
16
17
DIRECT PROGRAM FLOW
 GOTO, call and RETURN instructions like other
µcontrollers
 Call and return instruction use hardware stock,
independent of internal RAM and limited to eight levels
 RETLEWK instruction is identical with RETURN
instructions, except that before coming back from a
subprogram a constant defined by instruction operand
‘K’ is written in w register.

EXAMPLES
 Decrement a 16 bit counter
 upper byte of the counter COUNTH and lower byte COUNTL
 movf COUNTL, F; set Z if lower byte = 0
 btfsc STATUS, Z ; if so, decrement COUNTH
 decf COUNTH, F
 decf COUNTH, F 18
decf COUNTL, F : decrement COUNTL
19
20
21
 Using Relative Addressing
Table Loop-up :
mor/w 0 x 04 : Load w with 4
Call table : call the table subroutine
movwf result : store the result form the
table

 Table addwf PCL, W : Jump to (current PCL)


+w
ret/w 0 x 00 : return with 0 x 00 in w
ret/w 0 x 23 : return with 0 x 23 in w
ret/w 0 x 33 : etc
22
ret/w 0 x 88
THE PIC FAMILY PERIPHERALS
 Common peripheral in PIC are:
 Tri-state (floatable) digital 1/10 pins
 Analog to Digital converters (ADC)
 Serial communications: UART (RS-232C), SPI, I2 C, CAN
 Pulse width modulation (PWM)
 Timers and counters
 Watchdog timers
 A Review of Interrupts
 An interrupt is any service request that causes the CPU
to stop its current execution stream and to execute an
instruction stream that serves the interrupt.
 When the CPU Finishes servicing the interrupt, it
returns to the original execution stream at the point
where it left off.
 Interrupt driven I/O can be used for interfacing with on
chip peripherals. 23
24
 Interrupt Management

Use of register INTCON: Status and control


 Bit 7: Global interrupt enable
 Enables (if set) all unmasked interrupts or disables all
interrupts
 Bits 6,4,3: for enabling peripherals timer O, external interrupt,
port B change, interrupt respectively
 Bits 2,1,0: Timer 0, INT, port change interrupt flag
respectively.
 Flags bits get set when interrupts occurs regardless of the
value of enable bit

 Interrupts are managed using some registers like INTCON


 Maskable interrupts: is the capability to enable or disable
interrupts
 Vector interrupts: means the processor starts executing
25
the interrupt command from a fixed address. PIC uses
vector interrupt in the most
PERIPHERAL INTERRUPTS

 Managed using PIE and PIR registers


 PIE registers contains bits for enabling

interrupts from individuals peripherals


 PIR registers contain flag bits for individual

peripheral interrupts
 Bit oriented instructions can be used to

examine and/or manipulate control and


status registers

26
INTERRUPTS PROCESSING
 When interrupt is responded to
 GIE bit is cleared to disable other interrupts
 PC is pushed into stack
 PC is loaded with 0004h
 Save STATUS and W register in temporary
memory location.
 In the ISR, source of interrupt is determined by
polling the interrupt flag bit.
 Return from interrupt instruction (retfic) exist
ISR, set GIE bit to allow pending interrupt to
execute.

27
INTERRUPT CONSTRAINTS

 Each interrupt source is characterized by:


 Minimum time interval between interrupts from
the same source.
 Maximum time it takes the CPU to execute
interrupt sources handler

 Servicing of interrupt must not delayed


beyond the limit imposed by the timing
requirement of the source.

28
CRITICAL REGION

 A critical region is a sequence of instructions


that must be protected from an intervening
interrupt or produce erroneous output
 In PIC this problem is handled by
 Single cycle read-modify-write instructions
 xorwf PORTD, F
 Port D data read, XORed with W and written back to

port D
 Disabling interrupts by clearing GIE bit for the
required set of instructions.
29
 PIC peripherals Digital I/O

 All PIC have digital I/O pins, called “’ports’


 The 8pins 12C508 has 1 port with 4 digital I/O
pins
 The 68 pins 17C766 has 9 ports with 66 digital
I/O pins
 Ports are used to control and monitor
external devices
 Ports have 2 control registers
 TRISX sets whether each pin is an input or
output\
 PORTX sets their output bit levels
 Most pins have 25ma source sink (directly 30
drives LEDs)
 Managing Port Read/Write

 BCF/BSF PORTn does the following:


 Reads in the PORT byte
 Clears/set the bit
 Write the whole byte back
 If external input pulls a different output pin low or
high during the READ, the read in value will not be
what your expert- WORSE, the WRITE will
permanently change it that way.
 Solution: use shadowed I/O (e.g.: set PORT A bit
O)
 bsf _PORT A, O
 movf _ Port A, W 31
 movwf PORTA
PIC peripherals: Timers
 Available in all PICs

 14 bits cores may generate interrupts on timers overflow.

 Some 8 bits, some 16bits some have prescales and/or

postscalers
 Can use oriented pins as clock in/clock out

PIC Timer/Timer O
 8 bit timer/counter with prescaler

 Readable and writable

 8-bit software programmable prescaler

 Prescaler can divide the counter input by 2, 4, 8,


16…..256
 Internal or external clock set

 External clock connected to bit 4 of port A


 Interrupt on overflow from Ox FF to O xOO
32
 Edge select for external clock
 PIC Timer / Timer 1

 I6-bit timer or counter


 Interrupt on overflow
 Readable and writeable
 Different operating modes
 External crystal can be used
 Programmable prescaler

 Timer1: Operating Modes

 Synchronized Timer
 Increment every instruction cycle
 Synchronized counter
 Timer increments on rising edge of external clock
 External clock is synchronized with internal phase clock
 Asynchronous counter 33
 Timer increments independents of internal phase clock

PIC Timer: Timer 2
 Readable and writeable

 8-bit counter/timer with prescaler and postscaler

 Interrupt on overflow

Watchdog Timer
 Free running on chip RC oscillator which does not

required any external component.


 A WDT time-out generate a device reset

 In sleep mode a WDT time-out causes the device to

wake –up
 To avoid unintended device reset, postscaler has to

be changed after clearing watchdog timer (WDT).


 WDT is enabled/disabled by a device configurative 34

bit.
 PIC Peripherals: CCP Modules- for Control App
 Each module contains a 16 bit register which can operate
as 16 bit capture, 16-bit compare or as 10-bit PWM
master-slave duty cycle register.
 Capture counts external pin changes
 Compare will interrupt when the time equals the value in
a compare register.

 Capture
 Capture mode records value of timer when events like
rising edge or falling edge occurs in pin CCPx
 When capture is made, interrupt request flag bit is set.

 Compare
 Content of register is compared with timer 1 register pair
value 35
 When match occurs, voltage level at CPPx pin is changed
depending on the value of control bits.
PWM
 Pulse width modulation

 Duty cycle often expressed as a percentage of the period

 Average DC voltage will be approximately the same % of the

“ON” voltage
 Typical uses:

 Intensity control
 Motor control
 Temperature control

PWM Mode
 In pulse width modulation mode, CCPX pin produces up to a 10-

bit resolution PWM output.


 Since CCPx pin is multiplexed with the port data latch, the
corresponding TRIS bit must be cleared.
 Coupled with timer 2 for producing output

 Period and duty cycle of timer 2 output manipulated for


36
obtaining desired PWM waveform.

PWM: Set Up

 Steps required for setting up PWM are:


 Establish the PWM period by writing to PR2 register
 Establish the PWM duty cycle by writing onto CCPRxL
8 CCPxCON<5:4> bit.
 Make CCPx pin an output
 Establish TMR2 prescalers value and enable timer by
writing to T2CON
 Configure CCP module for PWM operation

37
38
PIC peripheral: ADC
 Converts an analog input signal to 8-bit/10 –bit digital
value
 Generates results via successive approximation
 Inputs analog channels, conversion clock and analog
reference voltage is software selectable
 Can operate even while the device is in sleep mode
 Can generate an interrupt on ADC conversion done
 Result written on to ADRES register

Synchronous Serial Port


 Serial interface module for communication with other

devices or micro-controllers
 Module operates in one of two modes:

 Serial peripheral interface (SPI)


39

 Inter-integrated circuit (I2C)


MORE PIC PERIPHERALS

 Some devices have 8-bit parallel slave port


 Multiplexed onto one of devices I/O
 For interfacing with *-bit peripherals or µprocessors
 USART (universal synchronous and asynchronous
receiver transmitted): can be configured as a full
duplex channel for communication with or peripheral
devices like CRT
 LCD module
 Generate timing control to drive LCD panel
 Also provides control of pixel data
 EEPROM data memory
 readable and writeable under normal operations
 not mapped directly in register file space
 indirectly accessed using SFR.

40
 In-circuit programmer
Serial in-circuit programming support
 PIC: Examples
 Low End: 12C508
 8pin package (DIP)
 12 bit core-33 instructions
 1µsec instruction time (Tclk = 4MHz)
 512 12bit program memory
 25 8bit data memory or register (File register)
 2 level hardware stack (no interrupts)
 5 GPIO pins, 1 input only (25MA source/sink)
 Features: internal pull-ups, wakeup on pin change, internal oscillation
 Peripherals: Timer, and watchdog timer.

 Mid Range 16F876


 28pin package (DIP)
 14bit core-35 instructions
 200nsec instruction time (Tclk = 20MHz)
 8,092 14 bit FLASH program memory
 368 8bit EEPROM (nonvolatile) data register
 8 level hardware stack (interrupts enabled)
 22 GPIO (20mA source/25mA 7sink)
 Peripherals: 5cl 10 bit ADC, USART/12C/SPI, 16and 8 bit timer 41
 Features: Brown out detect, In-circuit Debugger (ICD)
 Brown detect- Ability to detect voltage fluctuation and go back to predetermined state.
42
43

You might also like