Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_unsigned.all;
- entity cronometro is
- port(
- clk: in std_logic;
- botao1: in std_logic; -- Inicia/Finaliza contagem
- botao2: in std_logic; -- Muda precisão do display
- clockPF100: out std_logic;
- pulso1PF: out std_logic;
- displayA: out std_logic_vector (7 downto 0);
- displayB: out std_logic_vector (7 downto 0)
- );
- end cronometro;
- architecture cron of cronometro is
- -- Definição de sinais que serão utilizados
- signal clk100: std_logic; -- clock de 100Hz
- signal clkCont: std_logic_vector (16 downto 0); -- contador de clocks
- signal debCont1: std_logic_vector (1 downto 0); -- contador de clocks debounce1
- signal debCont2: std_logic_vector (1 downto 0); -- contador de clocks debounce2
- signal pulso1: std_logic; -- debounce do botao1
- signal pulso2: std_logic; -- debounce do botao2
- signal cronFlag: std_logic; -- flag que inicia cronometragem
- -- Sinais utilizados para facilitar contagem -- limite de estouro
- signal centesimos: std_logic_vector (3 downto 0); -- até 9
- signal decimos: std_logic_vector (3 downto 0); -- até 9
- signal segundosR: std_logic_vector (3 downto 0); -- até 9
- signal segundosL: std_logic_vector (3 downto 0); -- até 5
- signal minutosR: std_logic_vector (3 downto 0); -- até 9
- signal minutosL: std_logic_vector (3 downto 0); -- até 5
- signal horasR: std_logic_vector (3 downto 0); -- varia de 0-9 e 0-4
- signal horasL: std_logic_vector (3 downto 0); -- vai até 2
- -- Sinais para determinar precisão do Display
- signal displayL: std_logic_vector (3 downto 0); -- buffer: display da esquerda
- signal displayR: std_logic_vector (3 downto 0); -- buffer: display da direita
- signal precisao: std_logic_vector (1 downto 0); -- 4 modos:
- -- 0: Décimos Centésimos
- -- 1: SegundosL SegundosR
- -- 2: MinutosL MinutosR
- -- 3: HorasL HorasR
- begin
- -------------------------------------------------------------------------
- -- Gera o clk100 a partir do clk de maquina
- process (clk)
- begin
- if (clk'event and clk = '1') then
- if (clkCont < "11110101110110011") then
- clkCont <= clkCont + 1;
- else
- clkCont <= "00000000000000000";
- clk100 <= not clk100;
- clockPF100 <= clk100;
- end if;
- end if;
- end process;
- -------------------------------------------------------------------------
- -- Remove trepidação causado pelos botões
- process (clk100)
- begin
- if (clk100'event and clk100 = '1') then
- -- Debounce do botao1
- if (botao1 = '0') then -- botao pressionado
- if (debCont1 < "11") then
- debCont1 <= debCont1 + 1;
- if (debCont1 = "10") then
- pulso1 <= '1';
- end if;
- else
- pulso1 <= '0';
- end if;
- else
- pulso1 <= '0';
- debCont1 <= "00";
- end if;
- -- Debounce do botao2
- if (botao2 = '0') then -- botao pressionado
- if (debCont2 < "11") then
- debCont2 <= debCont2 + 1;
- if (debCont2 = "10") then
- pulso2 <= '1';
- end if;
- else
- pulso2 <= '0';
- end if;
- else
- pulso2 <= '0';
- debCont2 <= "00";
- end if;
- end if;
- end process;
- -------------------------------------------------------------------------
- -- Processa o botao1 e botao2 depois do debounce
- process (pulso1, pulso2)
- begin
- pulso1PF <= pulso1;
- if (pulso1'event and pulso1 = '1') then
- cronFlag <= not cronFlag;
- end if;
- if (pulso2'event and pulso2 = '1') then
- if (precisao < "11") then
- precisao <= precisao + 1;
- else
- precisao <= "00";
- end if;
- end if;
- end process;
- -------------------------------------------------------------------------
- -- Processa as contagens
- process (clk100, cronFlag)
- begin
- if (clk100'event and clk100 = '0') then
- if (cronFlag = '1') then -- começa a cronometragem
- if (centesimos < "1001") then
- centesimos <= centesimos + 1;
- else
- centesimos <= "0000";
- if (decimos < "1001") then
- decimos <= decimos + 1;
- else
- decimos <= "0000";
- if (segundosR < "1001") then
- segundosR <= segundosR + 1;
- else
- segundosR <= "0000";
- if (segundosL < "0101") then
- segundosL <= segundosL + 1;
- else
- segundosL <= "0000";
- if (minutosR < "1001") then
- minutosR <= minutosR + 1;
- else
- minutosR <= "0000";
- if (minutosL < "0101") then
- minutosL <= minutosL + 1;
- else
- minutosL <= "0000";
- if (horasL < "0010") then
- if (horasR < "1001") then
- horasR <= horasR + 1;
- else
- horasR <= "0000";
- horasL <= horasL +1;
- end if;
- else
- if (horasR < "0100") then
- horasR <= horasR + 1;
- else
- horasR <= "0000";
- horasL <= "0000";
- end if;
- end if;
- end if;
- end if;
- end if;
- end if;
- end if;
- end if;
- end if;
- -- Implementação dos modos dos displays:
- if (precisao = "00") then -- D C
- displayL <= decimos;
- displayR <= centesimos;
- end if;
- if (precisao = "01") then -- S S
- displayL <= segundosL;
- displayR <= segundosR;
- end if;
- if (precisao = "10") then -- M M
- displayL <= minutosL;
- displayR <= minutosR;
- end if;
- if (precisao = "11") then -- H H
- displayL <= horasL;
- displayR <= horasR;
- end if;
- end if;
- end process;
- -------------------------------------------------------------------------
- -- Processa os displays L e R (Left - Right)
- process (displayL, displayR)
- begin
- -- DisplayL -- FORMATO DO DISPLAY: edc.bafg
- case displayL is
- when "0000" => displayA <= "00010001";
- when "0001" => displayA <= "11010111";
- when "0010" => displayA <= "00110010";
- when "0011" => displayA <= "10010010";
- when "0100" => displayA <= "11010100";
- when "0101" => displayA <= "10011000";
- when "0110" => displayA <= "00011000";
- when "0111" => displayA <= "11010011";
- when "1000" => displayA <= "00010000";
- when "1001" => displayA <= "10010000";
- when others => displayA <= "11111111";
- end case;
- --DisplayR -- FORMATO DO DISPLAY: edc.bafg
- case displayR is
- when "0000" => displayB <= "00010001";
- when "0001" => displayB <= "11010111";
- when "0010" => displayB <= "00110010";
- when "0011" => displayB <= "10010010";
- when "0100" => displayB <= "11010100";
- when "0101" => displayB <= "10011000";
- when "0110" => displayB <= "00011000";
- when "0111" => displayB <= "11010011";
- when "1000" => displayB <= "00010000";
- when "1001" => displayB <= "10010000";
- when others => displayB <= "11111111";
- end case;
- end process;
- end cron;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement