Interrupts, Tasks and Timers

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
CSCI 4717/5717 Computer Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
INTERRUPTS PROGRAMMING
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
MICROPROCESSOR INPUT/OUTPUT
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
COMPUTER ORGANIZATIONS CSNB123 NSMS2013 Ver.1Systems and Networking1.
Microprocessors 1 MCS-51 Interrupts.
The Stack This is a special data structure: –The first item to be placed into the stack will be the last item taken out. Two basic operations: –Push: Places.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
CH10 Input/Output DDDData Transfer EEEExternal Devices IIII/O Modules PPPProgrammed I/O IIIInterrupt-Driven I/O DDDDirect Memory.
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.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
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.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
Resource Management IB Computer Science.
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Mon. Oct 2 Announcements Quiz Postponed to Wednesday – still only on 2.a + 2.b Video lecture for 2.a posted Lab 6 experiment extension You must come to.
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Timer and Interrupts.
Computer Architecture
Interrupts In 8085 and 8086.
Day 08 Processes.
Day 09 Processes.
Computer System Overview
Intro to Processes CSSE 332 Operating Systems
Chapter 3 Top Level View of Computer Function and Interconnection
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
Chapter 10 The Stack.
Advisor: Prof. Gandhi Puvvada
Advisor: Prof. Gandhi Puvvada
Computer System Overview
Processor Fundamentals
Interrupt Source: under
BIC 10503: COMPUTER ARCHITECTURE
Architectural Support for OS
Interrupts.
Chapter 10 And, Finally... The Stack
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Computer System Overview
Wireless Embedded Systems
Architectural Support for OS
COMP3221: Microprocessors and Embedded Systems
William Stallings Computer Organization and Architecture 7th Edition
Presentation transcript:

Interrupts, Tasks and Timers An embedded system have to respond to events where timing is a key consideration, eg to measure time durations to generate time-based events, which may be single or repeating to respond to external events at an appropriate speed, and which may not happen at predictable times In doing some combination of these, the system may find that it is being required to do more than one thing at the same time. The system has to be able to prioritise, and so choose which action to undertake first. So, methods to control time-based activity is required.

Interrupts, Tasks and Timers Timer – some circuit to measure time, and so initiate an event when a certain time has elapsed Interrupt – a method that allows a program to be suspended, so that the CPU can deal with a certain occurance, and once this has been dealt with, the original program can continue to execute as required. Tasks – are distinct activities that are performed, each of which has a block of code that is executed. As the number of tasks increases, we need to be able to develop techniques to handle them.

Interrupts, Tasks and Timers Polling An example of an event driven task would be when a user pushes a button – can handle this by continuously monitoring the external input. This is an example of polling Respond to button 1 Y Downside is when we need to monitor for very many events. Is button 1 pressed ? N Also, the CPU cannot perform any other tasks during a Y Respond to button 2 Is button 2 pressed ? polling routine. And all inputs are treated equally, so a response to an urgent event may be delayed until a relatively insignificant number of potential inputs are screened N Do other stuff

Interrupts, Tasks and Timers An alternative approach is to design the hardware so that an external input can effectively demand attention and stop the CPU from what it is currently doing. An example – suppose you had agreed to meet a friend at the bus station, the bus is running late and you don’t want to leave your friend waiting around once they finally arrive. Every 5 minutes, you could check on the live arrivals website of the bus station (effectively a polling type activity) or you can get your friend to call you when the bus leave the motorway and is 10 minutes away from its final destination. They you can carry on doing other things, until you get the call – this is an interrupt. In responding to interrupts, most microcontrollers follow a general pattern

Load Context, including PC Interrupts, Tasks and Timers Interrupt detected Main Program is running CPU completes the current instruction – it is about to execute a different piece of code, so must save key information so that it can continue after servicing the interrupt – this is the context. Program Counter points to where the the CPU should return to. All info is saved on the Stack – small piece of memory. Interrupt Vector points to the location of the code to service the interrupt. Complete Current Instruction Save “Context” on Stack, including Program Counter (PC) Find Interrupt Vector, and load PC Complete Current Instruction Interrupt Service Routine (ISR) starts N Once the Interrupt has been serviced, the CPU retrieves the information saved before dealing with the interrupt, and normal service is resumed. End of ISR ? Y Load Context, including PC from Stack Complete Current Instruction Main Program resumes

Interrupts on the mbed Can get more details on the mbed website /* Simple Interrupt Example*/ #include "mbed.h" InterruptIn button(p5); DigitalOut led1(LED1); DigitalOut flash(LED4); //this will cause the interrupt void ISR1(){ led1=!led1; } //the interrupt service routine int main() { button.rise(&ISR1); //interrupt routine executes on the //rising edge of the input from p5 while(1) { flash=!flash; wait(0.25); }

Interrupts, Tasks and Timers A bit more detail Most processors have a number of important interrupt mechanisms Interrupts can be prioritised – ie some are more important than others, and so if two interrupts occur at the same time, the higher priority interrupt executes first Interrupts can be masked – ie switched off if they are not needed, or are getting in the way. This can be temporary Interrupts can be nested – ie a higher priority interrupt can interrupt a lower priority. Can make programming complex iii) In the LPC1768, interrupts are controlled by the Nested Vectored Interrupt Controller (NVIC).

The NXP LPC 1768 Microcontroller Block Diagram

Interrupts, Tasks and Timers Timers We have made extensive use of the wait() function in the lab, which is very useful, but whilst we are using this function, the microcontroller cannot perform any other activity. As in previous situations, with ADC, DAC, PWM etc, it is useful to be able to let timing go on in the background, whilst the program continues to do more useful stuff. How can this be done ? The Digital Counter, which we will look at later in the course Preload 1 CLK in Interrupt generated when counter overflows Read

Interrupts, Tasks and Timers Timers Lets say clock is running at 100 MHz, and we have 32 bit counter, and can neglect propagation delay. Clock period is 10 ns. 32 bits means counts from 0 to 232-1 (4,294,967,295), and so would take 42.949 seconds. Can also generate an interrupt when a given bit is set in the counter. As we have 10 nm precision, can get very accurate timing for synchronous data transfer for example. The LPC1768 has four general purpose timers, based on the above approaches.

If you change the number of characters and record the time taken, /* Simple Timer Example*/ #include "mbed.h" Timer t; Serial pc(USBTX,USBRX); int main(){ t.start(); pc.printf("Greetings t.stop(); Earthling!\n"); pc.printf("The time taken was %f seconds\n", t.read()); } If you change the number of characters and record the time taken, can you work out what the data rate is ?

Interrupts, Tasks and Timers Switch debounce Switches are mechanical and as the contact is made and broken, the output often swings between logic states for a short time after the switch is opened or closed. This can cause all sorts of problems

Interrupts, Tasks and Timers Switch debounce If an interrupt was initiated by a user pressing a button, then could get into all sorts of problems due to this effect. Can be mitigated by detecting the first rising or falling edge, then masking any further interrupts for a given period of time, until the switch has “settled down” – can take millisecond timescales. Refer to the mbed website for additional background to understand the code on the next slide which performs switch debounce in software

/* Switch Debounce Example*/ #include "mbed.h" InterruptIn button(p10); DigitalOut led1(LED1); Timer debounce; Void toggle(void); //Interrupt on push button pin 10 //define timer debounce //function prototype int main(){ debounce.start(); //the address of the toggle function button.rise(&toggle); //is assigned to the rising edge } Void toggle(){ if(debounce.read_ms()>10) led1=!led1; debounce.reset(); //only allow toggle if //has passed 10 ms //restart timer after debounce timer toggle execution