V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,

Slides:



Advertisements
Similar presentations
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
I/O Unit.
68HC11 Polling and Interrupts
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Introduction An interrupt is an event which informs the CPU that its service (action) is needed. Sources of interrupts: internal fault (e.g.. divide by.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
GURSHARAN SINGH TATLA PIN DIAGRAM OF 8085 GURSHARAN SINGH TATLA
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
NS Training Hardware. System Controller Module.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
UNIT 8 Keypad Interface Contact Closure Counter Exceptions (Interrupts and Reset)
Ch. 9 Interrupt Programming and Real-Time Sysstems From Valvano’s Introduction to Embedded Systems.
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
System Clocks.
Interrupts, Counter and Timers. Interrupts (1) Interrupt-driven I/O uses the processor’s interrupt system to “interrupt” normal program flow to allow.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
MICROPROCESSOR INPUT/OUTPUT
CoE3DJ4 Digital Systems Design Chapter 6: Interrupts.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Interrupt.
I/O Interfacing A lot of handshaking is required between the CPU and most I/O devices. All I/O devices operate asynchronously with respect to the CPU.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
Microprocessors 1 MCS-51 Interrupts.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Chapter 5 - Interrupts.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Polled IO versus Interrupt Driven IO
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
The 8051 Microcontroller Chapter 6 INTERRUPTS. 2/29 Interrupt is the occurrence of a condition an event that causes a temporary suspension of a program.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
TIMERS.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Computer System Structures Interrupts
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Timer and Interrupts.
UNIT – Microcontroller.
Computer Architecture
Interrupts, Counter and Timers
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
* * * * * * * 8051 Interrupts Programming.
Interrupts, Tasks and Timers
Computer System Overview
Interrupt Source: under
Interrupts.
Interrupt.
PIC18 Interrupt Programming
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient, processor wastes time checking for ready condition –Either checks too often or not often enough Interrupt Driven IO – IO device interrupts processor when it is ready for data transfer –Processor can be doing other tasks while waiting for last data transfer to complete – very efficient. –All IO in modern computers is interrupt driven.

V 0.92 PIC24  C Interrupt Operation The normal program flow (main) is referred to as the foreground code. The interrupt service routine (ISR) is referred to as the background code. Copyright Delmar Cengage Learning All Rights Reserved. From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.

V 0.93 Vector Table Copyright Delmar Cengage Learning All Rights Reserved. From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”. This contains the starting address of the ISR for each interrupt source.

V 0.94 Copyright Delmar Cengage Learning All Rights Reserved. From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”. Interrupt Sources Serial data has arrived CNx Pin has changed state

V 0.95 Interrupt Priorities An interrupt can be assigned a priority from 0 to 7. Normal instruction execution is priority 0. An interrupt MUST have a higher priority than 0 to interrupt normal execution. Assigning a priority of 0 to an interrupt masks (disables) than interrupt. An interrupt with a higher priority can interrupt a currently executing ISR with a lower priority. If simultaneous interrupts of the SAME priority occur, then the interrupt with the LOWER VECTOR NUMBER (is first in the interrupt vector table) has the higher natural priority. For example, the INT0 interrupt has a higher natural priority than INT1.

V 0.96 Enabling an Interrupt Each interrupt source generally has FLAG bit, PRIORITY bits, and an ENBLE bit. The flag bit is set whenever the flag condition is true, which varies by the interrupt. The priority bits set the interrupt priority. The enable bit must be ‘1’ for the ISR to be executed. (NOTE: the enable bit does not have to be a ‘1’ for the flag bit to be set!!!!!). One of the things that must be done by the ISR is to clear the flag bit, or else the ISR will get stuck in an infinite loop. By default, all priority bits and enable bits are ‘0’, so interrupt ISRs are disabled from execution.

V 0.97 Traps vs. Interrupts A Trap is a special type of interrupt, is non-maskable, has higher priority than normal interrupts. Traps are always enabled! Hard trap: CPU stops after instruction at which trap occurs Soft trap: CPU continues executing instructions as trap is sampled and acknowledged Trap CategoryPriorityFlag(s) Oscillator FailureHard14_OSCFAIL (oscillator fail, INTCON1 ), _CF (clock fail, OSSCON ) Address ErrorHard13_ADDRERR (address error, INTCON1 ) Stack ErrorSoft12_STKERR (stack error, INTCON1 ) Math ErrorSoft11_MATHERR (math error, INTCON1 ) DMAC ErrorSoft10_DMACERR (DMA conflict write, INTCON1 )

V 0.98 Interrupt Vectors in Memory The compiler uses the _DefaultInterrrupt function as the default ISR. If an interrupt is triggered, and the ISR is the _DefaultInterrrupt, then the user did not expect the interrupt to occur. This means the interrupt is ‘unhandled’. We have written our own _DefaultInterrrupt that prints diagnostic information since this is an unexpected occurrence.

V 0.99 Our _DefaultInterrupt ISR Used for all interrupts when you do not provide an ISR. Our version saves the interrupt source, does a sofware reset, then interrupt source is printed.

V Output from the _DefaultInterrupt ISR

V Change Notification Interrupts When enabled, triggers an interrupt when a change occurs on a pin.

V Use Change Notification to wake from Sleep

V Remappable Pins Some inputs/outputs for internal modules must be mapped to RPx pins (remappable pins) if they are to be used. Input NameFunction Example Assignment Namemapping inputs to RPn External Interrupt 1INT1_INT1R = n; External Interrupt 2INT2_INT2R = n; Timer2 Ext. ClockT2CK_T2CKR = n; Timer3 Ext. ClockT3CK_T3CKR = n; Input Capture 1IC1_IC1R = n; Input Capture 2IC2_IC2R = n; UART1 ReceiveU1RX_U1RXR = n; UART1 Clr To SendU1CTS_U1CTSR = n; SPI1 Data InputSDI1_SDI1R = n; SPI1 Clock InputSCK1_SCK1R = n; SPI1 Slave Sel. InputSS1_SS1R = n;

V Remappable Pins (cont.) Mapping outputs to RPx pins. Output NameFunctionRPnR Example NameValueAssignment Default Port PinNULL0_RPnR = 0; UART1 TransmitU1TX3_RPnR = 3; UART1 Rdy. To SendU1RTS4_RPnR = 4; SPI1 Data OutputSDO17_RPnR = 7; SPI1 Clock OutputSCK1OUT8_RPnR = 8; SPI1 Slave Sel. Out.SS1OUT9_RPnR = 9; Output Compare 1OC118_RPnR = 18; Output Compare 2OC219_RPnR = 19;

V Remapping Macros Contained in pic24_ports.h: CONFIG_U1RX_TO_RP(pin) CONFIG_U1TX_TO_RP(pin) etc.. Example Usage: CONFIG_U1RX_TO_RP(10); //UART1 RX to RP10 CONFIG_U1TX_TO_RP(11); //UART1 TX to RP11

V INT2, INT1, INT0 Interrupts These are input interrupt sources (INTx) that can be configured to be rising edge triggered or falling-edge triggered by using an associated INTxEP bit (‘1’ is falling edge, ‘0’ is rising edge’. On the PIC24HJ32GP202, INT1 and INT2 must be brought out to remappable pins (RPx); INT0 is assigned a fixed pin location.

V Use INT1 to wake from Sleep mode //Interrupt Service Routine for INT1 void _ISRFAST _INT1Interrupt (void) { _INT1IF = 0; //clear the interrupt bit } /// Switch1 configuration, use RB13 inline void CONFIG_SW1() { CONFIG_RB13_AS_DIG_INPUT(); //use RB13 for switch input ENABLE_RB13_PULLUP(); //enable the pullup DELAY_US(1); // Wait for pull-up } int main (void) { configBasic(HELLO_MSG); /** Configure the switch ***********/ CONFIG_SW1(); CONFIG_INT1_TO_RP(13); //map INT1 to RP13 /** Configure INT1 interrupt */ _INT1IF = 0; //Clear the interrupt flag _INT1IP = 2; //Choose a priority _INT1EP = 1; //negative edge triggerred _INT1IE = 1; //enable INT1 interrupt while(1) { outString("Entering Sleep mode, press button to wake.\n"); //finish sending characters before sleeping WAIT_UNTIL_TRANSMIT_COMPLETE_UART1(); SLEEP(); //macro for asm("pwrsav #0") }

V Timers Recall that a Timer is just a counter. Time can be converted from elapsed Timer Ticks (Ticks) by multiplying by the clock period (Ttmr) of the timer: Time = Ticks x Ttmr If a timer is a 16-bit timer, and it is clocked at the FCY = 40 MHz, then will count from 0x0000 to 0xFFFF (65536 ticks) in: Time = x (1/40 MHz) = x 25 ns = ns = us = ms

V Timer 2 Block Diagram Copyright Delmar Cengage Learning All Rights Reserved. From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.

V T2IF Period The T2IF flag is set at the following period (T t2if ): T t2if = (PR2+1) x PRE x Tcy = (PR2+1) x PRE/Fcy Observe that because Timer2 is a 16-bit timer, if PR2 is its maximum value of 0xFFFF (65535), and the prescaler is ‘1’, this is just: T t2if = x 1/Fcy We typically want to solve for Tt2if, given a PRE value: PR2 = (T t2if x Fcy /PRE ) − 1

V Example T2IF Periods PR2/PRE Values for T t2if = 15 ms, Fcy = 40 MHz PRE=1PRE=8PRE=64PRE=256 PR (invalid) The PR2 for PRE=1, PRE=8 are invalid because they are greater than (PR2 is a 16-bit register). Configuring Timer2 to interrupt every T t2if period is called a PERIODIC INTERRUPT.

V Timer2 Control Register Copyright Delmar Cengage Learning All Rights Reserved. From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”. include\pic24_timer.h excerpts: /*T2CON: TIMER2 CONTROL REGISTER*/ #define T2_ON 0x8000 #define T2_OFF 0x0000 #define T2_IDLE_STOP 0x2000 #define T2_IDLE_CON 0x0000 #define T2_GATE_ON 0x0040 #define T2_GATE_OFF 0x0000 #define T2_PS_1_1 0x0000 #define T2_PS_1_8 0x0010 #define T2_PS_1_64 0x0020 #define T2_PS_1_256 0x0030 #define T2_32BIT_MODE_ON 0x0008 #define T2_32BIT_MODE_OFF 0x0000 #define T2_SOURCE_EXT 0x0002 #define T2_SOURCE_INT 0x0000

V Square Wave Generation Timer2 configured to generate an interrupt every 15 ms. An output pin is toggled in the ISR, so square wave has period of 30 ms. Copyright Delmar Cengage Learning All Rights Reserved. From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.

V Copyright Delmar Cengage Learning All Rights Reserved. From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”. Switch Sampling A Timer2 periodic Timer interrupt is used to sample the switch.

V Copyright Delmar Cengage Learning All Rights Reserved. From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”. Switch Sampling (cont.)

V Dividing Work between the ISR and main() There are usually multiple ways to divide work between the ISR and main(). The ‘right’ choice is the one that services the I/O event in a timely manner, and there can be more than right choice. Golden Rules: The ISR should do its work as fast as possible. Do not put long software delays into an ISR. An ISR should never wait for I/O, the I/O event should trigger the ISR! An ISR is never called as a subroutine.