Beruflich Dokumente
Kultur Dokumente
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity twoto4decvhdl is
Port ( a : in STD_LOGIC_VECTOR (1 downto 0);
y : out STD_LOGIC_VECTOR (3 downto 0));
end twoto4decvhdl;
architecture Behavioral of twoto4decvhdl is
begin
process (a)
begin
case a is
when "00"=> y<="0001";
when "01"=> y<="0010";
when "10"=> y<="0100";
when "11"=> y<="1000";
when others => null;
end case;
end process;
end Behavioral;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_2to4 IS
END tb_2to4;
--Outputs
signal y : std_logic_vector(3 downto 0);
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
- Stimulus process
stim_proc: process
begin
a<="00";
wait for 100 ns;
a<="01";
wait for 100 ns;
a<="10";
wait for 100 ns;
a<="11";
wait for 100 ns;
end process;
END;
begin
process ( En,I)
begin
if En='0' then Y<="XXX";
else
case I is
when"00000001"=>Y<="000";
when"00000010"=>Y<="001";
when"00000100"=>Y<="010";
when"00001000"=>Y<="011";
when"00010000"=>Y<="100";
when"00100000"=>Y<="101";
when"01000000"=>Y<="110";
when"10000000"=>Y<="111";
when others=> null;
end case;
end if;
end process;
end Behavioral;
END tb_eight23;
ARCHITECTURE behavior OF tb_eight23 IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT eight23encodervhdl
PORT(
en : IN std_logic;
I : IN std_logic_vector(7 downto 0);
Y : OUT std_logic_vector(2 downto 0)
);
END COMPONENT;
--Inputs
signal en : std_logic := '0';
signal I : std_logic_vector(7 downto 0) := (others => '0');
--Outputs
signal Y : std_logic_vector(2 downto 0);
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: eight23encodervhdl PORT MAP (
en => en,
I => I,
Y => Y
);
-- Stimulus process
stim_proc: process
begin
en<='1';
I<="00000001" ;
wait for 100 ns;
I<="00000010" ;
wait for 100 ns;
I<="00000100";
wait for 100 ns;
I<="00001000";
wait for 100 ns;
I<="00010000";
wait for 100 ns;
I<="00100000"
;
END;
COMPONENT eight23wpvhdl
PORT(
En : IN std_logic;
I : IN std_logic_vector(7 downto 0);
Y : OUT std_logic_vector(2 downto 0)
);
END COMPONENT;
--Inputs
signal En : std_logic := '0';
signal I : std_logic_vector(7 downto 0) := (others => '0');
--Outputs
signal Y : std_logic_vector(2 downto 0);
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: eight23wpvhdl PORT MAP (
En => En,
I => I,
Y => Y
);
-- Stimulus process
stim_proc: process
begin
en<='1';
I(7)<='1';
I(6)<='0';
I(5)<='0';
I(4)<='0';
I(3)<='0';
I(2)<='0';
I(1)<='0';
I(0)<='0';
wait for 100 ns;
en<='1';
I(7)<='0';
I(6)<='1';
I(5)<='0';
I(4)<='0';
I(3)<='0';
I(2)<='0';
I(1)<='0';
I(0)<='0';
wait for 100 ns;
en<='1';
I(7)<='0';
I(6)<='1';
I(5)<='1';
I(4)<='0';
I(3)<='0';
I(2)<='0';
I(1)<='0';
I(0)<='0';
end process;
END;
VHDL Code for 8 to 1 multiplexer
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity eightto1muxvhd is
Port ( En : in STD_LOGIC;
S : in STD_LOGIC_VECTOR (2 downto 0);
D : in STD_LOGIC_VECTOR (7 downto 0);
Y : out STD_LOGIC);
end eightto1muxvhd;
architecture Behavioral of eightto1muxvhd is
begin
process ( S,D,En)
begin
if En='1' then Y<='0';
else
case S is
when "000"=>Y<=D(0);
when "001"=>Y<=D(1);
when "010"=>Y<=D(2);
when "011"=>Y<=D(3);
when "100"=>Y<=D(4);
when "101"=>Y<=D(5);
when "110"=>Y<=D(6);
when "111"=>Y<=D(7);
when others=> Y<='Z';
end case;
end if;
end process;
end Behavioral;
Test bench code for 8 to 1 multiplexer
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_eightto1muxvhd IS
END tb_eightto1muxvhd;
ARCHITECTURE behavior OF tb_eightto1muxvhd IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT eightto1muxvhd
PORT(
En : IN std_logic;
S : IN std_logic_vector(2 downto 0);
D : IN std_logic_vector(7 downto 0);
Y : OUT std_logic
);
END COMPONENT;
--Inputs
signal En : std_logic := '0';
signal S : std_logic_vector(2 downto 0) := (others => '0');
signal D : std_logic_vector(7 downto 0) := (others => '0');
--Outputs
signal Y : std_logic;
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
S<="011";
D<="00001000";
wait for 100 ns;
S<="100";
D<="00010000";
wait for 100 ns;
S<="101";
D<="00100000";
wait for 100 ns;
S<="110";
D<="01000000";
wait for 100 ns;
S<="111";
D<="10000000";
wait for 100 ns;
end process;
END;
END COMPONENT;
--Inputs
signal A : std_logic_vector(3 downto 0) := (others => '0');
signal B : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal AEQB : std_logic;
signal AGTB : std_logic;
signal ALTB : std_logic;
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: cmparatorvhdl PORT MAP (
A => A,
B => B,
AEQB => AEQB,
AGTB => AGTB,
ALTB => ALTB
);
-- Stimulus process
stim_proc: process
begin
A<="0000";
B<="1001";
wait for 100 ns;
A<="0010";
B<="1001";
B<="1010";
wait for 100 ns;
A<="1010";
B<="1010";
end process;
END;
USE ieee.std_logic_1164.ALL;
ENTITY adsdsdsd IS
END adsdsdsd;
ARCHITECTURE behavior OF adsdsdsd IS
COMPONENT btog
PORT(
b : IN std_logic_vector(3 downto 0);
g : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
signal b : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal g : std_logic_vector(3 downto 0);
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
b(3)<='0';
b(2)<='0';
b(1)<='0';
b(0)<='0';
wait for 100 ns;
b(3)<='0';
b(2)<='0';
b(1)<='0';
b(0)<='1';
wait for 100 ns;
b(3)<='0';
b(2)<='0';
b(1)<='1';
b(0)<='0';
wait for 100 ns;
b(3)<='0';
b(2)<='0';
b(1)<='1';
b(0)<='1';
wait for 100 ns;
b(3)<='0';
b(2)<='1';
b(1)<='0';
b(0)<='0';
wait for 100 ns;
b(3)<='0';
b(2)<='1';
b(1)<='0';
b(0)<='1';
wait for 100 ns;
b(3)<='0';
b(2)<='1';
b(1)<='1';
b(0)<='0';
wait for 100 ns;
b(3)<='0';
b(2)<='1';
b(1)<='1';
b(0)<='1';
wait for 100 ns;
b(3)<='1';
b(2)<='0';
b(1)<='0';
b(0)<='0';
wait for 100 ns;
b(3)<='1';
b(2)<='0';
b(1)<='0';
b(0)<='1';
wait for 100 ns;
b(3)<='1';
b(2)<='0';
b(1)<='1';
b(0)<='0';
wait for 100 ns;
b(3)<='1';
b(2)<='0';
b(1)<='1';
b(0)<='1';
wait for 100 ns;
b(3)<='1';
b(2)<='1';
b(1)<='0';
b(0)<='0';
wait for 100 ns;
b(3)<='1';
b(2)<='1';
b(1)<='0';
b(0)<='1';
wait for 100 ns;
b(3)<='1';
b(2)<='1';
b(1)<='1';
b(0)<='0';
wait for 100 ns;
b(3)<='1';
b(2)<='1';
b(1)<='1';
b(0)<='1';
wait for 100 ns;
end process;
END;
VHDL code for full adder (dataflow)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Fulladdervhdl is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
Cin : in STD_LOGIC;
Sum : out STD_LOGIC;
Carry : out STD_LOGIC
);
end Fulladdervhdl;
architecture Behavioral of Fulladdervhdl is
signal X: STD_LOGIC;
begin
X <=(a xor b) and Cin;
Sum<= a xor b xor Cin;
Carry<= X or ( a and b);
end Behavioral;
Test bench code for Full adder (data flow)
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY fdad IS
END fdad;
ARCHITECTURE behavior OF fdad IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT Fulladdervhdl
PORT(
a : IN std_logic;
b : IN std_logic;
Cin : IN std_logic;
Sum : OUT std_logic;
Carry : OUT std_logic
);
END COMPONENT;
--Inputs
signal a : std_logic := '0';
signal b : std_logic := '0';
signal Cin : std_logic := '0';
--Outputs
signal Sum : std_logic;
signal Carry : std_logic;
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Instantiate the Unit Under Test (UUT)
entity Fadderbehavoural is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
Sum : out STD_LOGIC;
Test bench code for Full adder (Behavioral model ) is same as the above
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity or_g is
port ( a: in std_logic;
b: in std_logic;
c:out std_logic);
end or_g;
architecture behavioural of or_g is
begin
c<= a or b;
end behavioural;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and_g is
port ( a: in std_logic;
b: in std_logic;
c:out std_logic);
end and_g;
architecture behavioural of and_g is
begin
c<= a and b;
end behavioural;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity xor_g is
port ( a: in std_logic;
b: in std_logic;
c:out std_logic);
end xor_g;
architecture behavioural of xor_g is
begin
c<= a xor b;
end behavioural;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Faddstruct is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Cin : in STD_LOGIC;
Sum : out STD_LOGIC;
Cout : out STD_LOGIC);
end Faddstruct;
architecture Behavioral of Faddstruct is
component or_g is
port( a,b: in std_logic;
c:out std_logic);
end component;
component and_g is
port (a,b: in std_logic;
c:out std_logic);
end component;
component xor_g is
COMPONENT dffvhd
PORT(
clk : IN std_logic;
Rst : IN std_logic;
D : IN std_logic;
Q : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
BEGIN
stim_proc: process
begin
Rst<='0';
D<='0';
wait for 100 ns;
Rst<='0';
D<='1';
wait for 100 ns;
Rst<='1';
D<='0';
wait for 100 ns;
Rst<='1';
D<='1';
wait for 100 ns;
Rst<='0';
D<='0';
wait for 100 ns;
Rst<='1';
D<='0';
wait for 100 ns;
wait for clk_period*10;
-- insert stimulus here
end process;
END;
END tb_dffsrstvhd;
ARCHITECTURE behavior OF tb_dffsrstvhd IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT dffsrstvhd
PORT(
clk : IN std_logic;
Rst : IN std_logic;
D : IN std_logic;
Q : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal Rst : std_logic := '0';
signal D : std_logic := '0';
--Outputs
signal Q : std_logic;
constant clk_period : time := 100 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: dffsrstvhd PORT MAP (
clk => clk,
Rst => Rst,
D => D,
Q => Q
);
end process;
END;
VHDL code for TFF with Asynchronous reset
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tffasrst is
Port ( clk : in STD_LOGIC;
data :in std_logic;
reset : in STD_LOGIC;
q : out STD_LOGIC
);
end tffasrst;
architecture Behavioral of tffasrst is
signal t: std_logic;
begin
process (clk,reset)
begin
if ( reset='0') then
t<='0';
elsif (rising_edge(clk)) then
t<=not t;
end if;
end process;
q<=t;
end Behavioral;
begin
process (clk)
begin
if (rising_edge(clk)) then
if (Rst ='0') then
t<='0';
else
t<= not t;
end if;
end if;
end process;
q<=t;
end Behavioral;
Test bench code for TFF with Synchronous reset
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY fgfg IS
END fgfg;
ARCHITECTURE behavior OF fgfg IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT tffsrstvhd
PORT(
D : IN std_logic;
clk : IN std_logic;
Rst : IN std_logic;
Q : OUT std_logic
);
END COMPONENT;
--Inputs
signal D : std_logic := '0';
signal clk : std_logic := '0';
signal Rst : std_logic := '0';
--Outputs
signal Q : std_logic;
constant clk_period : time := 100 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: tffsrstvhd PORT MAP (
D => D,
clk => clk,
Rst => Rst,
Q => Q
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
D<='0';
Rst<='0';
wait for 100 ns;
D<='0';
Rst<='1';
wait for 100 ns;
D<='1';
Rst<='0';
wait for 100 ns;
D<='1';
Rst<='1';
wait for 100 ns;
entity jkffasrstvhd is
Port ( clk : in STD_LOGIC;
J : in STD_LOGIC;
K : in STD_LOGIC;
Rst : in STD_LOGIC;
Q : out STD_LOGIC;
Qbar: out STD_LOGIC
);
end jkffasrstvhd;
architecture Behavioral of jkffasrstvhd is
signal state:std_logic;
signal input: std_logic_vector(1 downto 0);
begin
input<= J & K;
process (clk,Rst) is
begin
if Rst='1' then
state<='0';
elsif( rising_edge(clk)) then
case ( input ) is
when"11"=> state <= not state;
when"10"=> state<='1';
when"01"=> state<='0';
when others=> null;
end case;
end if;
end process;
Q<= state;
Qbar<= not state;
end Behavioral;
Test bench code for JK FF with Asynchronous reset
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY asadd IS
END asadd;
ARCHITECTURE behavior OF asadd IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT jkffasrstvhd
PORT(
clk : IN std_logic;
J : IN std_logic;
K : IN std_logic;
Rst : IN std_logic;
Q : OUT std_logic;
Qbar : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
BEGIN
-- Stimulus process
stim_proc: process
begin
J<='0';
K<='0';
Rst<='1';
K<='1';
Rst<='0';
wait for 100 ns;
J<='1';
K<='0';
Rst<='1';
wait for 100 ns;
J<='1';
K<='1';
Rst<='1';
wait for 100 ns;
J<='0';
K<='0';
Rst<='1';
wait for 100 ns;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
K : IN std_logic;
Q : OUT std_logic;
clken : IN std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal Rst : std_logic := '0';
signal J : std_logic := '0';
signal K : std_logic := '0';
signal clken : std_logic := '0';
--Outputs
signal Q : std_logic;
-- Clock period definitions
constant clk_period : time := 100 ns;
constant clken_period : time := 100 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: jkffsrstvhd PORT MAP (
clk => clk,
Rst => Rst,
J => J,
K => K,
Q => Q,
clken => clken
);
J<='0';
K<='1';
Rst<='0';
wait for 100 ns;
J<='0';
K<='1';
Rst<='1';
wait for 100 ns;
J<='1';
K<='0';
Rst<='0';
wait for 100 ns;
J<='1';
K<='0';
Rst<='1';
wait for 100 ns;
J<='1';
K<='1';
Rst<='0';
wait for 100 ns;
J<='1';
K<='1';
Rst<='1';
wait for 100 ns;
wait for clk_period*10;
end process;
END;
end process;
end Behavioral;
Test bench code for BCD counter with Asynchronous reset
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY ggdgdfd IS
END ggdgdfd;
ARCHITECTURE behavior OF ggdgdfd IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT bcdcountervhdasrst
PORT(
rst : IN std_logic;
clk : IN std_logic;
q : Buffer std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
signal rst : std_logic := '0';
signal clk : std_logic := '0';
--Outputs
signal q : std_logic_vector(3 downto 0);
-- Clock period definitions
constant clk_period : time := 100 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: bcdcountervhdasrst PORT MAP (
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity bcdcountersrstvhd is
Port ( rst : in STD_LOGIC;
clk : in STD_LOGIC;
q : buffer STD_LOGIC_VECTOR (3 downto 0));
end bcdcountersrstvhd;
architecture Behavioral of bcdcountersrstvhd is
begin
process
begin
wait until (rising_edge(clk));
if rst='1' then Q<="0000";
elsif (rising_edge(clk)) then
Q<=Q+1;
if Q="1111" then Q<="0000";
end if;
end if;
end process;
end Behavioral;
END asascvcv;
ARCHITECTURE behavior OF asascvcv IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT bcdcountersrstvhd
PORT(
rst : IN std_logic;
clk : IN std_logic;
q : buffer std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
signal rst : std_logic := '0';
signal clk : std_logic := '0';
--Outputs
signal q : std_logic_vector(3 downto 0);
-- Clock period definitions
constant clk_period : time := 100 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: bcdcountersrstvhd PORT MAP (
rst => rst,
clk => clk,
q => q
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
rst<='1';
wait for 100 ns;
rst<='0';
wait for 100 ns;
wait for clk_period*10;
end process;
END;
end if;
end process;
end Behavioral;
Test bench code for SRFF with Asynchronous reset
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY jhkhjk IS
END jhkhjk;
ARCHITECTURE behavior OF jhkhjk IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT srffvhdasrst
PORT(
s : IN std_logic;
r : IN std_logic;
clk : IN std_logic;
rst : IN std_logic;
q : OUT std_logic;
qbar : OUT std_logic
);
END COMPONENT;
--Inputs
signal s : std_logic := '0';
signal r : std_logic := '0';
signal clk : std_logic := '0';
signal rst : std_logic := '0';
--Outputs
signal q : std_logic;
signal qbar : std_logic;
-- Clock period definitions
constant clk_period : time := 100 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: srffvhdasrst PORT MAP (
s => s,
r => r,
clk => clk,
rst => rst,
q => q,
qbar => qbar
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
s<='0';
r<='0';
rst<='1';
wait for 100 ns;
s<='0';
r<='0';
rst<='0';
wait for 100 ns;
s<='0';
r<='1';
rst<='0';
wait for 100 ns;
s<='0';
r<='1';
rst<='1';
wait for 100 ns;
s<='1';
r<='0';
rst<='0';
wait for 100 ns;
s<='1';
r<='0';
rst<='1';
wait for 100 ns;
s<='1';
r<='1';
rst<='0';
Write a VHDL code for SR FF with synchronous reset and its testbench
code
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee. std_logic_arith.all;
use ieee. std_logic_unsigned.all;
entity srffvhdsrst is
Port ( s : in STD_LOGIC;
r : in STD_LOGIC;
clk : in STD_LOGIC;
q : out STD_LOGIC;
qb : out STD_LOGIC);
end srffvhdsrst;
architecture Behavioral of srffvhdsrst is
begin
process (clk)
variable tmp: std_logic;
begin
if(rising_edge(clk)) then
if(s='0' and r='0')then
tmp:=tmp;
elsif(s='1' and r='1')then
tmp:='Z';
elsif(s='0' and r='1')then
tmp:='0';
else
tmp:='1';
end if;
end if;
q <= tmp;
qb <= not tmp;
end process;
end behavioral;
s : IN std_logic;
r : IN std_logic;
clk : IN std_logic;
q : OUT std_logic;
qb : OUT std_logic
);
END COMPONENT;
--Inputs
signal s : std_logic := '0';
signal r : std_logic := '0';
signal clk : std_logic := '0';
--Outputs
signal q : std_logic;
signal qb : std_logic;
-- Clock period definitions
constant clk_period : time := 100 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: srffvhdsrst PORT MAP (
s => s,
r => r,
clk => clk,
q => q,
qb => qb
);
END;