Professional Documents
Culture Documents
Counters
Counters
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity UPCOUNTER_4 is
port (CLK,RST: in std_logic; Q: out std_logic_vector(3 downto 0));
end UPCOUNTER_4;
begin
process(CLK,RST)
begin
if(RST='0') then
Q_S <= "0000";
else if(CLK' event and CLK='1') then
Q_S <= Q_S+'1';
end if;
end if;
end process;
Q <= Q_S;
end behavioural;
Down Counter
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity DOWNCOUNTER_4 is
port (CLK,RST: in std_logic; Q: out std_logic_vector(3 downto 0));
end DOWNCOUNTER_4;
begin
process(CLK,RST)
begin
if(RST='0') then
Q_S <= "1111";
else if(CLK' event and CLK='1') then
Q_S <= Q_S-'1';
end if;
end if;
end process;
Q <= Q_S;
end behavioural;
Up-Down Counter
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity UPDOWNCOUNTER_5 is
port (DIR,CLK,RST: in std_logic; Q: out std_logic_vector(4 downto 0));
end UPDOWNCOUNTER_5;
begin
process(CLK,RST)
begin
if(RST='1') then
Q_S <= "00000";
else if(CLK' event and CLK='1') then
if(DIR='1') then
Q_S <= Q_S+'1';
else
Q_S <= Q_S-'1';
end if;
end if;
end if;
end process;
Q <= Q_S;
end behavioural;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity DOWN_MOD200 is
port (CLK,RST: in std_logic; Q: out std_logic_vector(7 downto 0));
end DOWN_MOD200;
begin
process(CLK,RST)
begin
if(RST='1') then
Q_S <= "11000111";
else if(CLK' event and CLK='1') then
if (Q_S="00000000") then
Q_S <= "11000111";
else
Q_S <= Q_S-'1';
end if;
end if;
end if;
end process;
Q <= Q_S;
end behavioural;