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:external_interrupts [2010/03/04 13:47] – Translation in progress yllarsen:avr:external_interrupts [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== External interrupts ======+====== External Interrupts ======
  
-External interrups are one of the most simple peripheral functions. AVRs typically have 1 to 8 special pins, which are used to cause interrupts in the program when their logical value changes or they are at a certain state. Since this function is usually used to monitor external logical signals, these pins are called external interrupt pins.+External interrups are one of the most simple peripheral functions. Typically AVRs have 1 to 8 special pins, which are used to cause interrupts in the program when their logical value changes or they are at a certain state. Since this function is usually used to monitor external logical signals, these pins are called external interrupt pins.
  
-To use an external interrupt, the pin has to be configured as standard IO input (it can also be used as an output, but in this case the interrupt can only be created by the controller itself). It is necessary to allow receiving interrupts and specify the condition that causes the interrupt to fire in the external interrupt configuration register. There are four possible conditions:+To use an external interrupt, the pin has to be configured as standard IO input (it can also be used as an output, but in this case the interrupt can only be created by the controller itself). It is necessary to allow receiving interrupts and specify the condition that causes the interrupt to fire in the external interrupt configuration register. There are four possible conditions:
  
   * Logical zero (voltage of 0V)   * Logical zero (voltage of 0V)
Line 10: Line 10:
   * Rising front - logical change from zero to one.   * Rising front - logical change from zero to one.
  
-Katkestuse tekitamiseks loogilise nulli valimisel tekitatakse katkestust järjest senikaua, kuni viigu väärtus on null. Põhiprogrammi töö on samal ajal peatatud. 
  
-Lähtudes tööpõhimõttelton väliseid katkestusi kahte liiki: kontrolleri taktiga sünkroniseeritud ja asünkroonsedSünkroniseeritud katkestused toimivad sisendite väärtuse meelespidamise teel, mis tähendab, et loogilised muutused leitakse kahel erineval taktil saadud väärtuste võrdlemise teel. Kui välise signaali loogilised muutused toimuvad kiiremini, kui käib töötakt, siis katkestused, kas ei teki õigesti või jäävad üldse vahele. Asünkroonsed katkestused ei sõltu kontrolleri taktist ja võimaldavad tuvastada ka kiiremini muutuvat välist signaali - loogilist nivood peab signaal hoidma vähemalt 50 ns. ATmega128-l on 4 sünkroniseeritud ja 4 asünkroonset välist katkestust.+When the mode is set to logical zerothe interrupt will fire continuously as long as the pin has a value of zeroDuring this period the execution of the main program is stopped.
  
-~~PB~~+Grouped by principle, there are two types of interrupts: synchronized to the controller's clock and asynchronous. Synchronized interrupts work by remembering the values of the inputs, which means that the changes in logical values are found by comparing values read during two different clock cycles. If the logical changes in the signal happen faster than the controller's duty-cycle, the interrupts either fire incorrectly or are skipped altogether. Asynchronous interrupts do not depend on the controller's clock and enable detecting faster changes in the external signal as well - the logical level must still be constant for at least 50 ns. ATmega128 has 4 synchronized and 4 asynchronous external interrupts.
  
-<box 100% round #EEEEEE|Näide>+<pagebreak>
  
-Vaja on panna ATmega128 viik number 9 ehk siini viik 7 tekitama katkestust, kui selle väärtus muutubSellele viigule vastab väline katkestus INT7, mis on sünkroonne.+<box 100% round #EEEEEE|Example> 
 + 
 +Task: Make ATmega128 pin number 9 (pin 7 on bus E) fire an interrupt if its value is changedThis pin corresponds to the INT7 external interruptwhich is synchronous.
  
 <code c> <code c>
 #include <avr/interrupt.h> #include <avr/interrupt.h>
  
-// Välise katkestuse programm+// The code of the external interrupt
 ISR(INT7_vect) ISR(INT7_vect)
 { {
- // Tee midagi+ // Do something
 } }
  
 int main() int main()
 { {
- // Siini E viigu muutmine sisendiks biti nullimise teel+ // Change pin on bus E to an input by changing bit to zero
  DDRE &= ~(1 << PIN7);  DDRE &= ~(1 << PIN7);
  
- // Siini E viigule 7 pull-up takisti määramine sisendi ujumise vastu+ // Defining a pull-up resistor to to pin 7 on bus E 
 +        // to prevent input floating
  PORTE |= (1 << PIN7);  PORTE |= (1 << PIN7);
  
- // Väliste katkestuste seaderegistris katkestuse + // Set the interrupt mode to logical change for interrupt 
- // tekitajaks loogilise muutuse määramine+        // in the external interrupt configuration register
  EICRB = (1 << ISC70);  EICRB = (1 << ISC70);
  
- // Välise katkestuse lubamine+ // Allow external interrupt 7
  EIMSK |= (1 << INT7);  EIMSK |= (1 << INT7);
  
- // Globaalne katkestuste lubamine+ // Allow global interrupts
  sei();  sei();
  
- // Lõputu programmitsükkel+ // Endless loop
  while (1) continue;  while (1) continue;
 } }
Line 54: Line 56:
 </box> </box>
  
-Lisaks üksikute viikude tekitatavatele katkestustele on suurematel AVR-idel võimalik kasutada ka tervete gruppide viikude loogiliste väärtuste muutuste katkestusiNeid katkestusi nimetatakse lihtsalt viigu muutuse katkestusteks (inglise keeles //pin change interrupt//)Need rakenduvad siis, kui vähemalt ühe viigu väärtus grupis muutub.+In addition to interrupts fired by single pins, if the AVR has enough pins it is possible to use entire groups of pins to fire logical value change interruptsThese interrupts are simply called pin change interruptsThey fire when the value of at least one pin in the group is changed.
en/avr/external_interrupts.1267710478.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