Block2. Contador Descendente. Aldhair Moreno Palma

 

Código VHDL

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity ContadorDescendente is

    Port ( clk : in STD_LOGIC;

           rst : in STD_LOGIC;

           count : out STD_LOGIC_VECTOR(3 downto 0));

end ContadorDescendente;


architecture Behavioral of ContadorDescendente is

    signal contador : STD_LOGIC_VECTOR(3 downto 0) := "1001"; -- Valor inicial, cuenta desde 9 hasta 0

begin

    process(clk, rst)

    begin

        if rst = '1' then

            contador <= "1001"; -- Valor inicial al activar el reset

        elsif rising_edge(clk) then

            if contador = "0000" then

                contador <= "1001"; -- Reinicia al llegar a cero

            else

                contador <= contador - 1; -- Decrementa el contador

            end if;

        end if;

    end process;


    count <= contador; -- La salida es el valor del contador


end Behavioral;



Esquemas y Diagramas

















Comentarios