issue129: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 | ||
issue129:great_cow_basic [2018/02/03 08:37] – d52fr | issue129:great_cow_basic [2018/02/05 09:53] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**Correction: | **Correction: | ||
+ | |||
+ | Correction : Dans l' | ||
Ligne 7: | Ligne 9: | ||
In the previous example we learned that a microcontroller can understand if a switch (or any other device) is ‘ON’ (operating at between 3/5V) or ‘OFF’ (operating at 0V) because of its digital nature, but how will the microcontroller know that a voltage is somehow in between (e.g. at 2.3 Volts)? We can use the inbuilt analog to digital conversion of the attiny13a. Besides controlling the microcontroller within the source code, this will be the first time the microcontroller can be controlled from the outside world.** | In the previous example we learned that a microcontroller can understand if a switch (or any other device) is ‘ON’ (operating at between 3/5V) or ‘OFF’ (operating at 0V) because of its digital nature, but how will the microcontroller know that a voltage is somehow in between (e.g. at 2.3 Volts)? We can use the inbuilt analog to digital conversion of the attiny13a. Besides controlling the microcontroller within the source code, this will be the first time the microcontroller can be controlled from the outside world.** | ||
+ | |||
+ | Dans le dernier numéro, je vous ai présenté les modulations de largeur d' | ||
+ | |||
+ | Cette fois, je vous montrerai comment vous pouvez régler la luminosité de la LED ou la vitesse du PWM en la contrôlant avec un potentiomètre. Pour une bonne explication en français sur le potentiomètre, | ||
+ | |||
+ | Dans l' | ||
**Analog to digital conversion | **Analog to digital conversion | ||
Ligne 13: | Ligne 21: | ||
For the actual purpose I will use the single conversion mode of the ADC at the 8-bit resolution. This is precise enough, because the duty cycle of the PWM has the same resolution of 8-bit (values range from 0 - 255) so I do not need to map a higher to a lower resolution. Second I will use a medium frequency to measure the voltage; the higher the frequency the measurement takes place the more inaccurate the readings are. In 8-bit resolution every ADC value corresponds to a voltage level (ADC value = Volt255). If the microcontroller is powered at 5 V the measurement would read around 0.0196 mV per step. Powering it at 3 V the readings for each step would be around 0.0117 mV. See the table below for some arbitrary values.** | For the actual purpose I will use the single conversion mode of the ADC at the 8-bit resolution. This is precise enough, because the duty cycle of the PWM has the same resolution of 8-bit (values range from 0 - 255) so I do not need to map a higher to a lower resolution. Second I will use a medium frequency to measure the voltage; the higher the frequency the measurement takes place the more inaccurate the readings are. In 8-bit resolution every ADC value corresponds to a voltage level (ADC value = Volt255). If the microcontroller is powered at 5 V the measurement would read around 0.0196 mV per step. Powering it at 3 V the readings for each step would be around 0.0117 mV. See the table below for some arbitrary values.** | ||
+ | |||
+ | La conversion analogique/ | ||
+ | |||
+ | Le attiny13a dispose d'une conversion analogique/ | ||
+ | |||
+ | Pour le besoin présent, j' | ||
Ligne 21: | Ligne 35: | ||
This works of course with the hardware PWM variants of the previous article, I have not included the PWM variants out to streamline this article. ** | This works of course with the hardware PWM variants of the previous article, I have not included the PWM variants out to streamline this article. ** | ||
+ | |||
+ | Le pilotage de la LED | ||
+ | |||
+ | Pour piloter la LED avec le potentiomètre, | ||
+ | |||
+ | Ceci fonctionne, bien sûr, avec les variantes du PWM matériel de l' | ||
Ligne 28: | Ligne 48: | ||
I prefer to have PIN 8 (VCC) on the upper left hand corner of the breadboard. The potentiometer should have three terminals, place the potentiometer: | I prefer to have PIN 8 (VCC) on the upper left hand corner of the breadboard. The potentiometer should have three terminals, place the potentiometer: | ||
+ | |||
+ | Le circuit sur la plaque d' | ||
+ | |||
+ | Je présume que vous avez flashé le programme sur le microcontrôleur avec votre programmateur préféré ou un Arduino comme ISP. Maintenant, pour tester le programme, placez le attiny13a n' | ||
+ | |||
+ | Je préfère avoir la borne 8 (VCC) tout en haut à gauche de la plaque. Le potentiomètre devrait avoir trois bornes. Posez le potentiomètre avec les connexions vers vous. Commencez les connexions de la gauche vers la droite ; la première va à la masse, la seconde à la borne 3 (PB4) du microcontrôleur et la troisième va sur la tension positive de l' | ||
**Conclusion | **Conclusion | ||
Ligne 33: | Ligne 59: | ||
Reading analog values is a very useful function of the microcontroller and there are many possible uses for it. Besides reading a potentiometer you could e. g. measure the systems battery status and implement a draining protection for your systems battery. As an exercise you could expand the code to not only control the brightness of the LED but also the length of the pauses. In the next article we will experiment further with the analog digital conversion and see if we can print out the measured values to the serial console.** | Reading analog values is a very useful function of the microcontroller and there are many possible uses for it. Besides reading a potentiometer you could e. g. measure the systems battery status and implement a draining protection for your systems battery. As an exercise you could expand the code to not only control the brightness of the LED but also the length of the pauses. In the next article we will experiment further with the analog digital conversion and see if we can print out the measured values to the serial console.** | ||
+ | Conclusion | ||
+ | |||
+ | La lecture de valeurs analogiques est une fonction très utile d'un microcontrôleur et il y a de nombreuses utilisations de celle-ci. Outre la lecture d'un potentiomètre, | ||
**References | **References | ||
Ligne 39: | Ligne 68: | ||
ADC code optimisation http:// | ADC code optimisation http:// | ||
+ | |||
+ | Références | ||
+ | |||
+ | Explication approfondie de l'ADC : http:// | ||
+ | |||
+ | Optimisation du code de l'ADC : http:// | ||
Ligne 49: | Ligne 84: | ||
Also thanks to Bernd Dau for the hint with wrong file sizes.** | Also thanks to Bernd Dau for the hint with wrong file sizes.** | ||
+ | |||
+ | Remerciements | ||
+ | |||
+ | Je souhaite remercier Evan Venn (Anobium) de l' | ||
+ | |||
+ | Merci aussi à Bernd Dau pour sa remarque sur les tailles de fichiers erronés. | ||
issue129/great_cow_basic.1517643453.txt.gz · Dernière modification : 2018/02/03 08:37 de d52fr