issue134:great_cow_basic
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue134:great_cow_basic [2018/07/01 14:57] – créée auntiee | 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.** |
- | Interrupt service routines | + | Dans le n° 131 du FCM, je vous ai montré comment reconnaître l' |
- | 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 | + | **Interrupt |
- | 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: | + | 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: | ||
• if the level on PIN is low, | • if the level on PIN is low, | ||
• any logical change, | • any logical change, | ||
• 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). |
- | 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. | + | 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 following page (top left) shows a small pull-up version of an INT0 service routine in Great Cow BASIC. | The following page (top left) shows a small pull-up version of an INT0 service routine in Great Cow BASIC. | ||
- | 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.** |
- | Debouncing the button presses | + | 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 | ||
In addition you might not change the state of the LED everytime the interrupt occurs, because the switch could be bouncing or the signal quality is poor. Therefore you could add a simple debouncing algorithm. An example for the pull-up version with the INT0 interrupt in Great Cow BASIC is shown, page after next, top left. | In addition you might not change the state of the LED everytime the interrupt occurs, because the switch could be bouncing or the signal quality is poor. Therefore you could add a simple debouncing algorithm. An example for the pull-up version with the INT0 interrupt in Great Cow BASIC is shown, page after next, top left. | ||
- | 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:** |
- | Breadboard circuitry | + | Anti-rebond sur les appuis du bouton |
+ | |||
+ | En plus, vous ne voudriez peut-être pas changer l' | ||
+ | |||
+ | Et la routine d' | ||
+ | |||
+ | **Breadboard circuitry | ||
For the test with the internal pull-ups activated you would need an LED, a switch and the microcontroller (circuit on next page, bottom left). Connect one end of the switch to PIN 6 (PB.1) and the other to PIN 4 (GND). The anode of the LED goes to PIN 5 (PB0) and the cathode of the LED goes to PIN 4 (GND). After flashing the hex-file and connecting the power supply the LED should go on and off after pressing the switch. | For the test with the internal pull-ups activated you would need an LED, a switch and the microcontroller (circuit on next page, bottom left). Connect one end of the switch to PIN 6 (PB.1) and the other to PIN 4 (GND). The anode of the LED goes to PIN 5 (PB0) and the cathode of the LED goes to PIN 4 (GND). After flashing the hex-file and connecting the power supply the LED should go on and off after pressing the switch. | ||
- | 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 | ||
+ | |||
+ | 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 | Conclusion | ||
- | Interrupts permit the programmer to execute | + | Les interruptions permettent au programmeur de n' |
+ | |||
+ | **Sources | ||
+ | |||
+ | If you want to download | ||
Sources | Sources | ||
- | If you want to download the sources | + | Si vous voulez télécharger les sources |
+ | |||
+ | **References | ||
+ | |||
+ | 1. pull-up and down circuitry breadboard-friendly explained, in german https:// | ||
+ | |||
+ | Références | ||
+ | |||
+ | 1. Circuiterie des résistances de tirage et d' | ||
- | References | + | **Acknowledgement |
- | 1. pull-up | + | I wish to thank Evan Venn (Anobium) from the Great Cow BASIC Team for his insights |
- | Acknowledgement | + | Remerciements |
- | I wish to thank Evan Venn (Anobium) | + | Je souhaite remercier |
issue134/great_cow_basic.1530449871.txt.gz · Dernière modification : 2018/07/01 14:57 de auntiee