Timers and Interrupts Anurag Dwivedi. Let Us Revise.

Slides:



Advertisements
Similar presentations
Introduction to Micro-controllers Anurag Dwivedi.
Advertisements

More fun with Timer/Counters
Microcontroller Programming II MP6-1
I/O Unit.
MICRO-CONTROLLER: A microcontroller is the brain of the robot: These are: 1. Integrated Circuits (ICs) 2. Programmable.
EET 2261 Unit 10 Enhanced Capture Timer  Read Almy, Chapter 20.  Homework #10 and Lab #10 due next week.  Quiz next week.
68HC11 Polling and Interrupts
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
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.
Butterfly I/O Ports CS-212 Dick Steflik. I/O for our labs To get data into and out of our Butterfly its a little trickier than using printf and scanf.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
 Main Components:  Sensors  Micro controller  Motor drivers  Chasis.
INTERRUPTS PROGRAMMING
Timers and Interrupts Shivendu Bhushan Sonu Agarwal.
Introduction to Microcontrollers Shivendu Bhushan Summer Camp ‘13.
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
Input/Output mechanisms
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
Timer/counter Chapter 12
ARM Timers.
System Clocks.
A Few Words From Dilbert
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Chapter 4 TIMER OPERATION
MICROPROCESSOR INPUT/OUTPUT
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
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.
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.
CS-280 Dr. Mark L. Hornick 1 Atmel Timer/Counter System Most microcontrollers include some type of timer system Facilitates real-time monitoring and control.
MIPS I/O and Interrupt.
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.
Interrupts Microprocessor and Interfacing
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
Chapter 5 - Interrupts.
Interrupt On a very basic level, an interrupt is a signal that interrupts the current processor activity. It may be triggered by an external event (change.
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
Lecture 41 CSE 341 – Microprocessors Lecture 4 Md. Omar Faruqe UB 1228
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
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.
Introduction to AVR Name : 1) Abhishek Yadav ) Prakash Giri ) Kheni Niral ) Bhadresh Langadiya Branch.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
EET 2261 Unit 13 Enhanced Capture Timer
Basic Computer Organization and Design
ECE 3430 – Intro to Microcomputer Systems
Interrupts and signals
Timer and Interrupts.
UNIT – Microcontroller.
BITS EDU. CAMPUS , VARNAMA
AVR Addressing Modes Subject: Microcontoller & Interfacing
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
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.
Timer/Counter Modified from Dr. Lam Phung’s Slides.
AVR Programming in C Chapter 7
Interrupt Source: under
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
MIPS I/O and Interrupt.
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Wireless Embedded Systems
COMP3221: Microprocessors and Embedded Systems
Surjo Dutta and David Friedman
Presentation transcript:

Timers and Interrupts Anurag Dwivedi

Let Us Revise

Micro-Controllers  A small computer integrated in a single IC  Has I/O pins, RAM and Memory  We Use Atmega 16

Software Used  CvAvr : Editor and Compiler  Avr Studio : Used to program the code into the micro- controller

Registers  Registers are actual hardware memory locations inside the μ C.  What do we mean by this??  Consider a 8-bit long register. Each bit of the register can be realized as a flip-flop.  Ex. PORTA is a register.  When you set the value of PORTA = 0X01, you physically set the corresponding flip-flop a value of +5 Volts.

I/O Registers  There are 3 registers that control the I/O pins: DDR, PORT and PIN.  Each port has it’s own registers. Hence, port A has registers DDRA, PORTA, PINA; port B has registers DDRB, PORTB, PINB; and so on.  DDR, PORT and PIN serve different functions.  DDR Register : DDR decides whether the pins of a port are input pins or output pins.  PORT Register : PORT is used to set the output value.  PIN Register : PIN gives the value of the input.

Summary of Last Lecture

An example program #include int main(){ DDRA = 0xFF; while(1){ PORTA = 0xAA; _delay_ms(1000); PORTA = 0x55; _delay_ms(1000); } return 0; }

Timers  A Timer is usually a 8-bit register.  Values starts from 0 and goes up to 255.  Timer value increases by 1,after each period.  When the timer reaches its maximum value, in the next cycle, its value becomes 0 again and the process repeats itself.  The timer frequency can be factors of the base frequency of the MCU.  This process is independent of the CPU.

Simple Statistics  Maximum value of timer is n andclock period is t, then:  1. Timer period = t  2. Timer cycle period = (+1)×  3. Frequency of timer (f) = 1/  4. Frequency of timer cycle = 1/(+1)×

Interrupts  Interrupts means causing a break in a continuing process.

Why Interrupts ??  Suppose you need to check for a condition A while running another condition B

 Simple Solution..  while(1){  > if (Event A == true)  > // print event A has occurred  ----  > Event B  > Suppose Event A happens here  ---- }}  Do you see the problem in this approach??

A Better Solution .. ..  while(1){  ---  EVENT B  --- }} ..  handleA(){ ..  //print A }} We execute the event B in a normal way, in a while(1) loop. We consider the occurrence of event A as an interrupt. We execute the required code in the Handler of A It means that whenever an interrupt ( event A) occurs the code stops and a function is called …..

More on Interrupts  Interrupts are special events that can “interrupt” the normal flow of a program.  Whenever an Interrupt is called, the processor stops the normal program, handles the interrupt, and then resumes its normal work.  There are two types of interrupts: External and Internal

External Interrupts  The controller monitors the input at the special pins INT0 and INT1, whenever external interrupt is set on.  We can configure the program to call an external interrupt whenever any of the following conditions are met.  Rising Edge  Falling Edge  Any change

Internal Interrupts  The internal interrupts are called when different specific conditions are met by the timer value.  This brings us to the next topic..

Timers and Interrupts  Timers can generate certain interrupts: two, to be precise.  These are called OVERFLOW interrupt and COMPARE MATCH interrupt.

Overflow Interrupts  An overflow interrupt is generated when the timer exceeds its maximum value and resets to 0  The interrupt may or may not have a handler.  In either case, the timer continues to run; remember: timers are independent of the CPU.

Overflow Statistics  Suppose a timer of maximum value n has a time period t (also called as clock period). Then :  1. Timer cycle frequency = 1/(+1)×  2. OVERFLOW interrupt frequency = 1/(+1)×  If OVERFLOW interrupt is enabled, then aninterrupt is generated in every cycle.

Compare Match Interrupts  A compare match interrupt is called when the value of the timer equals a specific value, set by the user.  This value is set by setting the value of OCR register.  Before incrementing, the value of the timer is compared to OCR. If the two are equal, a COMPARE MATCH interrupt is generated

Compare Match Statistics  Suppose a timer of maximum value n has a time period t (also called as clock period). Then :  1. Timer cycle frequency = 1/(+1)×  2. COMPARE MATCH interrupt frequency = 1/(+1)×  If COMPARE MATCH interrupt is enabled, then an interrupt is generated in every cycle.

Interrupts – Overflow and Compare Match

Timer Modes  A timer works in three modes: Normal, CTC and PWM.  All three modes differ in the response of the controller to the interrupts generated.

Normal Mode  Standard mode: Timer starts at 0, goes to maximum value and then resets itself.  OVERFLOW and COMPARE MATCH interrupts generated as normal.  The timer mode used so far in this presentation is normal mode.

CTC Mode  Known as Clear Timer on Compare.  As evident by the name, the timer starts at 0 as usual, but instead of resetting after maximum value, it resets after reaching value specified in OCR register.  Compare match interrupt if enabled will be generated but not overflow interrupt (Why?)

CTC Mode Statistics  If clock time period is t:  1. Timer cycle time period = (+1)×  2. Frequency = 1/(+1)×  With the use of CTC Mode we can theoretically generate any frequency up to 8 MHz.  Example of 1 Hz generation.

Questions …