issue138:greatcowbasic
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue138:greatcowbasic [2018/10/27 14:20] – créée auntiee | issue138:greatcowbasic [2018/11/12 12:11] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | In FCM#136, I showed you how to use the analog to digital conversion (ADC) with a light-dependent resistor (LDR) to gather information about the ambient brightness and how to communicate to a remote device at distance. | + | **In FCM#136, I showed you how to use the analog to digital conversion (ADC) with a light-dependent resistor (LDR) to gather information about the ambient brightness and how to communicate to a remote device at distance. |
- | 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. |
- | Introducing the Watchdog timer | + | 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 les transmettre à un dispositif éloigné. |
+ | |||
+ | 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 | ||
Imagine a situation where you program a microcontroller for a critical system. You would not just rely on the reliability of the software to avoid damage, would you? | Imagine a situation where you program a microcontroller for a critical system. You would not just rely on the reliability of the software to avoid damage, would you? | ||
- | 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 de la minuterie du watchdog | ||
+ | |||
+ | Imaginez une situation où vous programmez un microcontrôleur pour un système critique. Vous ne compteriez pas uniquement sur la fiabilité | ||
+ | |||
+ | Un logiciel peut toujours contenir des défauts, ou, peut-être, certaines conditions environnementales peuvent se produire auxquelles vous n' | ||
- | 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.** |
- | LED flasher with the watchdog timer | + | 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 | ||
The WDT needs a timed sequence, without interruptions, | The WDT needs a timed sequence, without interruptions, | ||
Ligne 26: | 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). ** |
- | Powersave modes | + | Un clignotant à LED avec la minuterie du watchdog |
- | 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 | + | Le WDT a besoin d'une séquence minutée, sans interruption, |
+ | • D' | ||
+ | • Remettez à zéro le WDT. | ||
+ | • Le registre des modifications du watchdog | ||
+ | • Activez le watchdog et réglez le prédiviseur de la minuterie du watchdog. | ||
- | Energy efficient transmitter | + | 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 | ||
+ | |||
+ | 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 | ||
Let’s extend the code from the last issue and use the power-save mode, and the watchdog timer to pause the transmission. The microcontroller takes around 64 ms to start, then we set the watchdog timer. After this, the program sends the LDR values over the air. The transmission itself now takes around 48 ms. The former version of the program waits 8 s without doing anything – but still consumes power! | Let’s extend the code from the last issue and use the power-save mode, and the watchdog timer to pause the transmission. The microcontroller takes around 64 ms to start, then we set the watchdog timer. After this, the program sends the LDR values over the air. The transmission itself now takes around 48 ms. The former version of the program waits 8 s without doing anything – but still consumes power! | ||
- | 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. |
Here is the logged data from the serial line, with the new receiver in place, and the new software version on the microcontroller. The result (next page, top right) is good (see time 00:13:01 for the first dataset and 00:13:09 for the second dataset, as highlighted in black). | Here is the logged data from the serial line, with the new receiver in place, and the new software version on the microcontroller. The result (next page, top right) is good (see time 00:13:01 for the first dataset and 00:13:09 for the second dataset, as highlighted in black). | ||
- | 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. |
- | Breadboard circuitry | + | 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 | ||
The transmitter part is exactly the same as in the last issue, so I omit depicting it here again. The transmitter has two extra PINs to connect (than the former device): | The transmitter part is exactly the same as in the last issue, so I omit depicting it here again. The transmitter has two extra PINs to connect (than the former device): | ||
- | 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, |
- | Conclusion | + | 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 | ||
The initial simple receiver module I got (without too deep research on the subject) did its job for our first experiments, | The initial simple receiver module I got (without too deep research on the subject) did its job for our first experiments, | ||
- | 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 | ||
+ | |||
+ | 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 | Sources | ||
- | If you want to download the sources | + | Si vous voulez télécharger les sources |
- | References | + | **References |
The AVR watchdog timer explained http:// | The AVR watchdog timer explained http:// | ||
Ligne 78: | Ligne 143: | ||
RXB8 Datasheet | RXB8 Datasheet | ||
+ | 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:// | https:// | ||
+ | **Acknowledgement | ||
+ | |||
+ | I wish to thank Evan Venn (Anobium) from the Great Cow BASIC Team for his insights and valuable hints.** | ||
- | Acknowledgement | + | Remerciements |
- | I wish to thank Evan Venn (Anobium) | + | Je souhaite remercier |
issue138/greatcowbasic.1540642832.txt.gz · Dernière modification : 2018/10/27 14:20 de auntiee