Docsity

Class Notes on Microcontroller Applications | ECE 4510, Study notes of Microcomputers

Partial preview of the text

Download Class Notes on Microcontroller Applications | ECE 4510 and more Study notes Microcomputers in PDF only on Docsity!

ECE 4510/

Microcontroller ApplicationsMicrocontroller Applications

Ch

t

Chapter 6

Dr. Bradley J. BazuinAssociate Professor

Department of Electrical and Computer Engineering

College of Engineering and Applied SciencesCollege of Engineering and Applied Sciences

Chapter 6

p

-^

Resets

-^

Interrupts

-^

Differences between

-^

Interrupt/Reset Handlers–

Interrupt Service Routines

Cl

k

d R

t Bl

k

-^

Clock and Reset Block

-^

Low Power Modes

-^

COP watchdog timerCOP watchdog timer

Interrupts and Resets

p

-^

Interrupts–

Respond to real time hardware, “software events”, or programsoftware initiated interrupts.

-^

Software errors can cause software interrupts,usually referred to as a trap or a fault

-^

Illegal instruction, illegal memory address,etc.

-^

(advanced memory management page fault or segmentation fault)

–^

SWI is a software interrupt

-^

Transfers program execution to D-Bug

–^

Activated by: software or IRQ pin if enabled or a peripheral devicehardware interrupt if enabled.

-^

Software interrupts happen at defined times in code execution

p^

pp

–^

Hardware interrupts happen at random times during code execution

Reset

-^

The initial values of some CPU registers, flip-flops, and

g

,^

p

p ,

the control registers in I/O interface chips must beestablished in order for the computer to function properly.

The reset mechanism establishes these initial conditions for the

-^

The reset mechanism establishes these initial conditions for thecomputer system.

-^

There are at least two types of resets: power-on reset andmanual reset.–

The power-on reset establishes the initial values of registers andI/O control registers.

-^

The manual reset without power-down allows the computer to getout of most error conditions if hardware doesn’t fail.

-^

A reset is nonmaskable After a reset the CPU always

A

reset is nonmaskable. After a reset, the CPU always

starts at a defined address.

What is an Interrupt?

p

-^

An interrupt is a special event that requires the CPU to

p

p

q

stop normal program execution and perform some servicerelated to the event.–

Examples of interrupts include I/O completion, timer time-out,

p^

p^

p^

,^

illegal opcodes, arithmetic overflow, divide-by-0, etc.

-^

For most PCs, an interrupt is caused by a real-world event or bysomething going wrong.

-^

In most “real-time” signal processing almost all events driveinterrupts and interrupts are prioritized so the most importantinterrupt is worked on first.

I t

t

-^

Interrupt sources–

External: an external pin or level causes the interrupt

-^

Internal: an internal microcontroller peripheral device or CPU

ti^

th

i t

t

operation causes the interrupt

-^

Software: the swi assembly language instruction

Functions of Interrupts

p

-^

Performing time-critical operations or applications

g

p

pp

–^

Real-time data sample systems

-^

Power failure

C

di

ti

I/O

ti iti

d

ti

CPU f

-^

Coordinating I/O activities and preventing CPU frombeing tied up

-^

Providing a graceful way to handle or exit from errors

ov d

g a g ace u way to

a d e o e

t^

o

e^

o s

-^

Reminding the CPU to perform routine tasks–

Time-of-Day

-^

Health check and status

-^

Other Periodic Functions

-^

Task Switching for a multitasking operating system

g^

g^

p^

g^

y

Multi-tasking Operating Systems

g

p

g

y

-^

Modern computer systems consists of multiple application

p

y

p

pp

programs in the memory–

CPU time is divided into many short time slots of 10 to 20msMultitasking operating systems assign a program to be executed

-^

Multitasking operating systems assign a program to be executedfor one time slot

-^

At end of a time slot or when program is waiting for thecompletion of an I/O operation the operating system takes overcompletion of an I/O operation, the operating system takes overand assigns another program for execution

-^

This technique is called multi-tasking and dramaticallyimprove the CPU performance

-^

This multi-tasking technique is implemented by usingperiodic timer interrupts

periodic

timer interrupts

Basics of Interrupts (1 of 5)

p

-^

Interrupt priority

p p

y

–^

Allow multiple pending interrupt requests

-^

Resolve the order of service for multiple pending interrupts

I t

t^

k bilit

-^

Interrupt maskability–

Interrupts that can not be ignored by the CPU are callednonmaskable interrupts. (An NMI is usually the highest priorityinterrupt).

-^

Interrupts that can be ignored by the CPU are called maskableinterrupts.

-^

A maskable interrupt must be enabled before it can interrupt theCPU and must be disabled when it is not allowed to interrupt theCPU.

-^

An interrupt is enabled by setting an enable/disable bit or flag.

Basics of Interrupts (3 of 5)

p

-^

Interrupt vector–

Starting address of the interrupt service routine

-^

Interrupt vector table

A table where all interrupt vectors are stored

-^

A table where all interrupt vectors are stored

-^

Methods of determining interrupt vectors–

Predefined locations (Microchip PIC18, 8051 variants)

-^

Fetching the vector from a predefined memory location (HCS12)

-^

Executing an interrupt acknowledge cycle to fetch a vector numberin order to locate the interrupt vector (68000 and x86 families)

p^

(^

Basics of Interrupts (4 of 5)

p

-^

Steps required for interrupt programming

p

q

p p

g

g

–^

Step 1. Initializing the interrupt vector table

-^

Step 2. Writing the interrupt service routineStep 3 Enabling the desired interrupts at the appropriate location

-^

Step 3. Enabling the desired interrupts at the appropriate locationin the system code.

-^

The overhead of interrupts–

Saving and restoring of CPU status and other registers. (HCS12needs to save all CPU registers).

-^

Execution time of instructions of the interrupt service routine.

-^

Overhead time required to enter and exit an ISR

–^

The execution of the return-from-interrupt (RTI) instruction thatwill restore all the CPU registers.

g

Major Interrupt Issues

j

p

-^

Maskable Interrupts

p

-^

Interrupt Priority

-^

Interrupt Service

-^

Interrupt Vector

-^

Interrupt Programming

-^

Interrupt Overhead

Maskable Interrupt Operation

p

p

-^

Program can request the CPU to service or ignore a

g

q

g

maskable interrupt by setting or clearing an enable bit–

When an interrupt is enabled, the CPU will respond to itWhen an interrupt is disabled the CPU will ignore it

-^

When an interrupt is disabled, the CPU will ignore it

-^

An interrupt is said to be pending when active but not yetserviced by the CPU

-^

Pending interrupt may or may not be serviced dependingon whether or not they have priority and are enabledC

ll

id

l b l ( ll

k bl

-^

Computer system normally provides a global (all maskableinterrupts) and local interrupt masking capability

Enabling the XIRQ pin Interrupt

g

Q p

p

b

b

b

b

b

b

b

b

Th

CCR

S^

X^

H^

I^

N^

Z^

V^

C^

Th

e CCR

-^

After Reset, the X status bit is set to 1

-^

To allow XIRQ based “non-maskable interrupts” set the bit

Q

p

to 0 ANDCC #$BF

AND CCR

i h 1011 1111

$BF

ANDCC #$BF

;AND CCR with 1011 1111 or $BF

Also needed: interrupt vector and XIRQ ISR

XIRQ and the CCR X Bit

Q

•^

When an XIRQ interrupt occurs after non-maskable interrupts areenabled, both the X bit and the I bit are set automatically to preventother interrupts from being recognized during the interrupt serviceroutine.–

The mask bits are set after the registers are pushed onto the stacked but

-^

The mask bits are set after the registers are pushed onto the stacked, butbefore the interrupt vector is fetched.

-^

Normally, a return-from-interrupt (RTI) instruction at the end of theinterrupt service routine restores register values that were present beforeth

i t

t^

d

the interrupt occurred.

•^

Since the CCR is stacked before the X bit is set, the RTI normallyclears the X bit, and thus re-enables non-maskable interrupts.–

It is possible to manipulate the stacked value of X so that X is set after anIt is possible to manipulate the stacked value of X so that X is set after anRTI, but there is no software method to reset X (and disable XIRQ) onceX has been cleared.