Beruflich Dokumente
Kultur Dokumente
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component andgate port(a,b : in std_logic; y : out std_logic); end component; signal s1,s2,s3 : std_logic; begin A1:andgate port map(s1,s2,s3); process begin s1<='0'; s2<='0';
wait for 100ns; s1<='0'; s2<='1'; wait for 100ns; s1<='1'; s2<='0'; wait for 100ns; s1<='1'; s2<='1'; wait for 100ns; end process; end Test_arc;
OUTPUT:
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component orgate port(a,b : in std_logic; y : out std_logic); end component; signal s1,s2,s3 : std_logic; begin O1:orgate port map(s1,s2,s3); process begin s1<='0'; s2<='0';
wait for 100ns; s1<='0'; s2<='1'; wait for 100ns; s1<='1'; s2<='0'; wait for 100ns; s1<='1'; s2<='1'; wait for 100ns; end process; end Test_arc;
OUTPUT:
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component notgate port(a : in std_logic; y : out std_logic); end component; signal s1,s2 : std_logic; begin N1:notgate port map(s1,s2); process
begin s1<='0'; wait for 100ns; s1<='1'; wait for 100ns; end process; end Test_arc;
OUTPUT:
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component nandgate port(a,b : in std_logic; y : out std_logic); end component; signal s1,s2,s3 : std_logic; begin N2:nandgate port map(s1,s2,s3); process
begin s1<='0'; s2<='0'; wait for 100ns; s1<='0'; s2<='1'; wait for 100ns; s1<='1'; s2<='0'; wait for 100ns; s1<='1'; s2<='1'; wait for 100ns; end process; end Test_arc;
OUTPUT:
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component norgate port(a,b : in std_logic; y : out std_logic); end component; signal s1,s2,s3 : std_logic; begin N3:norgate port map(s1,s2,s3); process
10
begin s1<='0'; s2<='0'; wait for 100ns; s1<='0'; s2<='1'; wait for 100ns; s1<='1'; s2<='0'; wait for 100ns; s1<='1'; s2<='1'; wait for 100ns; end process; end Test_arc;
OUTPUT:
11
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component xorgate port(a,b : in std_logic; y : out std_logic); end component; signal s1,s2,s3 : std_logic; begin X1:xorgate port map(s1,s2,s3); process
12
begin s1<='0'; s2<='0'; wait for 100ns; s1<='0'; s2<='1'; wait for 100ns; s1<='1'; s2<='0'; wait for 100ns; s1<='1'; s2<='1'; wait for 100ns; end process; end Test_arc;
OUTPUT:
13
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component xnorgate port(a,b : in std_logic; y : out std_logic); end component; signal s1,s2,s3 : std_logic; begin X2:xnorgate port map(s1,s2,s3); process
14
begin s1<='0'; s2<='0'; wait for 100ns; s1<='0'; s2<='1'; wait for 100ns; s1<='1'; s2<='0'; wait for 100ns; s1<='1'; s2<='1'; wait for 100ns; end process; end Test_arc;
OUTPUT:
15
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component halfadd port(a,b : in std_logic; s,c : out std_logic); end component; signal s1,s2,s3,s4 : std_logic; begin HA1:halfadd port map(s1,s2,s3,s4);
16
process begin s1<='0'; s2<='0'; wait for 100ns; s1<='0'; s2<='1'; wait for 100ns; s1<='1'; s2<='0'; wait for 100ns; s1<='1'; s2<='1'; wait for 100ns; end process; end Test_arc;
OUTPUT:
17
TEST FILE:
Library ieee; use ieee.std_logic_1164.all; entity Test is end Test; architecture Test_arc of Test is component fulladd port(a,b,c : in std_logic; s,car : out std_logic); end component; signal s1,s2,s3,s4,s5 : std_logic; begin FA1:fulladd port map(s1,s2,s3,s4,s5);
18
process begin s1<='0'; s2<='0'; s3<='0'; wait for 100ns; s1<='0'; s2<='0'; s3<='1'; wait for 100ns; s1<='0'; s2<='1'; s3<='0'; wait for 100ns; s1<='0'; s2<='1'; s3<='1'; wait for 100ns; s1<='1'; s2<='0'; s3<='0'; wait for 100ns; s1<='1'; s2<='0'; s3<='1'; wait for 100ns; s1<='1'; s2<='1'; s3<='0'; wait for 100ns; s1<='1'; s2<='1'; s3<='1'; wait for 100ns; end process; end Test_arc;
19
OUTPUT:
20
entity HS_2 is Port(a,b:in std_logic; dif,bor:out std_logic); end HS_2; architecture HS_2_A of HS_2 is begin dif<=a XOR b; bor<=(NOT a) AND b; end HS_2_A;
TEST FILE:
Library ieee; use ieee.Std_logic_1164.all; entity Test is end Test; architecture Test_A of Test is component HS_2 Port(a,b:in std_logic; dif,bor:out std_logic); end component;
Signal a,b,dif,bor:std_logic;
21
begin A1:HS_2 port map(a,b,dif,bor); Process begin a<='0'; b<='0'; wait for 100 ns; a<='0'; b<='1'; wait for 100 ns; a<='1'; b<='0'; wait for 100 ns; a<='1'; b<='1'; wait for 100 ns; end process; end Test_A;
OUTPUT:
22
23
Process Variable t:std_logic_vector(2 downto 0):= "000"; begin a<=t(2); b<=t(1); bin<=t(0); wait for 100 ns; t:=t+ "001"; end process; end Test_A;
OUTPUT:
24
25
Process variable t:std_logic_vector(5 downto 0):= "000000"; begin s1<=t(5); s0<=t(4); i3<=t(3); i2<=t(2); i1<=t(1); i0<=t(0); wait for 100 ns; t:=t+ "00001"; end process; end Test_A ;
OUTPUT:
26
PROGRAM XIII: TO SIMULATE 4X1 MULTIPLEXER USING SELECT SIGNAL ASSIGNMENT STATEMENT
Library ieee; use ieee.Std_logic_1164.all; entity MUX_4X1 is Port(I:in std_logic_vector(3 downto 0); S:in std_logic_vector(1 downto 0); Y:out std_logic); end MUX_4X1; architecture MUX_4X1_A of MUX_4X1 is begin with s select Y<= I(0) when "00" , I(1) when "01" , I(2) when "10" , I(3) when "11"; end MUX_4X1_A;
27
Y:out std_logic); end component; Signal S : std_logic_vector(1 downto 0); Signal I : std_logic_vector(3 downto 0); signal Y : Std_logic; begin A1: MUX_4X1 port map(I,S,Y); Process variable t:std_logic_vector(1 downto 0):= "00"; begin S<=t; wait for 100 ns; t:=t+ "01"; end process; I<="0101" ; end Test_A ;
OUTPUT:
28
PROGRAM XIV: TO SIMULATE 4X1 MULTIPLEXER USING CONDITIONAL SIGNAL ASSIGNMENT STATEMENT
Library ieee; use ieee.Std_logic_1164.all; entity MUX_4X1 is Port(I:in std_logic_vector(3 downto 0); S:in std_logic_vector(1 downto 0); Y:out std_logic); end MUX_4X1; architecture MUX_4X1_A of MUX_4X1 is begin Y<= I(0) when S="00" else I(1) when S="01" else I(2) when S="10" else I(3); end MUX_4X1_A;
29
end component; Signal S : std_logic_vector(1 downto 0); Signal I : std_logic_vector(3 downto 0); signal Y : Std_logic; begin A1: MUX_4X1 port map(I,S,Y);
Process variable t:std_logic_vector(1 downto 0):= "00"; begin S<=t; wait for 100 ns; t:=t+ "01"; end process;
OUTPUT:
30
begin B1 : Block(E='1') begin sum<=a XOR b ; carry<= a AND b; end block B1; end FA_2_A;
TEST FILE:
Library ieee; use ieee.Std_logic_1164.all; entity Test is end Test; architecture Test_A of Test is component FA_2 Port(a,b,E:in std_logic; sum,carry:out std_logic);
31
end component;
32
OUTPUT:
33
34
component AND_2 Port(a,b:in std_logic; y:out std_logic); end component; component XOR_2 Port(a,b:in std_logic; y:out std_logic); end component; begin X1:XOR_2 port map(a,b,sum); A1:AND_2 port map(a,b,cout); end HA_2_A;
TEST FILE:
Library ieee; use ieee.Std_logic_1164.all; entity Test is end Test; architecture Test_A of Test is component HA_2 Port(a,b:in std_logic; sum,cout:out std_logic); end component; Signal a,b,sum,cout:Std_logic; begin A1:HA_2 port map(a,b,sum,cout);
Process
35
OUTPUT:
36
37
architecture OR_3_A of OR_3 is begin y<= (a OR b) OR c; end OR_3_A; entity OR_3 is port(a,b,c:in std_logic;y:out std_logic); end OR_3; architecture OR_3_A of OR_3 is begin y<= (a OR b) OR c; end OR_3_A; entity FA is port(a,b,cin:in std_logic; sum,cout:out std_logic); end FA; architecture FA_A of FA is component AND_2 Port(a,b:in std_logic; y:out std_logic); end component; component XOR_2 Port(a,b:in std_logic; y:out std_logic); end component; component OR_3 port(a,b,c:in std_logic;y:out std_logic); end component; signal t1,t2,t3,t4:std_logic; begin
38
X1:XOR_2 port map(a,b,t1); X2:XOR_2 port map(cin,t1,sum); A1:AND_2 port map(a,b,t2); A2:AND_2 port map(b,cin,t3); A3:AND_2 port map(cin,a,t4); O1:OR_3 port map(t2,t3,t4,cout); end FA_A;
TEST FILE:
Library ieee; use ieee.Std_logic_1164.all; entity Test is end Test; architecture Test_A of Test is component FA Port(a,b,cin:in std_logic; sum,cout:out std_logic); end component; Signal a,b,cin,sum,cout:Std_logic; begin A1:FA port map(a,b,cin,sum,cout); Process begin a<='0'; b<='0'; cin<='0'; wait for 100 ns; a<='0'; b<='0'; cin<='1'; wait for 100 ns; a<='0'; b<='1'; cin<='0';
39
wait for 100 ns; a<='0'; b<='1'; cin<='1'; wait for 100 ns; a<='1'; b<='0'; cin<='0'; wait for 100 ns; a<='1'; b<='0'; cin<='1'; wait for 100 ns; a<='1'; b<='1'; cin<='0'; wait for 100 ns; a<='1'; b<='1'; cin<='1'; wait for 100 ns; end process; end Test_A;
OUTPUT:
40
41
F1 : FA port map (A(0),B(0),'0',S(0),t(0)); F2 : FA port map (A(1),B(1),t(0),S(1),t(1)); F3 : FA port map (A(2),B(2),t(1),S(2),t(2)); F4 : FA port map (A(3),B(3),t(2),S(3),cout); end FA4_A; test Library ieee; use ieee.Std_logic_1164.all; use ieee.std_logic_unsigned.all;
architecture Test_A of Test is component FA4 Port(A,B:in std_logic_vector(3 downto 0); S:out std_logic_vector(3 downto 0); C:out std_logic); end component;
Signal A,B,S:Std_logic_vector(3 downto 0); signal C:Std_logic; begin A1: FA4 port map(A,B,S,C);
42
begin A<=t(7 downto 4); B<=t(3 downto 0); wait for 100 ns; t:=t+ "0000001";
OUTPUT:
43
PROGRAM XIX: JK FLIP FLOP WITH SYNCHRONOUS SET AND ASYNCHRONOUS RESET (BEHAVIOURAL MODELLING)
library ieee; use ieee.std_logic_1164.all; entity jk is port(j,k,clk,reset:in bit; Q :inout bit); end jk; architecture jk of jk is begin process(clk,reset) begin if reset='0' then Q<='0'; end if; if clk='0' and clk'event then Q<=(J and (not Q)) or ((not k) and Q); end if; end process; end jk;
TEST BENCH
library ieee; use ieee.std_logic_1164.all; entity test is end test; architecture test of test is component jk is port(j,k,clk,reset:in bit; Q:inout bit); end component; signal j,k,clk,reset,Q:bit; begin u1:jk port map(j,k,clk,reset,Q); process begin clk<='0' ; wait for 100ns; clk<='1' ; wait for 100ns; end process; process
44
begin reset<='0'; wait for 120ns; reset<='1' ; wait for 120ns; end process; process begin j<='0';k<='0'; wait for 100ns; j<='0'; k<='1'; wait for 100ns; j<='1';k<='0'; wait for 100ns; j<='1' ; k<='1'; wait for 100ns; end process; end test;
OUTPUT
45
PROGRAM XX: SR FLIP FLOP WITH SYNCHRONOUS SET AND ASYNCHRONOUS RESET (BEHAVIOURAL MODELLING)
library ieee; use ieee.std_logic_1164.all; entity SR is port(s,r,clk,reset:in std_logic; Q :inout std_logic); end SR; architecture sr of SR is begin process(clk,reset) begin if reset='0' then Q<='0'; elsif (clk='0' and clk'event) then if (s='1' and r='1') then Q<='-'; elsif (s='0' and r='0') then Q<=Q; elsif (s='0' and r='1') then Q<='0'; elsif (s='1' and r='0') then Q<='1'; end if; end if; end process; end sr;
TEST BENCH
library ieee; use ieee.std_logic_1164.all; entity test is end test; architecture test of test is component SR is port(s,r,clk,reset:in std_logic; Q:inout std_logic); end component;
46
signal s,r,clk,reset,Q:std_logic; begin u1:SR port map(s,r,clk,reset,Q); process begin clk<='0' ; wait for 100ns; clk<='1' ; wait for 100ns; end process; process begin reset<='0'; wait for 120ns; reset<='1' ; wait for 120ns; end process; process begin s<='0';s<='0'; wait for 100ns; s<='0'; r<='1'; wait for 100ns; s<='1';r<='0'; wait for 100ns; s<='1' ; r<='1'; wait for 100ns; end process; end test;
OUTPUT
47
PROGRAM XXI: T FLIP FLOP WITH SYNCHRONOUS SET AND ASYNCHRONOUS RESET (BEHAVIOURAL MODELLING)
library ieee; use ieee.std_logic_1164.all; entity T is port(t,clk,reset:in std_logic; Q :inout std_logic); end T; architecture tfilp of T is begin process(clk,reset) variable f:std_logic; begin if reset='0' then f:='0'; elsif falling_edge(clk) then if t='0' then f:=Q; elsif t='1' then f:=(not Q); end if; end if; Q<=f; end process; end tfilp;
TEST BENCH
library ieee; use ieee.std_logic_1164.all; entity test is end test; architecture test of test is component T is port(t,clk,reset:in std_logic; Q:inout std_logic); end component; signal t,clk,reset,Q:std_logic; begin
48
u1:T port map(t,clk,reset,Q); process begin clk<='0' ; wait for 100ns; clk<='1' ; wait for 100ns; end process; process begin reset<='0'; wait for 120ns; reset<='1' ; wait for 120ns; end process; process begin t<='0'; wait for 80ns; t<='1' ; wait for 80ns; end process; end test;
OUTPUT
49
TEST BENCH
library ieee; use ieee.std_logic_1164.all; entity test is end test; architecture test of test is component D is port(d,clk,reset:in std_logic; Q:inout std_logic); end component;
50
signal d,clk,reset,Q:std_logic; begin u1:D port map(d,clk,reset,Q); process begin clk<='0' ; wait for 100ns; clk<='1' ; wait for 100ns; end process; process begin reset<='0'; wait for 120ns; reset<='1' ; wait for 120ns; end process; process begin d<='0'; wait for 80ns; d<='1' ; wait for 80ns; end process; end test;
OUTPUT
51
TEST BENCH
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity test is end test; architecture test1 of test is component bcd is port(b:in std_logic_vector(3 downto 0); y:out integer); end component; signal b: std_logic_vector(3 downto 0); signal y: integer; begin
52
u1:bcd port map(b,y); process variable t:std_logic_vector(3 downto 0):="0000"; begin t:=t+"0001"; wait for 100ns; if( t="1010") then t:="0000"; end if; b<=t; end process; end test1;
OUTPUT
53
TEST BENCH
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity test is end test; architecture test1 of test is component bcd is port(b:in std_logic_vector(3 downto 0); y:out std_logic_vector(3 downto 0)); end component; signal b,y: std_logic_vector(3 downto 0); begin u1:bcd port map(b,y); process variable t:std_logic_vector(3 downto 0):="0000"; begin t:=t+"0001"; wait for 100ns; if( t="1010") then t:="0000"; end if;
54
OUTPUT
55
TEST BENCH
library ieee; use ieee.std_logic_1164.all; entity test is end test; architecture test_a of test is component Decoder_2 port(a,b:in std_logic; I:out std_logic_vector(3 downto 0));
56
end component; signal a,b:std_logic; signal I:std_logic_vector(3 downto 0); begin D1:Decoder_2 port map(a,b,I); Process begin a<='0';b<='0'; wait for 100ns;
a<='0';b<='1'; wait for 100ns; a<='1';b<='0'; wait for 100ns; a<='1';b<='1'; wait for 100ns; end process; end test_a;
OUTPUT
57
TEST BENCH
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity test is end test; architecture test1 of test is component decoder is port(b:in std_logic_vector(1 downto 0); y:out std_logic_vector(3 downto 0)); end component; signal b: std_logic_vector(1 downto 0);
58
signal y:std_logic_vector(3 downto 0); begin u1:decoder port map(b,y); process variable t:std_logic_vector(1 downto 0):="00"; begin t:=t+"01"; wait for 100ns; if( t > "11") then t:="00"; end if; b<=t; end process; end test1;
OUTPUT
59
TEST BENCH
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity test is end test; architecture test_a of test is component graytobin port(g: in std_logic_vector(3 downto 0); b: out std_logic_vector(3 downto 0)); end component;
60
signal b,g:std_logic_vector(3 downto 0); begin gb1:graytobin port map(g,b); process variable t: std_logic_vector(3 downto 0):="0000"; begin for i in 0 to 15 loop g(0)<=t(0); g(1)<=t(1); g(2)<=t(2); g(3)<=t(3); wait for 100ns; t:=t+"0001"; end loop; end process; end test_a;
OUTPUT
61
TEST BENCH
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity test is end test; architecture test1 of test is component comp is port(a,b:in std_logic_vector(1 downto 0); y:out integer); end component; signal a,b: std_logic_vector(1 downto 0); signal y:integer; begin u1:comp port map(a,b,y); process variable t:std_logic_vector(3 downto 0):="0000"; begin t:=t+"0001"; wait for 100ns; a<=t(3 downto 2); b<=t(1 downto 0); if( t="1111") then
62
OUTPUT
63
TEST BENCH
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity Test is end Test; architecture Test_A of Test is component twobitmul is port(A:in std_logic_vector(1 downto 0); B:in std_logic_vector(1 downto 0); y: out std_logic_vector(3 downto 0));
64
end component; signal A:std_logic_vector(1 downto 0); signal B:std_logic_vector(1 downto 0); signal y:std_logic_vector(3 downto 0); begin t1:twobitmul port map(A,B,y); process variable t:std_logic_vector(3 downto 0):="0000"; begin for i in 0 to 15 loop A(1)<=t(3); B(1)<=t(2); A(0)<=t(1); B(0)<=t(0); t:=t+"0001"; wait for 100ns; end loop; end process; end Test_A;
OUTPUT
65
TEST BENCH
library ieee; use ieee.std_logic_1164.all; entity test is end test; architecture test of test is component shift is port(si,clk,reset:in std_logic; Q :out std_logic_vector(3 downto 0)); end component; signal si,clk,reset:std_logic; signal Q:std_logic_vector(3 downto 0); begin u1:shift port map(si,clk,reset,Q); process begin
66
si<='0';wait for 5ns; si<='0';wait for 5ns; end process; process begin clk<='0';wait for 20ns; clk<='1';wait for 20ns; end process; process begin reset<='0';wait for 150ns; reset<='1';wait for 150ns; end process; end test;
OUTPUT
67
TEST BENCH
library ieee; use ieee.std_logic_1164.all; entity test is end test; architecture test of test is component counter is port(clk,reset:in std_logic; Q:out std_logic_vector(2 downto 0)); end component; signal Q:std_logic_vector(2 downto 0); signal clk,reset:std_logic; begin u1:counter port map(clk,reset,Q);
68
process begin clk<='0' ;wait for 20ns; clk<='1' ;wait for 20ns; end process; process begin reset<='0'; wait for 280ns; reset<='1' ;wait for 280ns; end process; end test;
OUTPUT
69
architecture BinTGray_A of BinTGray is begin g(0)<=b(0) xor b(1); g(1)<=b(1) xor b(2); g(2)<=b(2) xor b(3); g(3)<=b(3); end BinTGray_A;
TestBench:
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity Test is end Test; architecture Test_A of Test is component BinTGray port(b:in std_logic_vector(3 downto 0); g:out std_logic_vector(3 downto 0)); end component;
70
signal b,g:std_logic_vector(3 downto 0); begin BG1:BinTGray port map(b,g); process variable t:std_logic_vector(3 downto 0):="0000"; begin for i in 0 to 15 loop b(0)<=t(0); b(1)<=t(1); b(2)<=t(2); b(3)<=t(3); wait for 100ns; t:=t+"0001"; end loop; end process; end Test_A;
Output:
71
Testbench:
library ieee; use ieee.std_logic_1164.all;
72
architecture BCDTDecimal_A of BCDTDecimal is begin with b select output<="1111110" when "0000", "0110000" when "0001", "1101101" when "0010", "1111001" when "0011", "0110011" when "0100", "1011011" when "0101", "1011111" when "0110", "1110000" when "0111", "1111111" when "1000", "1111011" when "1001"; end BCDTDecimal_A;
Output: