Processor and compiler dependent

Similar documents
Fundamental concept in computation Interrupt execution of a program to handle an event

COMP2121: Microprocessors and Interfacing

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

INTERRUPT, TIMER/COUNTER. KONKUK UNIV. VLSI Design Lab. LSI Design Lab

Microprocessors & Interfacing

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

8-bit Microcontroller with 8K Bytes Programmable Flash AT90C8534. Preliminary

Introduction to Embedded Systems

AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Features. Introduction. AVR 8-bit Microcontrollers APPLICATION NOTE

Embedded Systems and Software

Timers and Interrupts. Mark Neil - Microprocessor Course

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

AGH University of Science and Technology Cracow Department of Electronics

Microprocessors & Interfacing

Interrupts (II) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR Timers TIMER0. Based on:

INTERRUPTS in microprocessor systems

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

Marten van Dijk Department of Electrical & Computer Engineering University of Connecticut

Marten van Dijk, Syed Kamran Haider

AGH University of Science and Technology Cracow Department of Electronics

Newbie s Guide to AVR Interrupts

3. (a) Explain the steps involved in the Interfacing of an I/O device (b) Explain various methods of interfacing of I/O devices.

Interrupt/Timer/DMA 1

Introduction to the MC9S12 Hardware Subsystems

8-bit Microcontroller with 1K Byte of In-System Programmable Flash AT90S1200

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

These three counters can be programmed for either binary or BCD count.

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

EE445L Fall 2012 Quiz 2B Page 1 of 6

ATmega Interrupts. Reading. The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

Department of EIE / Pondicherry Engineering College. Timer/Counters. Department of EIE / Pondicherry Engineering College 1

8051 Microcontroller Interrupts

AVR Helper Library 1.3. Dean Ferreyra

PC Interrupt Structure and 8259 DMA Controllers

Atmel AVR Timers and Interrupts

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash AT90S2323 AT90LS2323 AT90S2343 AT90S/LS2323. Features.

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash. ATtiny22 ATtiny22L. Preliminary. Features. Description

ADC: Analog to Digital Conversion

80C51 Block Diagram. CSE Overview 1

FIFTH SEMESTER B.TECH DEGREE EXAMINATION MODEL TEST QUESTION PAPER, NOVEMBER CS 305: Microprocessor and Microcontrollers PART A

8-bit Microcontroller with 1K Byte Flash. ATtiny15L

Physics 120B: Lecture 11. Timers and Scheduled Interrupts

PIC Microcontroller Introduction

General Purpose Programmable Peripheral Devices. Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

Lecture 14. Ali Karimpour Associate Professor Ferdowsi University of Mashhad

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

12.1. Unit 12. Exceptions & Interrupts

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

MCS-51 Serial Port A T 8 9 C 5 2 1

real-time kernel documentation

CHAPTER 11 INTERRUPTS PROGRAMMING

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

8-bit Microcontroller with 2K Bytes of Flash. ATtiny28L ATtiny28V

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash AT90S2313

EE458 - Embedded Systems Exceptions and Interrupts

Timer Module Timer A. ReadMeFirst

Course Introduction. Purpose: Objectives: Content: 27 pages 4 questions. Learning Time: 20 minutes

8-bit Microcontroller with 4K Bytes of In-System Programmable Flash AT90S4433 AT90LS4433. Features. Not Recommend for New Designs. Use ATmega8.

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

Input/Output Modes Chapter 8

ECE 372 Microcontroller Design Parallel IO Ports - Interrupts. ECE 372 Microcontroller Design Parallel IO Ports - Interrupts

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

Physics 124: Lecture 12. Timer Basics. Timers and Scheduled Interrupts

In Class Assignment 2

A. This Errata sheet represents the known bugs, anomalies and work-arounds for the ADuC812 MicroConverter.

The Atmel ATmega328P Microcontroller

Interrupts, timers and counters

Chapter 7 Central Processor Unit (S08CPUV2)

8-bit Microcontroller with 1K Bytes Flash. ATtiny10 ATtiny11 ATtiny12. Preliminary. Features. Pin Configuration

QUESTION BANK CS2252 MICROPROCESSOR AND MICROCONTROLLERS

Interrupts. Embedded Systems Interfacing. 08 September 2011

Microcomputer Architecture and Programming

Chapter Operation Pinout Operation 35

Microcontroller and Embedded Systems:

Embedded Systems and Software

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

Department of Electronics and Instrumentation Engineering Question Bank

Emulating an asynchronous serial interface (ASC0) via software routines

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

Winford Engineering ETH32 Protocol Reference

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Yielding, General Switching. November Winter Term 2008/2009 Gerd Liefländer Universität Karlsruhe (TH), System Architecture Group

Microprocessors B (17.384) Spring Lecture Outline

CN310 Microprocessor Systems Design

Module Introduction. PURPOSE: The intent of this module is to explain MCU processing of reset and interrupt exception events.

Clock and Fuses. Prof. Prabhat Ranjan Dhirubhai Ambani Institute of Information and Communication Technology, Gandhinagar

Topic 11: Interrupts ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

Microprocessor Architecture

Registers Format. 4.1 I/O Port Address

Distributed Real-Time Control Systems. Chapter 10 Real-Time Digital Control

Chapters 2, 3: bits and pieces. Chapters 2 & 3. Chapters 2, 3: bits and pieces. Chapters 2, 3: bits and pieces. Using C. A last word about hardware

Chapter 3 - Top Level View of Computer Function

MCU: Interrupts and Timers. Ganesh Pitchiah

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

Topic 11: Timer ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

8-bit Microcontroller with 1K Byte Flash. ATtiny11. ATtiny12

Marten van Dijk, Syed Kamran Haider

Transcription:

Fundamental concept in computation Interrupt execution of a program to handle an event Don t have to rely on program relinquishing control Can code program without worrying about others Issues What can interrupt and when? Where is the code that knows what to do? How long does it take to handle interruption? Can an interruption be, in turn, interrupted? How does the interrupt handling code communicate its results? How is data shared between interrupt handlers and programs? Reaction to something in I/O (human, comm link) Usually asynchronous to processor activities interrupt handler or interrupt service routine (ISR) invoked to take care of condition causing interrupt Change value of internal variable (count) Read a data value (sensor, receive) Write a data value (actuator, send) Main Program Instruction 1 Instruction 2 Instruction 3 Instruction 4.. ISR Save state Instruction 1 Instruction 2 Instruction 3.. Restore state Return from Interrupt Code sample that does not interrupt char SPI_SlaveReceive(void) { /* Wait for reception complete */ while(!(spsr & (1<<SPIF))) ; /* Return data register */ return SPDR; } Instead of busy waiting until a byte is received the processor can generate an interrupt when it sets SPIF SIGNAL(SIG_SPI) { RX_Byte = SPDR } Processor and compiler dependent Where to find ISR code? Different interrupts have separate ISRs Who does dispatching? Direct Different address for each interrupt type Supported directly by processor architecture Indirect One top-level ISR Switch statement on interrupt type A mix of these two extremes? How much context to save? Registers, flags, program counter, etc. Save all or part? Agreement needed between ISR and program Where should it be saved? Stack, special memory locations, shadow registers, etc. How much room will be needed on the stack? Nested interrupts may make stack reach its limit what then? Restore context when ISR completes Can interrupts be ignored? It depends on the cause of the interrupt No, for nuclear power plant temperature warning Yes, for keypad on cell phone (human timescale is long) When servicing another interrupt Ignore others until done Can t take too long keep ISRs as short as possible Just do a quick count, or read, or write not a long computation Interrupt disabling Will ignored interrupt stick? Rising edge sets a flip-flop Or will it be gone when you get to it? Level changes again and its as if it never happened Don t forget to re-enable 1

! " $%& When multiple interrupts happen simultaneously Which is serviced first? Fixed or flexible priority? Priority interrupts Higher priority can interrupt Lower priority can t Maskable interrupts don t bother me with that right now Not all interrupts are maskable, some are non-maskable External interrupts From I/O pins of microcontroller Internal interrupts Timers Output compare Input capture Overflow Communication units Receiving something Done sending ADC Completed conversion (&)* %+, - Fixed location in memory to find first instruction for each type of interrupt Only room for one instruction JMP to location of complete ISR Finish executing current instruction Disable all interrupts CLI Push program counter on to stack Jump to interrupt vector table Jump to start of complete ISR Save any context that ISR may otherwise change Automatic Registers and flags must be saved within ISR and restored before it returns this is very important! SEI Re-enable enable interrupts if nested interrupts are ok Complete ISR s code Re-enable enable interrupts upon return Jump back to next instruction before interruption RETI Compiler.! +,&, When you use interrupts you create the opportunity for multiple sections of code to update a variable. This might cause a problems in your logic if an interrupt updates a variable between two lines of code that are directly dependent on each other (e.g. if statement) One solution is to create critical sections where you disable the interrupts for a short period of time while you complete your logic on the shared variable Special pins: INT0, INT1, INT2 Can interrupt on edge or level Can interrupt even if set to be output pins Implements software interrupts by setting output cli();..critical section code goes here.. sei(); 2

, /0%& 1 %& 1 Timer0/Counter0 Clear timer on compare match (auto reload) Prescaler (divide clock by up to 1024) Overflow and compare match interrupts Registers Configuration Count value Output compare value Timer/Counter Control Register TCCR0 %& 1 2*34 %& 1 2*34 Timer/Counter Control Register TCCR0 Timer/Counter Control Register TCCR0 %& 1 2*34 ), Defined names for each register and bit Set timer to clear on match Set prescaler to 1024 TCCR0 = (1<<WGM01) (1<<CS02) (1<<CS00); Set count value to compare against OCR0 = 150; Set timer to interrupt when it reaches count TIMSK = (1<<OCIE0); 3

5, $,,* Set and clear interrupt enable sei(); cli(); Interrupt handler SIGNAL(SIG_OUTPUT_COMPARE0) { i++; } Setting I/O registers TCCR0 = (1<<WGM01) (1<<CS02) (1<<CS00); Enabling specific interrupts TIMSK = (1<<OCIE0); Use charge-redistribution technique no sample and hold circuitry needed even with perfect circuits quantization error occurs Basic capacitors sum parallel capacitance $,,* 2*34 $.6 &, Two reference voltage mark bottom and top end of range of analog values that can be converted ( V L and V H ) voltage to convert must be within these bounds ( V X ) Successive approximation most approaches to A/D conversion are based on this 8 to 16 bits of accuracy Approach sample value hold it so it doesn t change successively approximate report closest match During the sample time the top plate of all capacitors is switched to reference low V L Bottom plate is set to unknown analog input V X Q = CV Q S = 16 (V X - V L ) $.6, $.6 ** & Hold state using logically controlled analog switches Top plates disconnected from V L Bottom plates switched from V X to V L Q H = 16 (V L - V I ) conservation of charge Q S = Q H 16 (V X - V L ) = 16 (V L - V I ) V X - V L = V L - V I (output of op-amp) Each capacitor successively switched from V L to V H Largest capacitor corresponds to MSB Output of comparator determines bottom plate voltage of cap > 0 : remain connected to V H < 0 : return to V L 4

$.&, 78 $.&, 2784 Suppose V X = 21/32 (V H - V L ) and already sampled Compare after shifting half of capacitance to V H V I goes up by + 8/16 (V H -V I ) - 8/16 (V L -V I ) = + 8/16 (V H - V L ) V L - ( V I +.5 (V H - V L ) ) = V L - V I -.5 (V H - V L ) Output > 0 Compare after shifting another part of cap. to V H V I goes up by + 4/16 (V H -V I ) - 4/16 (V L -V I ) = + 4/16 (V H - V L ) V L - ( V I +.25 (V H - V L ) ) = V L - V I -.25 (V H - V L ) Output < 0 (went too far) $.&, 2784 $.&, /8 Compare after shifting another part of cap. to V H V I goes up by + 2/16 (V H -V I ) - 2/16 (V L -V I ) = + 2/16 (V H - V L ) V L - ( V I +.125 (V H - V L ) ) = V L - V I -.125 (V H - V L ) Output > 0 Compare after shifting another part of cap. to V H V I goes up by + 1/16 (V H -V I ) - 1/16 (V L -V I ) = + 1/16 (V H - V L ) V L - ( V I +.0625 (V H - V L ) ) = V L - V I -.0625 (V H - V L ) Output < 0 (went too far again) $.&,-,, $. Input sample of 21/32 Gives result of 1010 or 10/16 = 20/32 3% error 5

, /0$. $. $%& Needs a comparator and a D-to-A converter Takes time to do successive approximation Interrupt generated when conversion is completed 10-bit resolution (adjusted to 8 bits as needed) 65-260 usec conversion time 8 multiplexed input channels Capability to do differential conversion Difference of two pins Optional gain on differential signal (amplifies difference) Interrupt on completion of A-to-D conversion 0-V CC input range 2*LSB accuracy (2 * 1/1024 = ~0.2%) Susceptible to noise special analog supply pin (AVCC) and capacitor connection for reference voltage (AREF) Single-ended or differential 1 of 8 single-ended ADCx ADC1 at 1x gain ADC{0,1} ADC0 at 10x ADC{0,1} ADC0 at 200x ADC{2,3} ADC2 at 10x ADC{2,3} ADC3 at 200x ADC{0,1,2,3,4,5} ADC2 at 1x 6

5, 24 Ensure main program sets up all registers Enable interrupts as needed Enable global interrupts (SEI) Write handler routine for each enabled interrupt What if an interrupt occurs and a handler isn t defined? Make sure routine does not disrupt others Data sharing problem Save any state that might be changed (done by compiler) Re-enable interrupts upon return done by compiler with RETI!9 &!9 &2*34 Processor can go to sleep and save power Different modes put different sets of modules to sleep Which one to use depends on which modules are needed to wake up processor Timers, external interrupts, ADC, serial communication lines, etc. set_sleep_mode (mode); sleep_mode ();!9 &2*34 Wake up sources and active clocks 7