Interrupts, Counter and Timers

Slides:



Advertisements
Similar presentations
Interrupts How to do 2 things at the same time. Need for interrupts Computers often have to deal with asynchronous events. That is to say events that.
Advertisements

Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.
م/محمد علي عطية حسين. Pin Diagram DescriptionPin Name Oscillator crystal input/external clock source input. OSC1/CLKIN Oscillator crystal output.OSC2/CLKOUT.
CSCI 4717/5717 Computer Architecture
Mark Neil - Microprocessor Course 1 Timers 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.
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.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
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,
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.
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.
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.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
EEE237 Introduction to Microprocessors Week x. SFRs.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
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.
Microprocessors A practical approach Lesson 2 Hardware description and Delays.
Working with Time: Interrupts, Counters and Timers
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Aum Amriteswaryai Namah:. SUB ROUTINES Instead of repeating same program segments at all locations, they are written and stored separately; Each such.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Lecture – 8 Interrupt 1. Outline Introduction Handling interrupt Interrupt sources Switching interrupt Peripheral interrupts Using two interrupts Conclusions.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
TIMERS.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
An Introduction to Embedded Systems, and the PIC Microcontroller Lecture 8: Interrupts The aims of this session are to explore the structure and application.
EET 2261 Unit 13 Enhanced Capture Timer
Chapter 9 PIC18 Timer Programming in Assembly
Interrupts and exceptions
Microprocessor Systems Design I
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Timer and Interrupts.
Microprocessor Systems Design I
Microprocessor Systems Design I
Computer Architecture
Interrupts In 8085 and 8086.
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessors Timers
Microprocessor Systems Design I
Chapter 3 Top Level View of Computer Function and Interconnection
EECE.3170 Microprocessor Systems Design I
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
Computer System Overview
Processor Fundamentals
전자의료시스템 및 실습 System Configuration/Interrupt
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
COMPUTER PERIPHERALS AND INTERFACES
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
EECE.3170 Microprocessor Systems Design I
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
EECE.3170 Microprocessor Systems Design I
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
Computer System Overview
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

Interrupts, Counter and Timers

Interrupts (1) Interrupt-driven I/O uses the processor’s interrupt system to “interrupt” normal program flow to allow execution of an I/O service routine An interrupt is like a hardware-initiated subroutine call

Interrupts (2) Advantages Immediate response to I/O service request Normal execution continues until it is known that I/O service is needed Disadvantages Coding complexity for interrupt service routines Extra hardware needed Processor’s interrupt system I/O device must generate an interrupt request

Basic Steps for an Interrupt (1) An interrupt cycle begins at the next fetch cycle if: Interrupts are enable (GIE = 1) Interrupt request is active (I=1) Program counter (PC) is saved on the stack PC is loaded with address of interrupt service routine (ISR) Different schemes for determining this address Fixed location 0x0004 on the PIC processor

Basic Steps for an Interrupt (2) Interrupt service routine executes Saves any registers that will be altered so that normal program flow is not disturbed Performs input and/or output operations to clear the interrupt request Restores saved registers Returns Normal execution resumes

Program Flow for an Interrupt

Example Pseudo code for an ISR ISR: save register(s) if (IN_RDY == 1) input data if (OUT_RDY == 1) output data restore register(s) return

Example Error if Registers are not Saved before Executing ISR

16F84 INTCON Register

16F84 Interrupt Structure

Outline of 16F84 Interrupt Structure

16F84 Timer/Counter

16F84 OPTION Register

Relationship between TMR0 and Prescaler

Timing Diagram of TMRO Interrupt

Determining Timer Settings Consider the “wait for 500ms” for LED problem… Fosc = 4 MHz, internal timer can be driven by Fosc/4 = 1MHz To have a 500ms interrupt on overflow interval, desired scale = 500ms/1μs = 500,000 Maximum scale provided by Timer0 is 256*256=65,536 Probably we can set up an interrupt interval shorter than 500ms, say M ms, then toggle the LED after every N interrupts, where M*N = 500. The possible value of M has constraints. It is helpful to express the needed scale in terms of its prime factors, then allocate these among the prescaler, PR and the TMR0 register. let’s try M=4 and N=125 for this example.

Initialize the Timer0 Desired scale for 4ms timing is 4ms/1μs = 4,000. Play with the math we have 32*125 =4,000 In order to get an exact 4 ms timing, we’ll need to set the timer as follows: PS2 PS1 PS0 =100 ; set prescaler to 32 TMR0 = 256-125 =131 ; initialize TMR0 T0IF = 0 ; clear timer0 interrupt flag TOIE =1 ; enable timer0 interrupt

Timer0 Initialization Code InitTmr0 bcf STATUS, RP1 ;select bank 1 bsf STATUS, RP0 movlw B’11010100’ ; set up OPTION, prescaler and timer0 resources movwf OPTION bcf STATUS, RP0 ; select bank 0 movlw D’131’ movwf TMR0 ; initialize TMR0 bcf INTCON, T0IF ; clear Timer0 interrupt flag bsf INTCON, T0IE ; enable Timer0 interrupt source bsf INTCON, GIE ; enable global interrupts return

“Wait for 500ms” --- Use Timer Since our Timer is set to overflow every 4ms, waiting 4ms really means waiting until the timer overflows. We will write an interrupt service routine to handle the timer overflow in a future class. Now we assume that in the interrupt service routine (ISR), BLNKCNT is decremented by 1 each time an overflow occurs. Waiting 500ms means waiting timer overflow 125 times, which is counted by BLNKCNT. Five00Ms movlw 124 ; initialize BLNKCNT to 124, why??? movwf BLNKCNT ; BLNKCNT is a variable wait500 btfss BLNKCNT, 7 ; wait for 00000000 to 11111111 change goto wait500 ; wait if not return ; and return if yes

Put it All Together - The Mainline Program call Initial ; Initialize PortB call InitTmr0 ; Initialize Timer0 MainLoop call Blink ; Blink LED call Five00ms ; Insert 500ms delay goto MainLoop Note: BLNKCNT will be decremented in the interrupt service routine which we will talk about in the future!

Watchdog Timer Free running counter with its own oscillator Can be enabled or disabled through special directives in the program Usually used to reset the controller if the program gets stuck or works incorrectly Programmer needs to be careful when using it so that it does not cause problems