issue134:great_cow_basic
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue134:great_cow_basic [2018/07/17 07:30] – d52fr | issue134:great_cow_basic [2018/07/20 16:41] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**In FCM#131 I showed you how to recognize the state of a switch and debug over the serial line. After having some troubles with the code in this article, I had to have a break and get things together. So with some delay here we are now learning about interrupts, what they are and what for they are helpful. My apologies if this caused some inconveniences.** | **In FCM#131 I showed you how to recognize the state of a switch and debug over the serial line. After having some troubles with the code in this article, I had to have a break and get things together. So with some delay here we are now learning about interrupts, what they are and what for they are helpful. My apologies if this caused some inconveniences.** | ||
- | Dans le n°131 | + | Dans le n° 131 du FCM, je vous ai montré comment reconnaître l' |
**Interrupt service routines | **Interrupt service routines | ||
An interrupt does what the term describes, it interrupts a running program - or better: causes a jump in the program - and executes another piece of program code. The so called ‘interrupt service routine’. | An interrupt does what the term describes, it interrupts a running program - or better: causes a jump in the program - and executes another piece of program code. The so called ‘interrupt service routine’. | ||
+ | |||
+ | Routines de service d'une interruption | ||
+ | |||
+ | Une interruption fait ce que son nom décrit ; elle interrompt un programme qui tourne - ou mieux : elle entraîne un saut dans le programme et exécute un autre morceau du code du programme. C'est la dénommée « routine de service de l' | ||
**For the INT0 interrupt you only have one PIN available, the PIN B1 (PORTB.1). This restriction comes with some advantages, with INT0 you could set the trigger to four different states: | **For the INT0 interrupt you only have one PIN available, the PIN B1 (PORTB.1). This restriction comes with some advantages, with INT0 you could set the trigger to four different states: | ||
Ligne 12: | Ligne 16: | ||
• the falling edge or | • the falling edge or | ||
• the rising edge of the signal (the transition from the high to the low level). ** | • the rising edge of the signal (the transition from the high to the low level). ** | ||
+ | |||
+ | Pour l' | ||
+ | • si le niveau sur la borne est bas (LOW), | ||
+ | • sur tout changement logique, | ||
+ | • la chute de ou | ||
+ | • la montée du signal (la transition de l' | ||
**The PCINT0 interrupt can be used with all remaining PIN except Vcc and GND. The disadvantage of this interrupt is that it triggers on every transition and you have to determine which PCINT has fired. If only using one PIN this is a small caveat, but if using more than one, you would have to determine which one has ‘pulled the trigger’. Another possible solution regarding switches and interrupts would be a polling routine. At certain intervals it would be checked if a switch was pressed or not. For this you would use the service routine of a timer interrupt, but for one button only, it would be kind of over-engineering. So without further ado, here are some sample codes for INT0 interrupt routines. | **The PCINT0 interrupt can be used with all remaining PIN except Vcc and GND. The disadvantage of this interrupt is that it triggers on every transition and you have to determine which PCINT has fired. If only using one PIN this is a small caveat, but if using more than one, you would have to determine which one has ‘pulled the trigger’. Another possible solution regarding switches and interrupts would be a polling routine. At certain intervals it would be checked if a switch was pressed or not. For this you would use the service routine of a timer interrupt, but for one button only, it would be kind of over-engineering. So without further ado, here are some sample codes for INT0 interrupt routines. | ||
Ligne 18: | Ligne 28: | ||
The code to use the Pin Change Interrupt service routine instead is shown on the following page at the bottom left.** | The code to use the Pin Change Interrupt service routine instead is shown on the following page at the bottom left.** | ||
+ | |||
+ | L' | ||
+ | |||
+ | La page suivante (en haut à gauche) montre une petite version de la routine de service d'INT0 en Great Cow Basic, avec résistance de tirage. | ||
+ | |||
+ | Le code pour utiliser à la place la routine de service « Pin Change » (modification sur la connexion) est présenté sur la page suivante en bas à gauche. | ||
**Debouncing the button presses | **Debouncing the button presses | ||
Ligne 24: | Ligne 40: | ||
And the debouncing routine with the pin change interrupt in Great Cow BASIC is:** | And the debouncing routine with the pin change interrupt in Great Cow BASIC is:** | ||
+ | |||
+ | Anti-rebond sur les appuis du bouton | ||
+ | |||
+ | En plus, vous ne voudriez peut-être pas changer l' | ||
+ | |||
+ | Et la routine d' | ||
**Breadboard circuitry | **Breadboard circuitry | ||
Ligne 30: | Ligne 52: | ||
For testing purposes you would not change the hardware test circuit with above codes, with the pull-down version you would need to change code and also the breadboard circuit.** | For testing purposes you would not change the hardware test circuit with above codes, with the pull-down version you would need to change code and also the breadboard circuit.** | ||
+ | |||
+ | Circuit sur la plaque d' | ||
+ | |||
+ | Pour le test avec les résistances de tirage internes activées, vous aurez besoin d'une LED, d'un interrupteur et du microcontrôleur (voir le circuit sur la page suivante, en bas à gauche). Connectez une terminaison de l' | ||
+ | |||
+ | Pour les besoins du test, vous ne changerez pas la circuiterie de test du matériel avec le code ci-dessus ; dans la version avec résistances de tirage, vous auriez besoin de modifier le code ainsi que le circuit de la plaque d' | ||
**Conclusion | **Conclusion | ||
Interrupts permit the programmer to execute code only at a defined situation and give the advantage to give the main program the most computational power while running - except a interrupt is recognized - and do not have a need for a breaking scanning routine (e. g. check all 10 cycles if button is pressed). Or the other way around interrupts gain the developer the possibility to create a power saving device which has the maximum computational power only when needed and does consume as little power as possible the rest of the time. ** | Interrupts permit the programmer to execute code only at a defined situation and give the advantage to give the main program the most computational power while running - except a interrupt is recognized - and do not have a need for a breaking scanning routine (e. g. check all 10 cycles if button is pressed). Or the other way around interrupts gain the developer the possibility to create a power saving device which has the maximum computational power only when needed and does consume as little power as possible the rest of the time. ** | ||
+ | |||
+ | Conclusion | ||
+ | |||
+ | Les interruptions permettent au programmeur de n' | ||
**Sources | **Sources | ||
If you want to download the sources instead of copy-pasting it, you can now check it out with git or an SVN client. Have a look at https:// | If you want to download the sources instead of copy-pasting it, you can now check it out with git or an SVN client. Have a look at https:// | ||
+ | |||
+ | Sources | ||
+ | |||
+ | Si vous voulez télécharger les sources plutôt que de les copier-coller, | ||
**References | **References | ||
1. pull-up and down circuitry breadboard-friendly explained, in german https:// | 1. pull-up and down circuitry breadboard-friendly explained, in german https:// | ||
+ | |||
+ | Références | ||
+ | |||
+ | 1. Circuiterie des résistances de tirage et d' | ||
**Acknowledgement | **Acknowledgement | ||
I wish to thank Evan Venn (Anobium) from the Great Cow BASIC Team for his insights and valuable hints.** | I wish to thank Evan Venn (Anobium) from the Great Cow BASIC Team for his insights and valuable hints.** | ||
+ | |||
+ | Remerciements | ||
+ | |||
+ | Je souhaite remercier Evan Venn (Anobium) de l' | ||
issue134/great_cow_basic.1531805400.txt.gz · Dernière modification : 2018/07/17 07:30 de d52fr