Ligne 19 : |
Ligne 19 : |
| | | |
| == Utiliser un Timer == | | == Utiliser un Timer == |
− | Let’s create a timer object:
| + | Commecons par créer un objet timer: |
| | | |
| <nowiki>>>> tim = pyb.Timer(4)</nowiki> | | <nowiki>>>> tim = pyb.Timer(4)</nowiki> |
| | | |
− | Now let’s see what we just created:
| + | Voyons maintenant l'objet que nous venons juste de créer: |
| | | |
| <nowiki>>>> tim | | <nowiki>>>> tim |
| Timer(4)</nowiki> | | Timer(4)</nowiki> |
| | | |
− | The pyboard is telling us that {{fname|tim}} is attached to timer number 4, but it’s not yet initialised. So let’s initialise it to trigger at 10 Hz (that’s 10 times per second):
| + | La carte PyBoard nous informe que {{fname|tim}} est attaché au ''timer'' numéro 4 mais il n'est pas encore initialisé. Donc, initialisons le pour un déclenchement (''to trigger'' en anglais) à 10 Hz (soit 10 fois par seconde): |
| | | |
| <nowiki>>>> tim.init(freq=10)</nowiki> | | <nowiki>>>> tim.init(freq=10)</nowiki> |
| | | |
− | Now that it’s initialised, we can see some information about the timer:
| + | Analysons maintenant ce que nous pouvons vois dans les informations du ''timer'': |
| | | |
| <nowiki>>>> tim | | <nowiki>>>> tim |
| Timer(4, prescaler=624, period=13439, mode=UP, div=1)</nowiki> | | Timer(4, prescaler=624, period=13439, mode=UP, div=1)</nowiki> |
| | | |
− | The information means that this timer is set to run at the peripheral clock speed divided by 624+1, and it will count from 0 up to 13439, at which point it triggers an interrupt, and then starts counting again from 0. These numbers are set to make the timer trigger at 10 Hz: the source frequency of the timer is 84MHz (found by running {{fname|tim.source_freq()}}) so we get 84MHz / 625 / 13440 = 10Hz.
| + | Ces informations signifie que le ''timer'' est configuré pour fonctionner avec l'horloge matérielle divisé par 624+1, et qu'il comptera de 0 à 13439... point auquel il déclenche une interruption puis il recommence à compter depuis 0. Ces nombres sont utilisé pour déclencher le ''timer'' à 10 Hz. |
| + | |
| + | La fréquence source du ''timer'' est de 84MHz (résultat de la commande {{fname|tim.source_freq()}}) par conséquent nous obtenons 84.000.000 Hz / 625 / 13440 = 10 Hz. |
| | | |
| == Compteur du Timer == | | == Compteur du Timer == |