Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CMP3006 Embedded Systems Programming Lecture 5: Interrupts & Analog Input (ADC), Lecture notes of Embedded Systems

its for cmp3006 and 3010 some of the university notes it will be help

Typology: Lecture notes

2022/2023

Uploaded on 06/17/2023

fahd-2
fahd-2 ๐Ÿ‡น๐Ÿ‡ท

6 documents

1 / 32

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMP3006
EMBEDDED
SYSTEMS
PROGRAMMING
LECTURE 5 INT E RRUPTS & ANALOG
INPUT (ADC)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download CMP3006 Embedded Systems Programming Lecture 5: Interrupts & Analog Input (ADC) and more Lecture notes Embedded Systems in PDF only on Docsity!

CMP

EMBEDDED

SYSTEMS

PROGRAMMING

LECTURE 5 INTERRUPTS & ANALOG

INPUT (ADC)

Atmega 328 Pinout

Interrupts

Allow program to respond to events when they occur

Allow program to ignore events until the occur

External events e.g.:

UART ready with/for next character

Signal change on pin

๏ƒ˜ Action depends on context

of edges arrived on pin

Internal events e.g.:

Power failure

Arithmetic exception

Timer โ€œtickโ€

ATmega328 Interrupts

The ATmega328P provides support for 25 different interrupt sources. These

interrupts and the separate Reset Vector each have a separate program vector

located at the lowest addresses in the Flash program memory space.

The complete list of vectors is shown in Table 11-6 โ€œReset and Interrupt Vectors

in ATMega328P. Each Interrupt Vector occupies two instruction words.

The list also determines the priority levels of the different interrupts. The lower

the address the higher is the priority level.

RESET has the highest priority, and next is INT0 โ€“ the External Interrupt Request 0.

ATmega328 Interrupts

ATmega328 Interrupts

Interrupts

Type 1 โ€“ Event is remembered when interrupt is disabled

If interrupt is not enabled, flag is set

๏ƒ˜ When interrupt is enabled again, interrupt takes place, and flag is reset

Type 2 โ€“ Event is not remembered when interrupt is disabled

Signal level causes interrupt

If level occurs when interrupt is enabled, interrupt takes place

If interrupt is not enabled, and level goes away before the interrupt is enabled, nothing

happens

Interrupt Vectors

Interrupt Vector

Table in memory containing the first instruction of each

interrupt handler

Typically at program address 0

Interrupts

Global interrupt enable

Bit in SREG

Allows all interrupts to be disabled with one bit

sei() โ€“ set the bit

cli() โ€“ clear the bit

Interrupt priority is determined by order in table

Lower addresses have higher priority

ISR(vector) โ€“ Interrupt routine definition

reti() โ€“ return from interrupt

automatically generated for ISR

External Interrupts

Monitors changes in signals on pins

What causes an interrupt can be configured by setting control registers

appropriately

Pins:

๏ƒ˜ INT0 and INT1 โ€“ range of event options

๏ƒ˜ INT0 โ€“ PORTD [2]

๏ƒ˜ INT1 โ€“ PORTD [3]

PCINT[23:0] โ€“ any signal change (toggle)

๏ƒ˜ PCINT[7:0] โ€“ PORT B [7:0]

๏ƒ˜ PCINT[14:8] โ€“ PORT C [6:0]

๏ƒ˜ PCINT[23:16] โ€“ PORT D [7:0]

Pulses on inputs must be slower than I/O clock rate

INT0 and INT

External Interrupt Mask Register

If INT# bit is set (and the SREG I-bit is set), then interrupts are enabled on pin INT#

External Interrupt Flag Register

Interrupt flag bit is set when a change triggers an interrupt request

Flag is cleared automatically when interrupt routine is executed

Flag can be cleared by writing a 1 to it

Arduino Platform Support for

External Interrupts

attachInterrupt(interrupt, function, mode)

interrupt: 0 or 1

function : interrupt function to call

mode: LOW, CHANGE, RISING, FALLING

detachInterrupt(interrupt)

interrupts( ) โ€“ Enable interrupts : sei( )

noInterrupts( ) โ€“ Disable interrupts : cli( )