issue138:greatcowbasic
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 | ||
issue138:greatcowbasic [2018/11/10 09:02] – d52fr | issue138:greatcowbasic [2018/11/12 12:11] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
The reception with the standard receiver was bad, so I did some research, and ordered another receiver-module to improve the reception, it is called “RXB8 V2.0” and came at a reasonable price. | The reception with the standard receiver was bad, so I did some research, and ordered another receiver-module to improve the reception, it is called “RXB8 V2.0” and came at a reasonable price. | ||
- | Dans le FCM n° 136, je vous ai montré comment utiliser la conversion analogique-numérique (ADC) avec une photorésistance (LDR) pour obtenir des informations sur la luminosité ambiante et comment | + | Dans le FCM n° 136, je vous ai montré comment utiliser la conversion analogique-numérique (ADC) avec une photorésistance (LDR) pour obtenir des informations sur la luminosité ambiante et comment |
- | La réception était mauvaise avec le récepteur ordinaire ; aussi, j'ai effectué quelques recherches et commandé un autre module de réception pour l' | + | La réception était mauvaise avec le récepteur ordinaire ; aussi, j'ai effectué quelques recherches et commandé un autre module de réception pour l' |
**Introducing the Watchdog timer | **Introducing the Watchdog timer | ||
Ligne 13: | Ligne 13: | ||
Software can always contain bugs, or maybe some environmental conditions arise that you did not think of in the first place. So, it would be important to restart the microcontroller to its initial state if something goes wrong. In such situations you surely will use the watchdog timer, which can restart the microcontroller completely. With respect to low ressources, another use case of the watchdog timer would be to implement a power saving mode to save battery life. The device drains as little battery as possible (whilst sleeping) and can then use the watchdog timer to wake up. So how does the watchdog timer (WDT) work internally? | Software can always contain bugs, or maybe some environmental conditions arise that you did not think of in the first place. So, it would be important to restart the microcontroller to its initial state if something goes wrong. In such situations you surely will use the watchdog timer, which can restart the microcontroller completely. With respect to low ressources, another use case of the watchdog timer would be to implement a power saving mode to save battery life. The device drains as little battery as possible (whilst sleeping) and can then use the watchdog timer to wake up. So how does the watchdog timer (WDT) work internally? | ||
- | Présentation du watchdog | + | Présentation |
- | Imaginez une situation où vous programmez un microcontrôleur pour un système critique. | + | Imaginez une situation où vous programmez un microcontrôleur pour un système critique. |
- | Un logiciel peut toujours contenir des défauts, ou, peut-être, certaines conditions | + | Un logiciel peut toujours contenir des défauts, ou, peut-être, certaines conditions |
**The watchdog timer has a separate on-chip oscillator working at 128 KHz which works as a overflow timer. Thru a prescaler, you can set the time when the overflow occurs. The WDT can operate in three modes: interrupt, system reset or interrupt and system reset: | **The watchdog timer has a separate on-chip oscillator working at 128 KHz which works as a overflow timer. Thru a prescaler, you can set the time when the overflow occurs. The WDT can operate in three modes: interrupt, system reset or interrupt and system reset: | ||
• The interrupt mode can be used to wake up the device, or to timeout operations that last too long. | • The interrupt mode can be used to wake up the device, or to timeout operations that last too long. | ||
• The system reset mode is quite self-explanatory, | • The system reset mode is quite self-explanatory, | ||
- | • The remaining mode combines the aforementioned ones, the interrupt occurs and you can implement a routine where you save your data or send some debugging information (eg, over the UART), and then the system is reset. | + | • The remaining mode combines the aforementioned ones, the interrupt occurs and you can implement a routine where you save your data or send some debugging information (eg, over the UART), and then the system is reset. |
- | **The WDT can be activated in two ways: | + | The WDT can be activated in two ways: |
• By setting a hardware fuse (WDTON): in this mode the WDT is set to ‘system reset’ mode and cannot be changed or switched off by software on the fly. Only the overflow of the WDT can be prevented by resetting it. | • By setting a hardware fuse (WDTON): in this mode the WDT is set to ‘system reset’ mode and cannot be changed or switched off by software on the fly. Only the overflow of the WDT can be prevented by resetting it. | ||
• The WDT can be activated by software: then all three modes can be used. For the ATtiny13a, different timings can be set (to trigger overflow). For this article we need to know only two timing options.** | • The WDT can be activated by software: then all three modes can be used. For the ATtiny13a, different timings can be set (to trigger overflow). For this article we need to know only two timing options.** | ||
+ | |||
+ | La minuterie du watchdog a un oscillateur séparé, intégré à la puce, tournant à 128 kHz, qui fonctionne comme une minuterie de dépassement. Par l' | ||
+ | • Le mode par interruption peut être utilisé pour réveiller le dispositif ou pour arrêter des opérations qui durent trop longtemps. | ||
+ | • Le mode par remise à zéro du système se comprend de lui-même ; le dispositif est redémarré sans autre avertissement et toutes les données volatiles sont perdues. | ||
+ | • Le dernier mode combine les deux précédents ; l' | ||
+ | |||
+ | Le WDT peut être activé de deux manières : | ||
+ | • En installant un fusible matériel (WDTON) : dans ce mode, le WDT est réglé sur « remise à zéro du système » (system reset) et ne peut pas être modifié ou arrêté à la volée par logiciel. Seul le dépassement du WDT peut être empêché en le remettant à zéro. | ||
+ | • Le WDT peut être activé par un logiciel : dans ce cas, les trois modes sont disponibles. Pour le ATtiny13a, différentes durées peuvent être réglées (pour déclencher le dépassement). Dans cet article, nous n' | ||
**LED flasher with the watchdog timer | **LED flasher with the watchdog timer | ||
Ligne 36: | Ligne 45: | ||
• Enable the watchdog and set the prescaler of the watchdog timer. | • Enable the watchdog and set the prescaler of the watchdog timer. | ||
- | Compile the code shown right and upload it to the ATtiny13a, connect a LED to PortB.1, and see what happen. | + | Compile the code shown right and upload it to the ATtiny13a, connect a LED to PortB.1, and see what happen. |
- | **The program starts, the LED is turned on and activates the WDT. After 64 ms the microcontroller restarts. | + | The program starts, the LED is turned on and activates the WDT. After 64 ms the microcontroller restarts. |
The ‘boot time’ by default is about 64 ms according to the factory default. In this setup, the microcontroller is just reset - no power-save mode is used just yet. The LED flashes relatively fast because of the short time the LED is set to on (64 ms). ** | The ‘boot time’ by default is about 64 ms according to the factory default. In this setup, the microcontroller is just reset - no power-save mode is used just yet. The LED flashes relatively fast because of the short time the LED is set to on (64 ms). ** | ||
+ | |||
+ | Un clignotant à LED avec la minuterie du watchdog | ||
+ | |||
+ | Le WDT a besoin d'une séquence minutée, sans interruption, | ||
+ | • D' | ||
+ | • Remettez à zéro le WDT. | ||
+ | • Le registre des modifications du watchdog (WDTCR) doit être positionné sur un 1 logique dans le bit d' | ||
+ | • Activez le watchdog et réglez le prédiviseur de la minuterie du watchdog. | ||
+ | |||
+ | Compilez le code présenté à droite et téléversez-le dans le ATtiny13a, connectez une LED sur le PortB.1, et regardez ce qui se passe. | ||
+ | |||
+ | Le programme démarre, la LED s' | ||
+ | |||
+ | Le temps de démarrage (boot time) par défaut est d' | ||
**Powersave modes | **Powersave modes | ||
The ATTiny13a has three different power-save modes, each of them with more or less power consumption. In sequence by power-consumption (from highest to lowest) they are: Idle, ADC Noise Reduction and Power-down. The choice depends on the situation, and what you want to achieve with your device. For now, we’ll use power-down mode. The other sleep modes will be explained in a further article, when they are needed. To get an idea how low the power consumption can be, have a look at the site of Nick Gammon (Ref. No. 5), he did some measures for us.** | The ATTiny13a has three different power-save modes, each of them with more or less power consumption. In sequence by power-consumption (from highest to lowest) they are: Idle, ADC Noise Reduction and Power-down. The choice depends on the situation, and what you want to achieve with your device. For now, we’ll use power-down mode. The other sleep modes will be explained in a further article, when they are needed. To get an idea how low the power consumption can be, have a look at the site of Nick Gammon (Ref. No. 5), he did some measures for us.** | ||
+ | |||
+ | Modes d' | ||
+ | |||
+ | Le ATtiny13a a trois modes différents d' | ||
**Energy efficient transmitter | **Energy efficient transmitter | ||
Ligne 51: | Ligne 78: | ||
Here (next page, shown right) is how we optimize this by using the power-down sleep mode, and the watchdog timer.** | Here (next page, shown right) is how we optimize this by using the power-down sleep mode, and the watchdog timer.** | ||
+ | |||
+ | Transmetteur économe en énergie | ||
+ | |||
+ | Complétons le code du dernier numéro et utilisons le mode d' | ||
+ | |||
+ | Voici (page suivante, à droite) comment nous optimisons ceci en utilisant le mode de mise en sommeil par coupure de l' | ||
**On the first start after the microcontroller gets power, the microcontroller is initialised. Then the watchdog timer is set to the reset mode, and the main program measures the LDR and sends the data over the transmitter. Then all of the Timer and the ADC get switched off, and the sleep mode power-down is enabled. After that the microcontroller is sent to sleep. After 8 seconds it gets a restart, and so the same procedure gets repeated every 8 second. | **On the first start after the microcontroller gets power, the microcontroller is initialised. Then the watchdog timer is set to the reset mode, and the main program measures the LDR and sends the data over the transmitter. Then all of the Timer and the ADC get switched off, and the sleep mode power-down is enabled. After that the microcontroller is sent to sleep. After 8 seconds it gets a restart, and so the same procedure gets repeated every 8 second. | ||
Ligne 57: | Ligne 90: | ||
Only a minimum of garbage is received, so a data logging program could easily pick up the lines with the wanted data and safely omit the unwanted bytes. ** | Only a minimum of garbage is received, so a data logging program could easily pick up the lines with the wanted data and safely omit the unwanted bytes. ** | ||
+ | |||
+ | Au premier démarrage après la mise sous tension du microcontrôleur, | ||
+ | |||
+ | Voici un enregistrement des données sur la ligne série, avec le nouveau récepteur en activité, et la nouvelle version du programme dans le microcontrôleur. Le résultat (page suivante, en haut à droite) est bon (voir les instants 00:13:01 pour les premières données et 00:13:09 pour les secondes données, surlignées en noir). | ||
+ | |||
+ | Un minimum de déchet est reçu ; ainsi, un programme d' | ||
**Breadboard circuitry | **Breadboard circuitry | ||
Ligne 63: | Ligne 102: | ||
On the left side, there is a connector for the antenna (a wire ~ 17 cm is sufficient) and GND. On the right side, there are GND, DATA and Vcc (+5V). Both GND can be connected with a Y-wire to the same GND. The DATA pin goes to the Rx-Connector of the serial-to-usb-converter. Due to the shape of the new transmitter, | On the left side, there is a connector for the antenna (a wire ~ 17 cm is sufficient) and GND. On the right side, there are GND, DATA and Vcc (+5V). Both GND can be connected with a Y-wire to the same GND. The DATA pin goes to the Rx-Connector of the serial-to-usb-converter. Due to the shape of the new transmitter, | ||
+ | |||
+ | Circuit sur la plaque d' | ||
+ | |||
+ | La partie émetteur est exactement la même que dans le dernier article ; aussi, je me passe de la décrire à nouveau. Deux picots supplémentaires (par rapport au dispositif précédent) sont à connecter sur le récepteur : | ||
+ | |||
+ | Sur la partie gauche, il y a un connecteur pour l' | ||
**Conclusion | **Conclusion | ||
Ligne 69: | Ligne 114: | ||
The newer program saves power, and, because some lines of code have been saved too, it has a little extra free space on the microcontroller for further optimisation and other ideas. For the next issue, I plan to prepare a little data logger program on the PC side, and expand the transmitter software to send data in larger time frames, and to gather some real life values.** | The newer program saves power, and, because some lines of code have been saved too, it has a little extra free space on the microcontroller for further optimisation and other ideas. For the next issue, I plan to prepare a little data logger program on the PC side, and expand the transmitter software to send data in larger time frames, and to gather some real life values.** | ||
+ | |||
+ | Conclusion | ||
+ | |||
+ | Le module récepteur simple que j' | ||
+ | |||
+ | Le nouveau programme économise l' | ||
**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 goo.gl/ | 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 goo.gl/ | ||
+ | |||
+ | Sources | ||
+ | |||
+ | Si vous voulez télécharger les sources au lieu de les copier/ | ||
**References | **References | ||
Ligne 90: | Ligne 145: | ||
https:// | https:// | ||
+ | Références | ||
+ | |||
+ | La minuterie de watchdog AVR expliquée http:// | ||
+ | |||
+ | Note d' | ||
+ | http:// | ||
+ | |||
+ | Calculateur de fusibles avec une information globale sur les valeurs d' | ||
+ | http:// | ||
+ | |||
+ | Inspiration pour un code initial simple | ||
+ | https:// | ||
+ | |||
+ | Éléments mathématiques pour économiser l' | ||
+ | https:// | ||
+ | |||
+ | Notice technique du RXX88 | ||
+ | https:// | ||
**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' | ||
issue138/greatcowbasic.1541836928.txt.gz · Dernière modification : 2018/11/10 09:02 de d52fr