Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
fr:examples:timer:hardware_delay [2010/03/09 13:36] sdeniaudfr:examples:timer:hardware_delay [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 11: Line 11:
 [{{  :examples:timer:timer_counter.png?300|Les évenements qui correspondent au changement du //timer// AVR.}}] [{{  :examples:timer:timer_counter.png?300|Les évenements qui correspondent au changement du //timer// AVR.}}]
  
-Les compteurs AVR counters can be made to inform about overflow of the counter or achieving compare machOverflow happens when the counter has the maximal possible value and the cycle starts all over again form 0. With reaching a pre set value during the moment of growth of the counter’s value it is compared to the value given by the userOn the occurrence of the eventthe bits in the status indexes of the AVR are automatically set as high +Les compteurs AVR peuvent être utilisés pour informer d'un franchissement de limite ou pour atteindre une valeur de comparaisonLe franchissement de la limite est atteint lorsque la valeur du compteur arrive à sa valeur maximale, dans ce cas le cycle redémarre à 0. Pendant l'incrémentation du compteur, chacune des valeurs du compteur sont comparées à la valeur objectif pré-configurée par l'utilisateurLorsque ces conditions sont rempliesle bit des indexes de statut correspondants sont automatiquement configurés en position haute.
    
-For generating a delay using a timer, it is only necessary to set the timer and waiting for the status bit to go highDifferent from the software delaythe work of the timer is not depending on the compilerwhich makes them more reliable. At the same time the diversity (or complexity) of the set-up of the AVR counter can be considered fairly troublesome. Depending on the microcontroller’s timing signal, may happen that it will not divide exactly with the desired delay period and the delay will not be accurate.  +Pour réaliser une temporisation en utilisant un //timer//il suffit d'initialiser le //timer// et d'attendre que le bit de statut passe en position hauteCela est différent dans le cas de la temporisation logicielle travail du //timer// ne dépend pas du compilateurce qui le rend plus fiable. At the same time the diversity (or complexity) of the set-up of the AVR counter can be considered fairly troublesome. Depending on the microcontroller’s timing signal, may happen that it will not divide exactly with the desired delay period and the delay will not be accurate.  
  
-===== Practice ===== +===== Pratique =====
-The program code below is a delay function based on a timer, which is simplified a little bit. The principle of counting is the same as it is at software delay function – a desired amount of 1 ms long delays are produced. The delay is produced with an 8-bit ATmega 128 counter 0. It is calculated previously that at clock frequency 14,7456 Mhz the timing signal has to be divided at least 64 times, so that the counter would not reach to overflow in 1 ms. The value which the counter must have so that the overflow occurs after 1 ms is presented in the form of an expression and the variable is //timer_start//. //F_CPU// which is a constant in macro-language, that shows clock frequency in Hz. The clock frequency should be 25,6 at the moment but since fractions can not be used, the initial value will be set 26. Unfortunately here arises a mistake in delay time, however it is fairly small (-1,7 μs). +
  
-In the cycle takes place initialing of the counter and zeroing the flag of the overflow (by writing into that). Then is waited until the counter counts to 256 from the initial value, i.e. to the overflowAt the moment of the overflow the flag goes high and the delay of 1 ms has taken placeIn the end of the function the timer is stopped      +Le code du programme ci-dessous est une fonction de temporisation basée sur un //timer// simplifié. Le principe de comptage est le même que celui d'une fonction de temporisation logicielle – on fabrique une temporisation de longueur 1ms. La temporisation est réalisée avec un compteur 0 de ATmega 128 avec 8-bits. Il à été calculé précédemment que la fréquence de l'horloge est de 14,7456 Mhz le signal de temps doit être divisé 64 fois, donc le compteur ne pourra pas dépasser la limite de 1ms. La valeur que doit prendre le compteur est présenté sous la forme d'une expression dont la variable est ''timer_start''. ''F_CPU'' qui est une constante en langage macro, renvoi la fréquence de l'horloge en Hz. La fréquence de l'horloge doit être 25,6 pour le moment mais depuis qu'on ne peut plus utiliser les valeurs décimales, la valeur initiale sera 26. Malheureusement il survient une erreur dans le temps de la temporisation, qui peut être cependant négligeable (-1,7 μs).  
 + 
 +Dans le cycle on retrouve l'initialisation du compteur et la mise à zéro de la limite (en inscrivant 1). Puis il attend que le compteur atteigne la valeur 256 en partant de la valeur initiale, i.e. par rapport à la limiteA ce moment la balise prend une valeur haute et 1 ms est passéeA la fin de la fonction le //timer// est arrêté.
  
  
Line 57: Line 58:
 </code> </code>
  
-The following is a similar program to the example of the software delayIn the shorter 100 ms half-period the LED is lit and on the longer 900 ms half-period it is switched offAs the result the LED is blinking after every secondUnfortunatelyin this example the period isn't precisely 1 second eitherbecause executing other functions of the program takes also timeFor exact timing  16-bit timer with interruptions must be used+Le programme suivant est un exemple similaire de temporisation logicielleDans la demi-période la plus petite de 100ms la LED s'allume et dans la plus grande de 900ms elle s'éteintAinsi la LED clignote toutes les secondesMalheureusementdans cet exemple la période n'est pas précisément d'une secondeparce que l'exécution des fonction du programme prend aussi du tempsPour un timing tout à fait exact on doit utiliser un //timer// 16-bits avec interruptions.
  
 <code c> <code c>
fr/examples/timer/hardware_delay.1268141815.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0