Advertisement
salla

conta_updown

Jul 29th, 2019
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.65 KB | None | 0 0
  1. -- Contador de década sobe e desce
  2. -- Entradas: clk (clock), reset;
  3. -- Saída: q (Vetor 4 posições tipo BCD)
  4. -- Autores: João Vitor e Marcos Meira
  5. -- 02/08/2017
  6.  
  7. library IEEE;                                                        
  8. use IEEE.std_logic_1164.all;
  9. use IEEE.std_logic_unsigned.all;
  10.  
  11. entity conta_updown is
  12.   port (
  13.     clk:in bit;
  14.     reset: in bit;
  15.      sobedesce: in bit;
  16.      carry_out: out bit;
  17.     q: out std_logic_vector(3 downto 0)
  18.     );
  19. end conta_updown;
  20.  
  21. architecture arquitetura of conta_updown is
  22. begin
  23.     process(clk,reset)                                  
  24.     variable qtemp: std_logic_vector(3 downto 0);  
  25.     begin
  26.         if reset='1' then
  27.         qtemp:="0000";                                            
  28.        
  29.         else       
  30.             if clk'event and clk='1' then  
  31.                
  32.                 if sobedesce='1' then   ---     QUANDO sobedesce FOR 1
  33.                     if qtemp<9 then     ---
  34.                     qtemp:=qtemp+1;      ---                              
  35.                     carry_out <= '0';       ---
  36.                     else                        ---     CONTADOR CRESCENTE
  37.                     qtemp:="0000";       ---                                  
  38.                     carry_out <= '1';       ---
  39.                     end if;                 ---
  40. ----------------------------------------------------------------
  41.                 else                            --- QUANDO sobedesce FOR 0
  42.                     if qtemp>0 then     ---
  43.                     qtemp:=qtemp-1;     ---
  44.                     carry_out <= '0';       ---
  45.                     else                        --- CONTADOR DECRESCENTE
  46.                     qtemp:="1001";          ---
  47.                     carry_out <= '1';       ---
  48.                     end if;                 ---
  49.                    
  50.                 end if;
  51.             end if;
  52.         q<=qtemp;                                                
  53.         end if;
  54.     end process;                                                      
  55. end arquitetura;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement