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
pt:examples:timer:delay [2015/12/14 12:40] articapt:examples:timer:delay [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-~~PB~~+<pagebreak>
 ====== Espera ====== ====== Espera ======
  
Line 106: Line 106:
 </code> </code>
  
-Although it seems that the LED blinks in every 1 second, the time is actually little bit longerbecause the callouts of LED’s and delay functions are taking a couple of clock rates of the microcontroller+Embora pareça que o indicador pisca cada segundoo tempo é na verdade um pouco mais, porque as chamadas das funções de espera  e do LED tomam  um par de ciclos de relógio do microcontrolador.
  
-The program code below is a delay function based on a timer, which is simplified a little bitThe principle of counting is the same as it is at software delay function – a desired amount of 1 ms long delays are producedThe delay is produced with an 8-bit counter 0. It is calculated previously that at clock frequency 14,7456 Mhz the timing signal has to be divided at least 64 timesso 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-languagethat shows clock frequency in Hz. The clock frequency should be 25,6 at the moment but since fractions can not be usedthe initial value will be set 26. Unfortunately here arises a mistake in delay timehowever it is fairly small (-1,7 μs). +O código que se segue é uma função de espera com base num temporizador um pouco simplificadoO princípio de contagem é o mesmo da função de espera de software - uma quantidade desejada de esperas de 1 ms são produzidasO atraso é produzido com um contador de 8 bitsÉ calculado anteriormente que à frequência do relógio de 14,7456 MHz, o sinal de sincronismo tem de ser dividido, pelo menos, 64 vezesde modo a que o contador não chegue ao overflow em 1 ms. O valor que o contador deve ter para que o overflow ocorra após 1 ms é apresentado sob a forma de uma expressão sendo a variável //timer_start//. //F_CPU// que é uma constante na macro-linguagemmostra a freqüência de relógio em Hz. A frequência de relógio deve ser 25,6 no momentomas uma vez que fracções não podem ser usadas, o valor inicial será estabelecido em 26. Infelizmente aqui surge um erro no tempo de espera, sendo no entantobastante pequeno (-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 valuei.e. to the overflow. At 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      +No ciclo ocorre a inicialização do contador e a da flag de overflow (que será quando ocorre). De seguida, espera-se até que o contador atinja 256 a partir do valor inicialou seja, o overflow. No momento do overflow flag de overflow passa a high e a espera de 1 ms teve já lugarNo final da função do temporizador é parado     
  
  
Line 147: Line 147:
 </code> </code>
  
-Referenced delay function uses a timer library whose source code for ATmega controller looks like the following:+A função de espera referenciada usa uma biblioteca de temporizador cujo código-fonte para o controlador ATmega é parecida com o seguinte:
  
 <code c> <code c>
Line 194: Line 194:
 </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 time. For exact timing  a 16-bit timer with interruptions must be used+O que se segue é um programa semelhante ao exemplo de espera de software. Nos meios-períodos mais curtos de 100 ms, o LED é iluminado e nos meios-períodos mais longos é desligadoComo resultado o LED pisca a cada segundoInfelizmenteneste exemploo período não é precisamente um segundo também, porque execução de outras funções do programa leva tempo também. Para uma temporização exata, um temporizador de 16 bits com interrupções deve ser utilizado.
  
 <code c> <code c>
pt/examples/timer/delay.1450096841.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