gabrielbonham

VHDL - Exercicios

Sep 22nd, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.05 KB | None | 0 0
  1. -- Sistemas Digitais - BSI 2012/1
  2. -- Prof°: Paulo
  3. -- Tema: VHDL
  4. -- Alunos: Gabriel Ed, Lucas Menezes, Raif Cervany.
  5.  
  6. -- Projete um contador síncrono crescente módulo 10 usando a abordagem estrutural.
  7. -- O contador deve possuir:
  8. -- * um sinal de clock (CLK) como entrada
  9. -- * quatro sinais de saída, representando a contagem (DCBA).
  10.  
  11. -- Os seguintes componentes devem formar o contador solicitado:
  12. -- *4 instâncias do componente FF_JK, representando cada FF J-K que compõe o contador, possuíndo todas as entradas J, K, CLR, PRE e CLK devidamente ligadas.
  13. -- *1 instância do componente NAND2, representando a porta NAND de duas entradas que deve ser ligada na entrada CLR de cada FF J-K.
  14. -- *3 instâncias do componente AND4, representando as portas AND de 4 entradas que serão usada para interconectar os FFs.
  15.  
  16.  
  17. -- Bibliotecas
  18.  
  19. library IEEE;
  20. use IEEE.STD_LOGIC_1164.ALL;
  21. use IEEE.STD_LOGIC_ARITH.ALL;
  22. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  23.  
  24. -- Entidades
  25.  
  26. -- FF JK
  27.  
  28. ENTITY FF_JK IS
  29.   PORT (CLK         : IN  std_logic;                -- Clock
  30.         clear       : IN  std_logic;                -- Clear
  31.         pre         : IN std_logic;                 -- preset
  32.         J           : IN std_logic;                 -- J
  33.         K           : IN std_logic;                 -- K
  34.         Q           : OUT std_logic;                -- Saida
  35.         Qb          : OUT std_logic;                -- Saida negada
  36.         )
  37. END FF_JK;
  38.  
  39. architecture ff_out of FF_JK is
  40. begin
  41.     if rising_edge(CLK) then -- Borda de Subida
  42.     begin processo : process (clear,pre,J,K,Q,Qb)
  43.             if(not(clear)) then Q <= 0; -- Clear
  44.             elsif(not(pre)) then Q <= 1; -- Preset
  45.             else
  46.                 if(not(J) and not(K) and Q) then Q <= 1; -- Q0 = 1
  47.                 elsif(not(J) and not(K) and not(Q)) then Q <= 0; -- Q0 = 1
  48.                 elsif (not(J) and K) then Q <= 0; -- Reset
  49.                 elsif (J and not(K)) then Q <= 1; -- Set
  50.                 else (J and K) then Q <= not Q; -- Q barra
  51.                 end if;
  52.             end if;
  53.         Qb <- not Q;
  54.     end process processo;
  55.     end if;
  56. end ff_out;
  57.  
  58. -- Porta Nand
  59.  
  60. ENTITY Nand2 is
  61.     Port (  D,B         : IN std_logic; -- Entradas Lógicas
  62.             N_out       : OUT std_logic;
  63.         )
  64. END Nand2;
  65.  
  66. architecture Nand2_out of Nand2 is
  67. begin
  68. N_out <= not (D and B);
  69. end Nand2_out;
  70.  
  71. -- Porta AND
  72.  
  73. ENTITY And4 is
  74.     Port ( D,C,B,A      : IN std_logic; -- Entradas Lógicas
  75.             S_And       : OUT std_logic; -- Saida Lógica
  76.         )
  77. END And4;
  78.  
  79. architecture And4_out of And4 is
  80. begin
  81. S_And <= (A and B and C and D);
  82. end And4_out;
  83.  
  84. -- Circuito final
  85. ENTITY contador IS
  86.   PORT (CLK   : IN  std_logic;                  -- Clock
  87.         D,C,B,A : Out std_logic);               -- Saidas
  88. END contador;
  89.  
  90. architecture contador_out of contador is
  91.     component FF_JK is
  92.     Port{
  93.         CLK,clear,pre,J,K       : IN  std_logic;                -- Entradas
  94.         Q,Qb                    : OUT std_logic;                -- Saidas
  95.     }
  96.     end component
  97.    
  98.     component Nand2 is
  99.     Port{
  100.         D,B                 : IN std_logic;                 --Entradas
  101.         S_And                   : Out std_logic;            --Saidas Lógicas
  102.     }
  103.     end component
  104.    
  105.     component And4 is
  106.     Port{
  107.         D,C,B,A                 : In std_logic;                 --Entradas
  108.         N_out                   : Out std_logic;                --Saidas Lógicas
  109.     }
  110.     end component
  111.    
  112.     For ALL : FF_JK use entity work.FF_JK(ff_out);
  113.     For ALL : Nand2 use entity work.Nand2(Nand2_out);
  114.     For ALL : And4 use entity work.FF_JK(And4_out);
  115.    
  116.     signal D_out, C_out, B_out, A_out,nD_out, nC_out, nB_out, nA_out, And1_out, And2_out,And3_out,Nand1_out : std_logic;
  117.    
  118. begin
  119.     And1 :  And4 port map(1,1,1,A_out,And1_out);  --  POrta And A
  120.     And2 :  And4 port map(1,1,B_out,A_out,And2_out);  --  Porta And AB
  121.     And3 :  And4 port map(1,C_out,B_out,And3_out);  --  Porta And ABC
  122.     Nand1 : Nand2 port map(D_out,B_out,Nand1_out); -- Porta Nand DB - Clear quando contador chegar em 1010 = DB.
  123.     FF_A : FF_JK port map (rising_edge,Nand1_out,1,1,1,A_out,nA_out); -- Valor de A
  124.     FF_B : FF_JK port map (rising_edge,Nand1_out,1,And1_out,And1_out,B_out,nB_out); -- Valor de B
  125.     FF_C : FF_JK port map (rising_edge,Nand1_out,1,And2_out,And2_out,C_out,nC_out); -- Valor de C
  126.     FF_D : FF_JK port map (rising_edge,Nand1_out,1,And3_out,And3_out,D_out,nD_out); -- Valor de D
  127.    
  128.     begin valores : process (D_out,C_out,B_out,A_out)
  129.     D <= D_out;
  130.     C <= C_out;
  131.     B <= B_out;
  132.     A <= A_out;
  133.     end process valores;
  134. end contador_out;
Advertisement
Add Comment
Please, Sign In to add comment