Mudanças entre as edições de "Avaliação 1 - SST"
Ir para navegação
Ir para pesquisar
(Criou página com '==Debouncer para Chave== * *') |
|||
Linha 1: | Linha 1: | ||
==Debouncer para Chave== | ==Debouncer para Chave== | ||
− | * | + | ;FUNCIONAMENTO: |
− | * | + | *Chave fechada (y='0') : x deve permanecer baixo por no mínimo 10ms sem interrupção. |
+ | *Chave aberta (y='1') : x deve permanecer alto por no mínimo 10ms sem interrupção. | ||
+ | [[Arquivo:CircuitoAntiRepique.png|300px|center]] | ||
+ | |||
+ | ;PARÂMETROS: | ||
+ | *fclk: inteiro = 1. Define a frequência do clock (kHz); | ||
+ | *twindow: inteiro = 10. Define a janela de tempo (ms); | ||
+ | *x: Valor de entrada (std_logic); | ||
+ | *clk: Valor de clock (std_logic); | ||
+ | *y: Buffer, neste caso variável de saída (std_logic); | ||
+ | *Constant max: Definida por um inteiro resultado da multiplicação das variáveis de entrada [fclk * twindow = (1kHz * 10ms = 10 bordas positivas de clock)]. | ||
+ | *Process é sensível a borda de subida do clock; | ||
+ | *Count: Afim de verificar em quantos períodos de clock a entrada x ficou alta/baixa. | ||
+ | |||
+ | ;CÓDIGO: | ||
+ | :<syntaxhighlight lang=vhdl> | ||
+ | library ieee; | ||
+ | use ieee.std_logic_1164.all; | ||
+ | |||
+ | entity debouncer is | ||
+ | |||
+ | generic( | ||
+ | fclk: integer := 1; --clock freq in kHz | ||
+ | twindow: integer := 10); --time window in ms | ||
+ | |||
+ | port( | ||
+ | x: in std_logic; | ||
+ | clk: in std_logic; | ||
+ | y : buffer std_logic); | ||
+ | |||
+ | end entity; | ||
+ | |||
+ | architecture key of debouncer is | ||
+ | constant max: integer := fclk * twindow; | ||
+ | |||
+ | begin | ||
+ | process(clk) | ||
+ | |||
+ | variable count : integer range 0 to max; | ||
+ | |||
+ | begin | ||
+ | if(clk'event and clk='1') then | ||
+ | if(y /= x) then | ||
+ | count := count + 1; | ||
+ | if(count = max) then | ||
+ | y <= x; | ||
+ | count := 0; | ||
+ | end if; | ||
+ | |||
+ | else | ||
+ | count := 0; | ||
+ | |||
+ | end if; | ||
+ | |||
+ | end if; | ||
+ | |||
+ | end process; | ||
+ | |||
+ | end architecture; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ;FORMA DE ONDA: | ||
+ | [[Arquivo:chavedebouncer.png|1100px|center]] | ||
+ | [[Arquivo:chavedebouncer2.png|1100px|center]] |
Edição das 20h05min de 16 de abril de 2015
Debouncer para Chave
- FUNCIONAMENTO
- Chave fechada (y='0') : x deve permanecer baixo por no mínimo 10ms sem interrupção.
- Chave aberta (y='1') : x deve permanecer alto por no mínimo 10ms sem interrupção.
- PARÂMETROS
- fclk: inteiro = 1. Define a frequência do clock (kHz);
- twindow: inteiro = 10. Define a janela de tempo (ms);
- x: Valor de entrada (std_logic);
- clk: Valor de clock (std_logic);
- y: Buffer, neste caso variável de saída (std_logic);
- Constant max: Definida por um inteiro resultado da multiplicação das variáveis de entrada [fclk * twindow = (1kHz * 10ms = 10 bordas positivas de clock)].
- Process é sensível a borda de subida do clock;
- Count: Afim de verificar em quantos períodos de clock a entrada x ficou alta/baixa.
- CÓDIGO
library ieee; use ieee.std_logic_1164.all; entity debouncer is generic( fclk: integer := 1; --clock freq in kHz twindow: integer := 10); --time window in ms port( x: in std_logic; clk: in std_logic; y : buffer std_logic); end entity; architecture key of debouncer is constant max: integer := fclk * twindow; begin process(clk) variable count : integer range 0 to max; begin if(clk'event and clk='1') then if(y /= x) then count := count + 1; if(count = max) then y <= x; count := 0; end if; else count := 0; end if; end if; end process; end architecture;
- FORMA DE ONDA