Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


logiciels:arduino-timer:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
logiciels:arduino-timer:accueil [2014/05/23 18:41]
resonance [Registres]
logiciels:arduino-timer:accueil [2018/01/22 11:14] (Version actuelle)
resonance ancienne révision (2016/08/13 22:08) restaurée
Ligne 14: Ligne 14:
   * **Timer 0** : pins 5 et 6  : 976.5625 Hz (8 bits > 256 values)   * **Timer 0** : pins 5 et 6  : 976.5625 Hz (8 bits > 256 values)
   * **Timer 1** : pins 9 et 10 : 490.20 Hz (16 bits > 65536 values)   * **Timer 1** : pins 9 et 10 : 490.20 Hz (16 bits > 65536 values)
-  * **Timer 2** : pins 11 et 3 : 490.20 Hz (8 bits)+  * **Timer 2** : pins 3 et 11 : 490.20 Hz (8 bits) 
 + 
 +{{http://www.gammon.com.au/images/Arduino/Timer_and_Counter_pins.jpg?600}}
  
 **Arduino MEGA** :  **Arduino MEGA** : 
-  * Les mêmes timer 01 et 3 +  * **Timer 0** : pins 4 et 13  
-  * timer 3 : pins 5, 3, 2 (16 bits) +  * **Timer 1** : pins 11 et 12 
-  * timer 4 : pins 8, 7, 6 (16 bits) +  * **Timer 2** : pins 9 et 10 
-  * timer 5 : pins 46, 45 et 44 (16 bits)+  * **Timer 3** : pins 2, 3 et 5 (16 bits) 
 +  * **Timer 4** : pins 6, 7 et 8 (16 bits) 
 +  * **Timer 5** : pins 46, 45 et 44 (16 bits) 
 + 
 +Sur une Mega, chaque Tone simultané utilisera les timers dans cet ordre : 2, 3, 4, 5, 1, 0 ([[https://books.google.fr/books?id=raHyKejOBF4C&pg=PA307#v=onepage&q&f=false|source]]) 
 + 
 +**Arduino Leonardo** (no Timer 2!) : 
 +http://provideyourown.com/2012/arduino-leonardo-versus-uno-whats-new/ 
 +The Leonardo has 7 PWM pins instead of 6. ATmega32U4 also has a new timer, timer4 which has 10 bits and uses a PLL to count at 64MHz. Their mappings are different as well: 
 +  * **Timer 0** : pins 3 et 11  : 8 bits 
 +  * **Timer 1** : pins 5, 9, 10 : 16 bits  
 +  * **Timer 2** : no 
 +  * **Timer 3** : pins 5, 9, 10 : 16 bits 
 +  * **Timer 4** : pins 6, 13 (10 bits) 
 + 
 + 
 +**Tone et Leonardo** problem :https://code.google.com/p/rogue-code/issues/detail?id=13 
 + 
 + 
 +===== PWM Frequency ===== 
 +<code> 
 +TCCR0B = TCCR0B & 0b11111000 | <setting>; //Timer 0 (PWM pins 5 & 6) 
 +TCCR1B = TCCR1B & 0b11111000 | <setting>; //Timer 1 (PWM pins 9 & 10) 
 +TCCR2B = TCCR2B & 0b11111000 | <setting>; //Timer 2 (PWM pins 3 & 11) 
 +</code>
  
 +| setting | 5 & 6 | 3,11 & 9,10 |
 +| 0x01 |62500 | 31250 |
 +| 0x02 |7812 | 3906 |
 +| 0x03 | 976 | 488 |
 +| 0x04 | 244 | 122 |
 +| 0x05 | 61 | 30 |
  
-{{http://www.gammon.com.au/images/Arduino/Timer_and_Counter_pins.jpg}} 
 ===== Tone ===== ===== Tone =====
 When you use analogOut() to create pulsewidth modulation (PWM) on an output pin, you can change the on-off ratio of the output (also known as the duty cycle) but not the frequency. If you have a speaker connected to an output pin running analogOut(), you'll get a changing loudness, but a constant tone. To change the tone, you need to change the frequency. The tone() command does this for you.  When you use analogOut() to create pulsewidth modulation (PWM) on an output pin, you can change the on-off ratio of the output (also known as the duty cycle) but not the frequency. If you have a speaker connected to an output pin running analogOut(), you'll get a changing loudness, but a constant tone. To change the tone, you need to change the frequency. The tone() command does this for you. 
Ligne 54: Ligne 85:
   * Fast PWM (ATMega328P datasheet p152-153)   * Fast PWM (ATMega328P datasheet p152-153)
   * CTC (Clear Timer on Compare Match)   * CTC (Clear Timer on Compare Match)
- 
- 
  
 ==== Fast PWM ==== ==== Fast PWM ====
Ligne 73: Ligne 102:
   * CS - Clock Select bits   * CS - Clock Select bits
   * COMnA & COMnB - Compare Match Output bits    * COMnA & COMnB - Compare Match Output bits 
- 
  
 {{:logiciels:arduino-timer:timer-ocoa.png|}} {{:logiciels:arduino-timer:timer-ocoa.png|}}
Ligne 95: Ligne 123:
  
 Target Timer Count = (Input Frequency / (Prescaler * Target Frequency)) - 1 Target Timer Count = (Input Frequency / (Prescaler * Target Frequency)) - 1
- 
  
 Target Timer Count = (16000000 / 1) -1 Target Timer Count = (16000000 / 1) -1
- 
- 
  
 Those familiar with C will know that an unsigned eight bit value can store a value from 0 to 28 − 1, Those familiar with C will know that an unsigned eight bit value can store a value from 0 to 28 − 1,
 or 255, before running out of bits to use and becoming zero again. Similarly, an unsigned 16 bit or 255, before running out of bits to use and becoming zero again. Similarly, an unsigned 16 bit
 value may store a value from 0 to 216 − 1, or 65535 before doing the same. value may store a value from 0 to 216 − 1, or 65535 before doing the same.
 +
 +==== Exemple : 20Khz ====
 +<code cpp>
 +// Réglage de la fréquence PWM du Timer 1
 +// vu sur : https://github.com/pololu/zumo-shield/blob/master/ZumoMotors/ZumoMotors.cpp
 +
 +int mypwm = 200; // réglage de test avec max = 400 ici
 +
 +void setup() {
 +  // PWM frequency calculation
 +  // 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = 20kHz
 +  TCCR1A = 0b10100000;
 +  TCCR1B = 0b00010001;
 +  ICR1 = 400; // max
 +}
 +
 +void loop() {
 +  OCR1B = mypwm; // 0-400
 +}
 +</code>
  
 ===== Interruptions ===== ===== Interruptions =====
/home/resonancg/www/wiki/data/attic/logiciels/arduino-timer/accueil.1400863309.txt.gz · Dernière modification: 2014/05/23 18:41 de resonance