0% found this document useful (0 votes)
37 views4 pages

Contador

This document describes a VHDL design for a 4-digit counter with multiplexing and decoding. The counter increments from 0 to 9999 in response to a clock signal. It can operate at normal or fast speed depending on an input signal. The value is multiplexed to 7-segment display drivers. Additional logic generates signals to activate the correct display digit.

Uploaded by

Axel Ocampo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views4 pages

Contador

This document describes a VHDL design for a 4-digit counter with multiplexing and decoding. The counter increments from 0 to 9999 in response to a clock signal. It can operate at normal or fast speed depending on an input signal. The value is multiplexed to 7-segment display drivers. Additional logic generates signals to activate the correct display digit.

Uploaded by

Axel Ocampo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity SuperContador is
Port ( clk : in STD_LOGIC;
clksal: out STD_LOGIC;
reset : in STD_LOGIC;
speed : in STD_LOGIC;
sal : out STD_LOGIC_VECTOR (6 downto 0);
unidad: inout STD_LOGIC_VECTOR (3 downto 0);
decena: inout STD_LOGIC_VECTOR (3 downto 0);
centena: inout STD_LOGIC_VECTOR (3 downto 0);
millar: inout STD_LOGIC_VECTOR (3 downto 0);
an0 : out STD_LOGIC;
an1 : out STD_LOGIC;
an2 : out STD_LOGIC;
an3 : out STD_LOGIC);
end SuperContador;

architecture Behavioral of SuperContador is


signal clk_div : STD_LOGIC_VECTOR(23 downto 0) := (others => '0');
signal sel : STD_LOGIC_VECTOR(1 downto 0) := "00";
signal s : STD_LOGIC_VECTOR(14 downto 0);
signal s14_val : STD_LOGIC; -- Variable para almacenar s(14)
begin

-- Divisor de frecuencia
process(clk)
begin
if rising_edge(clk) then
clk_div <= clk_div + 1;
end if;
end process;

-- Señal de salida del divisor de frecuencia


clksal <= clk_div(23);

-- Contador de 0 a 9999
process(clksal, reset)
begin
if reset = '1' then
unidad <= "0000";
decena <= "0000";
centena <= "0000";
millar <= "0000";
elsif rising_edge(clksal) then
-- Almacenar el valor de s(14) en la variable s14_val
s14_val <= s(14);

if speed = '0' then


-- Velocidad normal: Incrementa en cada ciclo de clksal
if unidad = "1001" then
unidad <= "0000";
if decena = "1001" then
decena <= "0000";
if centena = "1001" then
centena <= "0000";
if millar = "1001" then
millar <= "0000";
else
millar <= millar + 1;
end if;
else
centena <= centena + 1;
end if;
else
decena <= decena + 1;
end if;
else
unidad <= unidad + 1;
end if;
else
-- Velocidad rápida: Incrementa cada dos ciclos de clksal
if s14_val = '1' then
if unidad = "1001" then
unidad <= "0000";
if decena = "1001" then
decena <= "0000";
if centena = "1001" then
centena <= "0000";
if millar = "1001" then
millar <= "0000";
else
millar <= millar + 1;
end if;
else
centena <= centena + 1;
end if;
else
decena <= decena + 1;
end if;
else
unidad <= unidad + 1;
end if;
end if;
end if;
end if;
end process;

-- Multiplexor
process(unidad, decena, centena, millar, sel)
begin
case sel is
when "00" =>
sal <= unidad;
when "01" =>
sal <= decena;
when "10" =>
sal <= centena;
when "11" =>
sal <= millar;
end case;
end process;

-- Decodificador
process(sal)
begin
case sal is
when "0000" =>
sal <= "0000001";
when "0001" =>
sal <= "1001111";
when "0010" =>
sal <= "0010010";
when "0011" =>
sal <= "0000110";
when "0100" =>
sal <= "1001100";
when "0101" =>
sal <= "0100100";
when "0110" =>
sal <= "0100000";
when "0111" =>
sal <= "0001111";
when "1000" =>
sal <= "0000000";
when "1001" =>
sal <= "0000100";
when others =>
sal <= "1111111";
end case;
end process;

-- Divisor de frecuencia para el contador de 0 a 3


process(clksal)
begin
if rising_edge(clksal) then
s <= s + 1;
end if;
end process;

-- Contador de 0 a 3
process(s(14))
begin
if rising_edge(s(14)) then
sel <= sel + 1;
end if;
end process;

-- Decodificador de activación de ánodo


process(sel)
begin
case sel is
when "00" =>
an0 <= '1';
an1 <= '0';
an2 <= '0';
an3 <= '0';
when "01" =>
an0 <= '0';
an1 <= '1';
an2 <= '0';
an3 <= '0';
when "10" =>
an0 <= '0';
an1 <= '0';
an2 <= '1';
an3 <= '0';
when "11" =>
an0 <= '0';
an1 <= '0';
an2 <= '0';
an3 <= '1';
when others =>
an0 <= '0';
an1 <= '0';
an2 <= '0';
an3 <= '0';
end case;
end process;

end Behavioral;

You might also like