Differences

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

Link to this comparison view

Next revision
Previous revision
pt:examples:timer:periodic_interrupt [2015/12/14 22:59] – Criação deste novo documento. articapt:examples:timer:periodic_interrupt [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 9: Line 9:
 ===== Teoria ===== ===== Teoria =====
  
-The goal of this chapter is to demonstrate the usage of the interrupts on the example of the countersThe interrupts are program parts which are reacting to the events taking place in the microcontrollersThey are usually used for quick response to an eventbut they can also be used for completing several parallel processesprecisely timed action and saving powerFor exampleit is possible to make a LED blinking using interruptionsso that blinking frequency does not depend on what is happening in the program at the momentWhen the interrupt occur then main program execution stopped and the interrupt priority check of the interrupt vector table happenafter that the program of the interrupt function has been executedWhile the interrupt program will be executed then the main program execution continues on the state where it left off.+O objetivo deste capítulo é demonstrar o uso das interrupções no exemplo dos contadoresAs interrupções são partes do programa que reagem aos eventos que têm lugar nos microcontroladoresSão usadas normalmente ​​para uma resposta rápida a um eventomas podem também ser usadas ​​para completar vários processos paralelosacções precisas no tempo e de poupança energéticaPor exemploé possível fazer um LED piscar com interrupçõesde modo a que a freqüência do piscar não dependa do que acontece no programa em execuçãoQuando a interrupção ocorre a execução do programa principal pára e acontece a verificação da prioridade de interrupção na tabela de vectores de interrupção. Depois dissodá-se então por concluída a função de interrupçãoDepois da interrupção, o programa principal continua a partir do estado onde parou.
  
-===== Practice =====+===== Prática =====
  
-The following program shows how the counter is set up to make an interruptThere are 2 LEDs of the Digital i/o module in the program, the state of the red LED is changed periodically with software delay, the state of the green LED is changed when interrupts occurThere is a separate exercise for blinking LED with software delay and it is not explained hereThe main goal is to explain the usage of the library of the counters and interrupts+O programa seguinte mostra como o contador é configurado para fazer uma interrupçãoExistem 2 LEDs do módulo de I/O digital no programa. O estado do LED vermelho é alterado periodicamente com uma espera por software; o estado do LED verde é alterado quando ocorrem interrupçõesExiste um exercício separado para um LED piscar com espera por software que não é explicado aquiO objetivo principal é explicar o uso da biblioteca dos contadores e interrupções.
  
-The following shows the use of interrupts of the xmega controllerIn the beginning of the programthe 16-bit counter/timer E1 has been set upFirstthe timer period will be set, so the maximum value of the count function TC_SetPeriod. The divider of the counter is 1024 and the value of period is 31249, so when the clock frequency is 32 MHz, the period will be exactly one secondIt is easy to calculate with following formula:+O que se segue mostra o uso de interrupções do controlador xmega. No início do programao contador/temporizador de 16 bits E1 é configuradoEm primeiro lugaro período do temporizador irá ser definido para o valor máximo da função de contagem TC_SetPeriod. O divisor do contador é de 1024 e o valor do período é de 31249, por isso, quando a frequência de relógio é de 32 MHz, o período será exatamente um segundoIsto é fácil de calcular com seguinte fórmula:
  
 period = (32000000 Hz / 1024 / 1) - 1 = 31249 period = (32000000 Hz / 1024 / 1) - 1 = 31249
  
-After allowing the interrupt to achieve the maximum value of the counter 1, an interrupt must be allowed at the global levelwhich means over the entire microcontrollerThe global interrupts can be enabled by function sei and forbidding with cli. header file avr/interrupt.h must be included for defining the program part of these functions and interruptsThe program part of the interrupt is defined with macro function ISR, which parameter is the name of the interrupt vectorIn this set-up the vector of counter 1’s maximum value achievement interrupt is TCE1_OVF_vect. In additionto allow the global interrupt, a different priority interrupts should be enabled one by oneusing the xmega PMIC.CTRL register.+Depois de permitir que a interrupção atinja o valor máximo do contador 1, uma interrupção deve ser permitida a nível global, o que significa ao longo de todo o microcontroladorAs interrupções globais podem ser ativadas por função sei e proíbidas com cli. Um ficheiro header avr/interrupt.h deve ser incluído na definição da parte do programa dessas funções e interrupçõesA parte do programa da interrupção é definida com função macro ISR, cujo parâmetro é o nome do vetor de interrupçãoNesta configuração o valor máximo de interrupção atinjida do vetor do contador é TCE1_OVF_vect. Além dissopara permitir a interrupção global, as prioridades de interrupção devem ser definidas uma umausando o registo XMEGA PMIC.CTRL.
  
 <code c> <code c>
Line 64: Line 64:
 </code> </code>
  
 +Os exemplos de interrupção são bastante diferentes entre as séries de controladores ATmega (neste exemplo usamos o ATmega2561), porque os temporizadores, em comparação com os controladores da série XMEGA, também são diferentes.
  
-Example of interrupt is quite different between ATmega series (in this example ATmega2561) controllersbecause the timers, compared to the xmega series controllers, are also different. +No início do programao contador/temporizador de 16 bits foi configurado com a função //timer1_init_ctc//Com esta função se o contador CTC //clear timer on compare match// tiver sido definido para o modo em que o valor máximo do temporizador não é 2<sup>16</sup> - 1, mas pode ser selecionadoNeste caso, o valor máximo é fixado para ser igual ao valor do índice do ICR1. O divisor do contador é de 1024 e o valor da ICR1 é 14400, por isso, quando a freqüência de relógio é 14,7456 MHz, o período será exatamente um segundoIsto é fácil de calcular com seguinte fórmula:
- +
-In the beginning of the program, the 16-bit counter/timer has been set up with the function //timer1_init_ctc// With this function the counter CTC //clear timer on compare match// has been set to the mode where the maximum value of the timer is not 2<sup>16</sup> - 1 but can be selectedIn this case the maximum value is set to equal the value of the ICR1 indexThe divider of the counter is 1024 and the value of ICR1 is 14400, so when the clock frequency is 14,7456 MHz, the period will be exactly one secondIt is easy to calculate with following formula+
  
 f = 14745600 Hz / 1024 / 14400 = 1  f = 14745600 Hz / 1024 / 14400 = 1 
Line 112: Line 111:
 </code> </code>
  
-At the start of the program it is seen that regardless of what the microcontroller is doing in the main programthe interrupts are taking place and the green LED is blinking.+No início do programa confirma-se queindependentemente do que o microcontrolador está a executar no programa principal, as interrupções ocorrem e o LED verde pisca.
  
pt/examples/timer/periodic_interrupt.1450133958.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