issue129: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 | ||
| issue129:great_cow_basic [2018/01/27 12:48] – créée auntiee | issue129:great_cow_basic [2018/02/05 09:53] (Version actuelle) – auntiee | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | **Correction: | ||
| + | Correction : Dans l' | ||
| - | Correction: In the previous article I compared the compiled file sizes, the given sizes are in Byte, not in KByte. My apologies for this inaccuracy. | ||
| - | + | **In the last issue I introduced you to the software and hardware pulse width modulation (PWM) to dim a LED. And in the first examples we needed not much hardware than the microcontroller, | |
| - | In the last issue I introduced you to the software and hardware pulse width modulation (PWM) to dim a LED. And in the first examples we needed not much hardware than the microcontroller, | + | |
| This time I will show you how you can set the brightness of the LED or the speed of the PWM by controlling it with a potentiometer. | This time I will show you how you can set the brightness of the LED or the speed of the PWM by controlling it with a potentiometer. | ||
| - | 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.** | 
| - | Analog to digital conversion | + | 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 | ||
| The attiny13a features a 10-bit successive approximation analog to digital conversion (ADC), which means, that the input voltage is repeatedly compared to a reference voltage until the input and the reference voltage are nearly equal. The attiny13a has 4 multiplexed ADC channel (PIN PB2-5), each one can be used independently to measure voltages. For the moment we leave out some special functions such as free running mode, start ADC on interrupt or trigger an interrupt after conversion. The datasheet of the attiny13a has detailed information about this topic, but Great Cow BASIC has got you covered, so that using the ADC can be done quite easily. | The attiny13a features a 10-bit successive approximation analog to digital conversion (ADC), which means, that the input voltage is repeatedly compared to a reference voltage until the input and the reference voltage are nearly equal. The attiny13a has 4 multiplexed ADC channel (PIN PB2-5), each one can be used independently to measure voltages. For the moment we leave out some special functions such as free running mode, start ADC on interrupt or trigger an interrupt after conversion. The datasheet of the attiny13a has detailed information about this topic, but Great Cow BASIC has got you covered, so that using the ADC can be done quite easily. | ||
| - | 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/ | ||
| - | Controlling the LED | + | Le attiny13a dispose d'une conversion analogique/ | 
| + | |||
| + | Pour le besoin présent, j' | ||
| + | |||
| + | |||
| + | **Controlling the LED | ||
| To control the LED with the potentiometer I will expand the software PWM code to read the analog value of the potentiometer and set the brightness accordingly. | To control the LED with the potentiometer I will expand the software PWM code to read the analog value of the potentiometer and set the brightness accordingly. | ||
| - | 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 | ||
| - | Breadboard circuitry | + | Pour piloter la LED avec le potentiomètre, | 
| + | |||
| + | Ceci fonctionne, bien sûr, avec les variantes du PWM matériel de l' | ||
| + | |||
| + | |||
| + | **Breadboard circuitry | ||
| I assume that you flashed the program to the microcontroller with your preferred programmer or an Arduino as ISP. To try out the program now place the attiny13a somewhere in the middle of a breadboard so that the upper and the lower side are placed above and under the middle line of the breadboard. | I assume that you flashed the program to the microcontroller with your preferred programmer or an Arduino as ISP. To try out the program now place the attiny13a somewhere in the middle of a breadboard so that the upper and the lower side are placed above and under the middle line of the breadboard. | ||
| - | 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: | 
| - | Conclusion | + | Le circuit sur la plaque d' | 
| - | 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. | + | 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' | ||
| - | References | + | **Conclusion | 
| + | |||
| + | 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 | ||
| In depth explanation of the ADC	http:// | In depth explanation of the ADC	http:// | ||
| - | ADC code optimisation	http:// | + | ADC code optimisation	http:// | 
| + | Références | ||
| + | Explication approfondie de l'ADC : http:// | ||
| + | Optimisation du code de l'ADC : http:// | ||
| - | 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. | ||
| - | 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.1517053711.txt.gz · Dernière modification : 2018/01/27 12:48 de auntiee
                
                