Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.

Slides:



Advertisements
Similar presentations
Assembler Exercises Chapters 4-6 Dr. Gheith Abandah1.
Advertisements

Introduction to PIC Microcontrollers
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.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006.
م/محمد علي عطية حسين. Pin Diagram DescriptionPin Name Oscillator crystal input/external clock source input. OSC1/CLKIN Oscillator crystal output.OSC2/CLKOUT.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
68HC11 Polling and Interrupts
Eng. Husam Alzaq The Islamic Uni. Of Gaza
SENIOR PROJECT PRESENTATION REMOTE CONTROL CAR MURAT DİNÇER.
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 
Taking timing further Chapter Nine 9.1 – 9.8 Dr. Gheith Abandah1.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 30: PIC data memory.
The 8051 Microcontroller and Embedded Systems
Today’s Lecture List the Timers of PIC18 and their associated registers Describe the various modes of the PIC18 timers Program the PIC18 timers in Assembly.
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
System Clocks.
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
Interrupts, Counter and Timers. Interrupts (1) Interrupt-driven I/O uses the processor’s interrupt system to “interrupt” normal program flow to allow.
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
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.
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.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
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.
Department of Electronic & Electrical Engineering Template program. Input / Output (IO) ● Template program. ● Introduction to IO ● Setting up for IO ●
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
Working with Time: Interrupts, Counters and Timers
PIC16F887.
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
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.
Aum Amriteswaryai Namah:. SUB ROUTINES Instead of repeating same program segments at all locations, they are written and stored separately; Each such.
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
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.
5-2-1 PIC microcontroller. Learning objectives To aid revision, areas that are examinable are identified by a vertical line in the left margin. Where.
I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
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.
16F877A.
Chapter 9 PIC18 Timer Programming in Assembly
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Interrupts, Counter and Timers
Microprocessor Systems Design I
Microprocessors Timers
PIC 16F877.
EE Embedded Systems Fall 2015
The PIC uCs PIC Microcontroller and Embedded Systems Muhammad Ali Mazidi, Rolin McKinlay and Danny Causey Eng. Husam Alzaq The Islamic Uni. Of Gaza 11-1.
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
PIC18 Interrupt Programming
EECE.3170 Microprocessor Systems Design I
PIC18 Interrupt Programming
Presentation transcript:

Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1

Outline Interrupts – Interrupt Structures – Interrupt Demonstration Program – Dealing with Multiple Interrupt Sources – Context Saving Counters and Timers Watchdog Timer Sleep Mode Dr. Gheith Abandah2

General Interrupt Structure Dr. Gheith Abandah3

The 16F84A Interrupt Sources Dr. Gheith Abandah4 1.External interrupt. It shares a pin with Port B, bit 0. It is edge triggered. 2.Timer 0 overflow. It occurs when the timers 8-bit counter overflows. 3.Port B interrupt on change. This interrupts when a change is detected on any of the higher 4 bits of Port B. 4.EEPROM write complete.

The 16F84A Interrupt Structure Dr. Gheith Abandah5 INTCON: SFR 0Bh

PIC Response to an Interrupt Dr. Gheith Abandah6

Interrupt Demonstration 1 – Page 1 #include p16f84A.inc ; ;Port A all output ;Port B: Bit 0 = Interrupt input ; org 00;Reset start goto start org 04 ;Int Service Routine start goto Int_Routine Dr. Gheith Abandah7

Interrupt Demonstration 1 – Page 2 start bsf status,rp0 ;select bank 1 movlw 01 movwf trisb ;bits 1-7 output, bit 0 input movlw 00 movwf trisa ;porta bits all output bcf status,rp0 ;select bank 0 bsf intcon,inte ;enable external interrupt bsf intcon,gie ;enable global int ;Remove semi-colon from following instruction to change ;interrupt edge ; bsf option_reg,intedg Dr. Gheith Abandah8

Interrupt Demonstration 1 – Page 3 wait movlw 0a ;set up initial port output values movwf porta movlw 15 movwf porta goto wait ; org 0080 Int_Routine ;Int Service Routine continues here movlw 00 movwf porta bcf intcon,intf ;clear INTF - Important retfie end Dr. Gheith Abandah9

Multiple Interrupts – Identifying the Source interrupt btfsc intcon,0 ;test RBIF goto portb_int ;Port B Change routine btfsc intcon,1 ;test INTF goto ext_int ;external interrupt routine btfsc intcon,2 ;test T0IF goto timer_int ;timer overflow routine btfsc eecon1,4 ;test EEPROM write complete flag goto eeprom_int ;EEPROM write complete routine Dr. Gheith Abandah10

Bad Effects of Interrupt Service Routines … movf plo,0 addwf qlo,0 ;What happens on an interrupt here? movwf rlo btfsc status,0 … Int_Routine bcf status,0 ;clear the Carry flag movlw 0ff ;change W reg value bcf intcon,intf retfie end Dr. Gheith Abandah11

Solution: Context Saving PUSH movwf w_temp ;Copy W to W_TEMP register swapf status,0 ;Swap status into W movwf status_temp ;Save status... Actual ISR goes here... POP swapf status_temp,0 ;Swap nibbles into W movwf status ;Move W into STATUS register swapf w_temp,1 ;Swap nibbles in W_TEMP swapf w_temp,0 ;Swap nibbles in W_TEMP into W Clear interrupt flag(s) here retfie Dr. Gheith Abandah12

Critical Regions In critical regions, we cannot allow the intrusion of an interrupt. Critical regions generally include all time- sensitive activity and any calculation where the ISR makes use of the result. Disable, or mask, the interrupts for their duration, by manipulating the enable bits in the INTCON register. Dr. Gheith Abandah13

Counters and Timers A digital counter is usually made of flip flops and counts up or down. When the triggering event is a constant frequency clock, we get a timer. Dr. Gheith Abandah14

Timer Applications (a)Measure the time between two events (b)Measure the time between two pulses (c)Measure a pulse duration Use polling or interrupts Dr. Gheith Abandah15

PIC 16F84A Timer 0 Module Dr. Gheith Abandah16

PIC 16F84A Timer 0 Module Dr. Gheith Abandah17

Option Register T0CS: Clock source select T0SE: Source edge select PSA: Prescaler assignment bit PS2:PS0: Prescaler rate select Dr. Gheith Abandah18

Counter Demonstration – Page 1 ; ;Demos Timer 0 as counter, using ping-pong hardware ; ;Clock freq 800kHz approx (RC osc.) ;Port A 4 right paddle (ip) Counter input. ; 2 "out of play" led (op) ;Port B 7-0 "play" leds (all op) ; list p=16F84A #include p16f84A.inc ; Dr. Gheith Abandah19

Counter Demonstration – Page 2 ; org 00 ; Initialise bsf status,rp0 ;select memory bank 1 movlw B' ' movwf trisa ;set port A to above pattern movlw 00 movwf trisb ;all port B bits output movlw B' ' ;set up T00 for external input, ; +ve edge, and no prescale movwf TMR0 bcf status,rp0 ;select bank 0 ; Dr. Gheith Abandah20

Counter Demonstration – Page 3 ; movlw 04 ;switch on a led to show power is on movwf porta loop movf TMR0,0 ;Continuously display T0 on Port B movwf portb goto loop end Dr. Gheith Abandah21

Hardware-Generated Delays In software-generated delays, the CPU is tied up during the delay time. Can use Timer 0 for delays. The timer overflow interrupt is used to inform the CPU when the delay time is up. Example: – Clock = 800 KHz Fosc/4 = 200 KHz T = 5 μs – Preselect = 8 for 125 count 125 x 8 x 5 μs = 5.00 ms – Need to set T0 at = 131 to get overflow after 5 ms Dr. Gheith Abandah22

HW Delay Demonstration – Page 1... ;Initialise org 0010 start bsf status,5 ;select memory bank 1 movlw B' ' movwf trisa ;set port A to above pattern movlw 00 movwf trisb ;all port B bits output movlw B' ' ;set up T0 for internal input, ; prescale by 8 movwf option_reg bcf status,5 ;select bank 0... Dr. Gheith Abandah23

HW Delay Demonstration – Page 2... ;introduces delay of 5ms approx delay5 movlw D'131' ;preload T0, so that 125 cycles, ; each of 40us, occur to overflow movwf TMR0 del1 btfss intcon,2 ;test for Timer Overflow flag goto del1 ;loop if not set bcf intcon,2 ;clear Timer Overflow flag return Dr. Gheith Abandah24

The Watchdog Timer A big danger with any computer-based system is that the software fails in some way and that the system locks up or becomes unresponsive. The WDT continually counts up. If it ever overflows, it forces the microcontroller into reset. If the instruction clrwdt is not executed every (18 ms * prescaler rate), overflow occurs. Dr. Gheith Abandah25

Sleep Mode When the sleep instruction is executed, the PIC halts execution and enters power saving mode. It awakes at: – External reset (MCLR) – WDT wake-up – Occurrence of an enabled interrupt Dr. Gheith Abandah26

Summary Interrupts and counter/timers are important hardware features of almost all microcontrollers. They both carry a number of important hardware and software concepts, which must be understood. The basic techniques of using interrupts and counter/timers have been introduced in this chapter. There is considerably increased sophistication in their use in more advanced applications. Dr. Gheith Abandah27