Advertisement
Guest User

Untitled

a guest
Oct 26th, 2010
2,947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 6.66 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5. entity cronometro is
  6. port(
  7.     clk: in std_logic;
  8.     botao1: in std_logic;  -- Inicia/Finaliza contagem
  9.     botao2: in std_logic;  -- Muda precisão do display
  10.     clockPF100: out std_logic;
  11.     pulso1PF: out std_logic;
  12.     displayA: out std_logic_vector (7 downto 0);
  13.     displayB: out std_logic_vector (7 downto 0)
  14. );
  15. end cronometro;
  16.  
  17. architecture cron of cronometro is
  18.  
  19. -- Definição de sinais que serão utilizados
  20. signal clk100: std_logic;           -- clock de 100Hz
  21. signal clkCont: std_logic_vector (16 downto 0); -- contador de clocks
  22. signal debCont1: std_logic_vector (1 downto 0); -- contador de clocks debounce1
  23. signal debCont2: std_logic_vector (1 downto 0); -- contador de clocks debounce2
  24. signal pulso1: std_logic;           -- debounce do botao1
  25. signal pulso2: std_logic;           -- debounce do botao2
  26. signal cronFlag: std_logic;         -- flag que inicia cronometragem
  27.  
  28. -- Sinais utilizados para facilitar contagem      -- limite de estouro
  29. signal centesimos: std_logic_vector (3 downto 0); -- até 9
  30. signal decimos: std_logic_vector (3 downto 0);    -- até 9
  31. signal segundosR: std_logic_vector (3 downto 0);  -- até 9
  32. signal segundosL: std_logic_vector (3 downto 0);  -- até 5
  33. signal minutosR: std_logic_vector (3 downto 0);   -- até 9
  34. signal minutosL: std_logic_vector (3 downto 0);   -- até 5
  35. signal horasR: std_logic_vector (3 downto 0);     -- varia de 0-9 e 0-4
  36. signal horasL: std_logic_vector (3 downto 0);     -- vai até 2
  37.  
  38. -- Sinais para determinar precisão do Display
  39. signal displayL: std_logic_vector (3 downto 0); -- buffer: display da esquerda
  40. signal displayR: std_logic_vector (3 downto 0); -- buffer: display da direita
  41. signal precisao: std_logic_vector (1 downto 0); -- 4 modos:
  42.                              -- 0: Décimos Centésimos
  43.                              -- 1: SegundosL SegundosR
  44.                              -- 2: MinutosL MinutosR
  45.                              -- 3: HorasL HorasR
  46.  
  47. begin
  48. -------------------------------------------------------------------------
  49.   -- Gera o clk100 a partir do clk de maquina
  50.   process (clk)
  51.   begin
  52.     if (clk'event and clk = '1') then
  53.       if (clkCont < "11110101110110011") then
  54.     clkCont <= clkCont + 1;
  55.       else
  56.     clkCont <= "00000000000000000";
  57.     clk100 <= not clk100;
  58.     clockPF100 <= clk100;
  59.       end if;
  60.     end if;
  61.   end process;
  62.  
  63. -------------------------------------------------------------------------
  64.   -- Remove trepidação causado pelos botões
  65.   process (clk100)
  66.   begin
  67.     if (clk100'event and clk100 = '1') then
  68.  
  69.       -- Debounce do botao1
  70.       if (botao1 = '0') then -- botao pressionado
  71.     if (debCont1 < "11") then
  72.       debCont1 <= debCont1 + 1;
  73.       if (debCont1 = "10") then
  74.         pulso1 <= '1';
  75.       end if;
  76.     else
  77.       pulso1 <= '0';
  78.     end if;
  79.       else
  80.     pulso1 <= '0';
  81.     debCont1 <= "00";
  82.       end if;
  83.      
  84.       -- Debounce do botao2
  85.       if (botao2 = '0') then -- botao pressionado
  86.     if (debCont2 < "11") then
  87.       debCont2 <= debCont2 + 1;
  88.       if (debCont2 = "10") then
  89.         pulso2 <= '1';
  90.       end if;
  91.     else
  92.       pulso2 <= '0';
  93.     end if;
  94.       else
  95.     pulso2 <= '0';
  96.     debCont2 <= "00";
  97.       end if;
  98.      
  99.     end if;
  100.   end process;
  101.  
  102. -------------------------------------------------------------------------
  103.   -- Processa o botao1 e botao2 depois do debounce
  104.   process (pulso1, pulso2)
  105.   begin
  106.     pulso1PF <= pulso1;
  107.     if (pulso1'event and pulso1 = '1') then
  108.       cronFlag <= not cronFlag;
  109.     end if;
  110.    
  111.     if (pulso2'event and pulso2 = '1') then
  112.       if (precisao < "11") then
  113.     precisao <= precisao + 1;
  114.       else
  115.     precisao <= "00";
  116.       end if;
  117.     end if;
  118.   end process;
  119.  
  120. -------------------------------------------------------------------------  
  121.   -- Processa as contagens
  122.   process (clk100, cronFlag)
  123.   begin
  124.     if (clk100'event and clk100 = '0') then
  125.       if (cronFlag = '1') then -- começa a cronometragem
  126.     if (centesimos < "1001") then
  127.       centesimos <= centesimos + 1;
  128.     else
  129.       centesimos <= "0000";
  130.       if (decimos < "1001") then
  131.         decimos <= decimos + 1;
  132.       else
  133.         decimos <= "0000";
  134.         if (segundosR < "1001") then
  135.           segundosR <= segundosR + 1;
  136.         else
  137.           segundosR <= "0000";
  138.           if (segundosL < "0101") then
  139.         segundosL <= segundosL + 1;
  140.           else
  141.         segundosL <= "0000";
  142.         if (minutosR < "1001") then
  143.           minutosR <= minutosR + 1;
  144.         else
  145.           minutosR <= "0000";
  146.           if (minutosL < "0101") then
  147.             minutosL <= minutosL + 1;
  148.           else
  149.             minutosL <= "0000";
  150.             if (horasL < "0010") then
  151.               if (horasR < "1001") then
  152.             horasR <= horasR + 1;
  153.               else
  154.             horasR <= "0000";
  155.             horasL <= horasL +1;
  156.               end if;
  157.             else
  158.               if (horasR < "0100") then
  159.             horasR <= horasR + 1;
  160.               else
  161.             horasR <= "0000";
  162.             horasL <= "0000";
  163.               end if;
  164.             end if;
  165.           end if;
  166.         end if;
  167.           end if;
  168.         end if;
  169.       end if;
  170.     end if;
  171.       end if;
  172.      
  173.       -- Implementação dos modos dos displays:
  174.       if (precisao = "00") then  -- D C
  175.     displayL <= decimos;
  176.     displayR <= centesimos;
  177.       end if;
  178.  
  179.       if (precisao = "01") then  -- S S
  180.     displayL <= segundosL;
  181.     displayR <= segundosR;
  182.       end if;
  183.  
  184.       if (precisao = "10") then  -- M M
  185.     displayL <= minutosL;
  186.     displayR <= minutosR;
  187.       end if;
  188.  
  189.       if (precisao = "11") then  -- H H
  190.     displayL <= horasL;
  191.     displayR <= horasR;
  192.       end if;
  193.     end if;
  194.   end process;
  195.  
  196. -------------------------------------------------------------------------  
  197.   -- Processa os displays L e R (Left - Right)
  198.   process (displayL, displayR)
  199.   begin
  200.  
  201.     -- DisplayL -- FORMATO DO DISPLAY:  edc.bafg
  202.     case displayL is
  203.       when "0000" => displayA <= "00010001";
  204.       when "0001" => displayA <= "11010111";
  205.       when "0010" => displayA <= "00110010";
  206.       when "0011" => displayA <= "10010010";
  207.       when "0100" => displayA <= "11010100";
  208.       when "0101" => displayA <= "10011000";
  209.       when "0110" => displayA <= "00011000";
  210.       when "0111" => displayA <= "11010011";
  211.       when "1000" => displayA <= "00010000";
  212.       when "1001" => displayA <= "10010000";
  213.       when others => displayA <= "11111111";
  214.     end case;
  215.  
  216.     --DisplayR -- FORMATO DO DISPLAY:  edc.bafg
  217.     case displayR is
  218.       when "0000" => displayB <= "00010001";
  219.       when "0001" => displayB <= "11010111";
  220.       when "0010" => displayB <= "00110010";
  221.       when "0011" => displayB <= "10010010";
  222.       when "0100" => displayB <= "11010100";
  223.       when "0101" => displayB <= "10011000";
  224.       when "0110" => displayB <= "00011000";
  225.       when "0111" => displayB <= "11010011";
  226.       when "1000" => displayB <= "00010000";
  227.       when "1001" => displayB <= "10010000";
  228.       when others => displayB <= "11111111";
  229.     end case;
  230.   end process;
  231.  
  232. end cron;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement