Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:avr:interrupts [2010/02/28 14:32] mikk.leinien:avr:interrupts [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Interrupts ====== ====== Interrupts ======
  
-Katkestuse (inglise keeles //interrupt//) saavad AVR-il tekitada loenduridandmesideliidesedanaloog-digitaalmuundurkomparaatorspetsiaalsed sisend-väljundviigud ja mitmed muud funktsioonidolenevalt kontrolleristIgat katkestust saab lubada või keelata seda genereerivas üksusesOlenemata katkestuse lubamisest või mitteon iga katkestuse jaoks vastavas kontrolleriüksuses 1-bitine andmeväli (lipuke, inglise keeles //interrupt flag//), mis märgitakse katkestust põhjustava sündmuse toimumisel tõeseksKui toimub nimetatud andmevälja muutumine ja katkestus on lubatudhakkab kontroller täitma koodi, mis oli katkestuse toimumisel ette nähtud.+Interrupts in AVR can be caused by counterscommunication interfacesanalog-to-digital converterscomparatorsspecial input-output pins and several other functionsdepending on the controllerAny interrupt can be allowed or disallowed by the unit that generates itRegardless of the interrupt being allowed or disallowedthere is a 1-bit field (interrupt flag) in the corresponding unit of the controllerwhich is marked as true when the interrupt condition is fulfilledIf the interrupt flag is changed to true and the interrupt is allowedthe controller starts to execute the code specified for this interrupt.
  
-AVR mikrokontrolleris on iga katkestus seotud kindla sündmusegaIgal sündmusel on olekuregistris lipubittmis tähistab sündmuse juhtumistLisaks on sündmustega seotud katkestuste maskeerimise registrid ja vastavad bitidKui sündmuse katkestuse bitt on maskeerimata ja tekib sündmusjätab protsessor mõne(kümne) töötakti jooksul käimasoleva programmi täitmise pooleli ning alustab katkestuse programmi täitmistPärast katkestuse programmi täitmist jätkab protsessor poolelijäänud programmi täitmist.+Every interrupt in the AVR microcontroller is tied to a specific eventEach event has a flag bit in the status registerwhich marks the occurring of the eventEvents are also tied to interrupt mask registers and the corresponding bitsIf the event's interrupt bit is left unmasked and an event occursthe processor halts executing the current program for a few duty-cycles and begins executing the interrupt programAfter the interrupt program has been executed, the processor resumes executing the paused main program.
  
-<box 100% round #EEEEEE|Näide>+<box 100% round #EEEEEE|Example>
  
-Katkestuste kasutamiseks AVR LibC teegiga tuleb kasutusele võtta //interrupt.h// failKatkestusel täitmisele minev programmikood lisatakse pärast "ISR"-i nimelist võtmesõna. "ISR" järele sulgudesse kirjutatakse katkestuse nimi. C-keele koodinäide:+To use interrupts with the AVR LibC library, it is necessary to include //interrupt.h//The code that gets executed upon interrupt is written after the "ISR" keywordThe text between the brackets after "ISR" is the name of the interruptThe following is a language example:
  
 <code c> <code c>
Line 14: Line 14:
 ISR(XXX_vect) ISR(XXX_vect)
 { {
- // Tee midagi+ // Do something
 } }
 </code> </code>
Line 20: Line 20:
 </box> </box>
  
-Globaalne, kõigi katkestuste toimumise lubamine, määratakse ära juht- ja olekuregistris SREG. Võimaluse kõiki katkestusi keelata või lubada tingib andmete kaitse vajadusKuna katkestused katkestavad käimasoleva programmi täitmisevõivad nad segada või rikkuda andmeid, mida põhiprogramm katkestamise hetkel kasutasSellist olukorda saab vältida kõikide katkestuste keelamisega enne tundlike andmetega tegelemistGlobaalne katkestuste keelamine on lihtnekui seda saab teha ühe registri (SREG) muutmisegaPärast kriitilise programmiosa lõppu saab katkestused uuesti lubada ja kõik katkestused, mille lipuke vahepeal ära märgitilähevad täitmisele.+Global allowing of all interrupts is configured from the control and status register SREG. The option to allow or disallow all interrupts at once is there to help protect dataSince interrupts disrupt the execution of the main programsome data used by the main program may be disturbed or corrupted in the processSituations like this can be avoided by simply disallowing all interrupts before processing such delicate dataDisallowing interrupts globally is easyif it can be done by changing only one register (SREG). After the critical part of the program has been executedthe interrupts can easily be allowed again and all the interrupts that would have fired in the meantime are executed.
  
-~~PB~~+<pagebreak>
  
-<box 100% round #EEEEEE|Näide>+<box 100% round #EEEEEE|Example>
  
-Oletame, et programmis on kasutusel 16-bitine muutuja, mille väärtust muudab nii põhiprogramm kui ka katkestuse programmilõikja selle muutuja väärtus omistatakse hiljem teisele muutujale:+Let's suppose there is a 16-bit variable in use in the programwhich is changed by both the main program and the interrupt program and the value of this variable is later given to another variable:
  
 <code c> <code c>
 #include <avr/interrupt.h> #include <avr/interrupt.h>
  
-// Globaalsed 16-bitised muutujad ja y+// Global 16-bit variables and y
 unsigned short x, y; unsigned short x, y;
  
-// Suvaline katkestus, mis muudab väärtuse+// A random interrupt that changes the value of x
 ISR(XXX_vect) ISR(XXX_vect)
 { {
Line 42: Line 42:
 int main() int main()
 { {
- // Muutujale väärtuse omistamine+ // Give a value to x
  x = 0x1111;  x = 0x1111;
  
- // Globaalne katkestuste lubamine+ // Allow interrupts globally
  sei();  sei();
  
- // x väärtuse muutujasse laadimine+ // Give the value of to y
  y = x;   y = x;
 } }
 </code> </code>
  
-Programm on väga lihtne algul omistatakse muutujale väärtus 0x1111 ja hiljem selle väärtus omakorda muutujale y. Kui vahepeal tekib katkestussaab x-i väärtuseks 0x3333. Loogikareeglite järgi saab muutujal programmi lõpus olla kaks võimalikku väärtustkuid 8-bitise AVR peal on ka kolmas võimalusNimelt, 8-bitise arhitektuuriga toimub 16-bitiste andmete liigutamine 2 takti jooksul ja vahepeal tekkiv katkestus võib andmete ühtsust rikkudaNiisiis võib peale 0x1111 ja 0x3333  tekkida ka väärtus 0x3311. Et sellist asja ei juhtukstuleks katkestused enne operatsioonemis toimuvad pikemalt kui takti jooksul, ajutiselt keelata.+The program itself is very simple first, variable is given a value of 0x1111 and later, its value is given to variable y. If an interrupt occurs between those two operations, x gets a value of 0x3333. By logic, variable can have two possible values by the end of the programbut on an 8-bit AVR there is also a third optionThis is because 8-bit architecture needs 2 cycles to move 16-bit data and therefore a badly-timed interrupt can corrupt the integrity of the dataConsequently, y can have a value of 0x1111 or 0x3333, but it can also have a value of 0x3311 at the end of the programTo avoid getting the thirdunwanted valueall interrupts should be temporarily disallowed before performing operations that take more than cycle.
  
-Toodud näites muutujale y muutuja väärtuse omistamine ohutul meetodil:+In the following example, the value of is given to y using a safe method:
  
 <code c> <code c>
- // Globaalne katkestuste keelamine+ // Disallow interrupts globally
  cli();  cli();
  
- // Laadimine+ // Give the value of x to y
  y = x;  y = x;
  
- // Globaalne katkestuste uuesti lubamine+ // Re-allow all interrupts again
  sei();  sei();
 </code> </code>
  
 </box> </box>
en/avr/interrupts.1267367575.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0