Microprocessors, Lecture 9:Interrupts in AVR Microcontrollers(Chapter 10 of the text book)
Contents Interrupts ATmega32 Using interrupts in C programmingUniversity of Tehran 2
Interrupts in AVRInterrupts: A way o improve performanceUniversity of Tehran 3
How do interrupts work?University of Tehran 4
Interrupt vs. polling Polling:– Continuously check the flags to know when theexpected event occurs, then go for the nextevent– Example: Timer time-out problem of the previous lecture:University of Tehran 5
Interrupt vs polling Polling: wasting time to check the devicescontinuously What if we are to generate two delays at thesame time?– Example: Toggle bit PB.5 every 1s and PB.4 every 0.5s. What if there are some task to be donesimultaneously with the timers?– Example: (1) read the contents of port A, process thedata, and send them to port D continuously, (2) toggle bitPB.5 every 1s, and (3) PB.4 every 0.5s.University of Tehran 6
Interrupt vs polling Interrupts– A mechanism to work with peripheral devices No need for the processor to monitor the status ofthe devices and events Let the events notify the processor when theyoccur– By sending an interrupt signal to processorUniversity of Tehran 7
Interrupt vs polling Interrupts:– Example: Copy the contents of port A to port Dcontinuously and toggle bit PB.5 every 1s and PB.4every 0.5s.– Solution:» Copying the contents of port A to port D as the main program» Get timers 0 and 1 to generate the delays» Define two interrupts for timers 0 and 1 to notify the processorwhen they finish counting» Upon an interrupt, stop the main program, service the timers andcontinue the main programUniversity of Tehran 8
Interrupts Interrupting mechanism in all microprocessors andmicrocontrollers is almost the same:– Define the set of devices and events that can generatean interrupt– Write a function for each interrupt that will be executedwhen the corresponding interrupt is activated» The address of this function must be saved somewhere– Set a priority scheme among interrupts– A mechanism is needed to disable all or some interruptsUniversity of Tehran 9
Interrupts ISR: Interrupt Service Routine– The function that is executed when an interruptis enabled Interrupt Vector Table: a table that keeps theaddress of each ISR in the instruction memoryUniversity of Tehran 10
Interrupt sources in AVR.University of Tehran 11
External interrupts 3 pins of ATmega32University of Tehran 12
Interrupts in AVR Just 2-bytes for eachinterrupt service routine Too small to write theinterrupt service routine Æ Write the routinesomewhere in the memoryand put a code to jump to theaddress of the function in the2-byte assigned to the ISRUniversity of Tehran 13
Interrupts in AVR How is an interrupt serviced?1. Stop fetching the next instruction and save PC2. Go to Interrupt Vector Table to find the address of the ISR ofthe interrupting device3. Execute the function4. Resume normal execution by retrieving PCUniversity of Tehran 14
Enabling Interrupts Interrupts can be enabled or disabled byprogrammer– Bit7 (I) in SREG (status register)– SREG keeps the processor status (remember the firstlecture on AVR)– Disabled on reset (I 0)University of Tehran 15
Enabling Interrupts In addition to Bit7 (I) in SREG each interruptshould be enabled independently The enable bit of each interrupt is in some register– Example: TIMSK register to enable/disable timerinterrupts– TIMSK Timer Interrupt Mask– Mask? غيرفعال کردن ، پوشاندن To enable timer1 overflow interrupt:– Bit7 (I) in SREG Å 1– Bit 0 of TIMSK (TOIE0)Å 1University of Tehran 16
Interrupt priority What if two or more interrupts occurat the same time?– The interrupt with lower ISR addressis prioritized (external int. 0 has thehighest priority) When an interrupt is serviced, the Ibit becomes automatically 0 todisable interrupts– Will be enabled when returning fromthe ISRUniversity of Tehran 17
TIMSK registerUniversity of Tehran 18
Interrupt programming in C Enable interrupts Set the mask register (TIMSK for timers)– Example: TIMSK 0x01; Write the ISR function to specify whatoperation should be done when the interruptoccursÆ Compiler dependent: different in differentcompilers!University of Tehran 19
Interrupt programming in C A way to use assemblyinstructions in C:#asm(“instruction”) SEI: (Set I) an assemblyinstruction that enablesinterrupts (bit 7 ofSREG 1) CLI: Clear I #asm(“sei”); enableinterrupts in C No way to accessSREG.7 in C Mazidi’s book uses a differentcompilerÆ differentinstructions: sei() instead of#asm(“sei”), different ISRnames#asm(“sei”);interrupt [TIM0 OVF] void timer0 ovf isr(void)Æ On entering the timers ISR, the TOV0bit is automatically cleared, no need tobe cleared by softwareUniversity of Tehran 20
Interrupt programming in C In codevision, ISR is generated duringproject setup. Just fill the function body!University of Tehran 21
External Interrupts To allow externalsources interrupt themicrocontroller Can be masked by CIGRregister GICR: General interruptcontrol registerUniversity of Tehran 22
External Interrupts- GICRUniversity of Tehran 23
External interrupts Interrupts can be edge triggered or level triggered Edge trigger: activated when a change in signallevel occurs Level trigger: activated when a signal has aspecific value INT0 and INT1 can be programmed to be edge orlevel triggered– Low-level active by default INT 2 is only edge triggeredUniversity of Tehran 24
External interrupts A register called ISC (interrupt sense control) canset the interrupt type of INT0 and INT1ISC RegisterISC10 and ISC11 set the same setting for INT1University of Tehran 25
External Interrupts- Cprogramming#asm(“sei”);University of Tehran 26
Resume normal execution by retrieving PC . University of Tehran 15 Enabling Interrupts Interrupts can be enabled or disabled by programmer – Bit7 (I) in SREG (status register) – SREG keeps the processor status (remember the first lectur
AVR Basics The AVR microcontrollers are divided into three groups: 1. tiny AVR 2. AVR (Classic AVR) 3. mega AVR 4. xmega AVR The difference between these devices lies in the available features. The tinyAVR μC are usually devices with lower pin-count or a reduced feature set compared to the mega & xmega AVR's. All AVR devices have identical
pher on 8-bit AVR microcontrollers, 32-bit RISC-V processors, and 64-bit ARM processors. The optimal performance is achieved through e cient register allo-cation and instruction techniques. 3.1 8-bit Low-end AVR Microcontrollers Instruction set. AVR microcontrollers have useful instruction sets. Generally instructions take 1 or 2 clock cycles.
The AVR 3700/AVR 370 7.2-channel and AVR 2700/AVR 270 7.1-channel digital audio/ video receivers continue this tradition with some of the most advanced audio and video processing capabilities yet, and a wealth of listening and viewing options. To obtain the maximum enjoyment from your new receiver, please read this manual and
the Avr 3700/Avr 370 7.2-channel and Avr 2700/Avr 270 7.1-channel digital audio/ video receivers continue this tradition with some of the most advanced audio and video processing capabilities yet, and a wealth of listening and viewing options. to obtain the maximum enjoyment from your new receiver, please read this manual and
avr 3700 и avr 2700 предназначены для использования с переменным током напряжением 120 В. avr 370 и avr 270 предназначены для использования с переменным током напряжением 220 – 240 В. Подключение к напряжению,
die receiver avr 3700 und avr 2700 sind für den Betrieb mit 120 v Wechselstrom (ac) ausgelegt. die receiver avr 370 und avr 270 sind für den Betrieb mit 220-240 v Wechselstrom (ac) ausgelegt. der anschluss an ein Stromnetz, das nicht dem Stromnetz entspricht, für das ihr receiver gebaut wurde, kann zu einem Sicherheits- und
download the AVR 3650, AVR 365, AVR 2650, AVR 265 Owner’s Manual. Place the Receiver Place the receiver on a firm and level surface. Be certain that the surface and any mounting hardware can support the receiver’s weight. Provide proper space above and below the receiver for ventilation. If you install the receiver
Устройства avr 3650 и avr 2650 были сконструированы для использования с источником сетевого напряжения 120 В переменного тока. Устройства avr 365 и avr 265 были сконструированы для исполь-