Professional Documents
Culture Documents
Vlsi
Vlsi
ALU
library IEEE;
use IEEE.STD_LOGIC_unsigned.all;
entity alu is
cin: in STD_LOGIC);
end alu;
---ARITHMETIC UNIT
b when "011",
a OR b when "011",
end behavioral;
Test Bench:
library IEEE;
--Library UNISIM:
--use UNISIN. VComponents.all
end alu_tb;
component alu is
end component;
begin
process
begin
a<="0001";
b<="1111";
cin<='0';
end process;
process
begin
sel<= sel+'1';
end process;
end Behavioral;
USR
USR
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.NUMERIC_STD.ALL;
--library UNISIM;
--use UNISIM.VComponents.all;
entity sh4 is
end sh4;
process(clk,in4,load1,out4)
begin
if(load1='1') THEN
s4 <= in4;
else
s4 <= out4;
end if;
end if;
end process;
end Behavioral;
--PIPO TestBench
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity pipo_tb is
end pipo_tb;
component sh4 is
end component;
begin
process
begin
clk<= '0';
clk<= '1';
wait for 10 ns ;
end process;
process
begin
load1<= '1';
in4<= "1010";
load1<= '0';
in4<= "0011";
in4<= "1111";
end process;
end beh;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
load : in STD_LOGIC;
end sh3;
signal s3 : STD_LOGIC;
begin
process(clk,in3,load,s3)
begin
if(load='1') THEN
s3 <= temp(3);
end if;
end process;
end Behavioral;
--PISO TB
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity piso_tb is
end piso_tb;
component sh3
load : in STD_LOGIC;
end component;
signal clk, load, out3: std_logic;
begin
process
begin
clk<= '0';
clk<= '1';
wait for 10 ns ;
end process;
Process
begin
load<= '1' ;
in3<= "1100";
load<= '0';
end process;
end beh;
-- SIPO MainCode
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity sh2 is
in2 : in STD_LOGIC;
end sh2;
begin
process(clk,in2,out2)
begin
end if;
end process;
end Behavioral;
--SIPO TestBench
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity sipo_tb is
end sipo_tb;
component sh2 is
in2 : in STD_LOGIC;
end component;
begin
process
begin
clk<= '0';
clk<= '1';
wait for 10 ns ;
end process;
end beh;
--SISO Maincode
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity sh1 is
in1 : in STD_LOGIC;
end sh1;
begin
process(clk,in1,s1)
begin
end if;
end process;
end Behavioral;
-- SISO Testbench
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity siso_tb is
end siso_tb;
component sh1
in1 : in STD_LOGIC;
end component;
begin
process
begin
clk<= '0';
clk<= '1';
wait for 20 ns ;
end process;
in1<= '1', '0' after 80 ns;
end beh;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;
--library UNISIM;
--use UNISIM.VComponents.all;
entity sh_uni is
load : in STD_LOGIC;
si : in STD_LOGIC;
component sh1
in1 : in STD_LOGIC;
end component;
component sh2
in2 : in STD_LOGIC;
end component;
component sh3
load : in STD_LOGIC;
end component;
component sh4
load1 : in STD_LOGIC;
end component;
begin
end Behavioral;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
--USE ieee.numeric_std.ALL;
ENTITY usr_test IS
END usr_test;
COMPONENT sh_uni
PORT(
clk : IN std_logic;
load : IN std_logic;
si : IN std_logic;
);
END COMPONENT;
--Inputs
--BiDirs
--Outputs
signal so : std_logic;
BEGIN
po => po
);
clk_process :process
begin
end process;
stim_proc: process
begin
si<= '1';
wait for 20 ns ;
si<= '0';
wait for 20 ns ;
si<= '1';
si<= '0';
wait for 20 ns ;
sel<= "01";
si<= '1';
si<= '0';
wait for 20 ns;
si<= '1';
si<= '1';
load<= '1' ,'0' after 20 ns,'1' after 100 ns, '0' after 120 ns;
pi<= "1100";
pi<="1111";
load<= '1', '0' after 20 ns, '1' after 100 ns, '0' after 120 ns;
pi<= "0010";
pi<= "0100";
end process;
END;
MOD-N Counter
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity count is
Port ( clk : in STD_LOGIC;
clk_div: inout std_logic;
rst : in STD_LOGIC;
an : out std_logic_vector(3 downto 0);
seg : out std_logic_vector(6 downto 0);
q : inout STD_LOGIC_VECTOR (3 downto 0));
end count;
architecture Behavioral of count is
signal count : std_logic_vector( 25 downto 0):= (others => '0');
begin
an<="0001";
process(clk_div,rst)
variable temp: std_logic_vector(3 downto 0):="0000";
begin
if (rst='1') then
temp:= "0000";
elsif (clk_div'event and clk_div='1') then
temp:= temp+'1';
if( temp > "1001") then
temp := "0000";
end if;
end if;
q<=temp;
end process;
process(clk)
begin
if (clk'event and clk='1') then
count <= count + '1';
end if;
clk_div<= count(0);
end process;
--clk_div<= count(1);
process(q)
begin
case q is
when "0000" => seg <= "1000000"; -- 0
when "0001" => seg <= "1001111"; -- 1
when "0010" => seg <= "0100100"; -- 2
when "0011" => seg <= "0110000"; -- 3
when "0100" => seg <= "0011001"; -- 4
when "0101" => seg <= "0010010"; -- 5
when "0110" => seg <= "0000010"; -- 6
when "0111" => seg <= "1111000"; -- 7
when "1000" => seg <= "0000000"; -- 8
when "1001" => seg <= "0010000"; -- 9
when others => seg <= "1111111";
end case;
end process;
end Behavioral;
Test Bench
—-Testbench
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity COUNTER_TB is
-- Port ( );
end COUNTER_TB;
architecture Behavioral of COUNTER_TB is
COMPONENT count is
Port ( clk : in STD_LOGIC;
clk_div: inout std_logic;
rst : in STD_LOGIC;
q : inout STD_LOGIC_VECTOR (3 downto 0));
end component;
signal clk,clk_div: std_logic;
signal rst:std_logic;
signal q: std_logic_vector(3 downto 0);
begin
u1: count port map(clk,clk_div,rst,q);
process
begin
clk<='1';
wait for 100 ns;
clk<='0';
wait for 100 ns;
end process;
rst<='1', '0' after 300 ns ;
end Behavioral;
FIFO
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity fifoo is
GENERIC
(
ADDRESS_WIDTH:integer:=2;
DATA_WIDTH:integer:=4
);
Port ( clk : in STD_LOGIC;
-- clk_div : inout STD_LOGIC;
reset : in STD_LOGIC;
enr : in STD_LOGIC;
enw : in STD_LOGIC;
dataout : out STD_LOGIC_VECTOR (DATA_WIDTH-1 downto 0);
datain : in STD_LOGIC_VECTOR (DATA_WIDTH-1 downto 0);
empty : out STD_LOGIC;
error : out STD_LOGIC;
full : out STD_LOGIC);
end fifoo;
architecture Behavioral of fifoo is
type memory_type is array(0 to ((2**ADDRESS_WIDTH)-1)) of STD_LOGIC_VECTOR(DATA_WIDTH-1
downto 0);
signal memory:memory_type;
signal readptr,writeptr: STD_LOGIC_VECTOR(ADDRESS_WIDTH-1 downto 0):="00";
signal full0:STD_LOGIC:='0';
signal empty0:STD_LOGIC:='1';
signal counter:STD_LOGIC_VECTOR(30 downto 0):=(others=>'0');
signal clk_div:STD_LOGIC:='0';
begin
full<=full0;
empty<=empty0;
fifo0:process(clk_div,reset,datain,enw,enr)
begin
if reset='1'thenreadptr<=(others=>'0');
writeptr<=(others=>'0');
empty0<='1';
full0<='0';
error<='0';
elsif clk_div'event and clk_div='1' then
if enw='1' and full0='0' then
memory (conv_integer(writeptr))<=datain;
writeptr<=writeptr+'1';
if(writeptr+'1'=readptr) then
full0<='1';
empty0<='0';
else
full0<='0';
empty<='1';
end if;
end if;
end if;
if enr='1' and empty0='0' then
dataout<=memory(conv_integer(readptr));
readptr<=readptr+'1';
if(readptr+'1'=writeptr) then
full0<='0';
empty0<='1';
else
full0<='1';
empty0<='0';
end if;
end if;
if(empty0='1' and enr='1') or (full0='1' and enw='1') then
error<='1';
else
error<='0';
end if;
end process;
process(clk)
begin
if(clk'EVENT and clk='1') then
counter<=counter+1;
end if;
end process;
clk_div<=counter(0);
end Behavioral;
Test Bench
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity fifoo_test is
-- PORT();
end fifoo_test;
architecture Behavioral of fifoo_test is
component fifoo is
GENERIC
(
ADDRESS_WIDTH:integer:=2;
DATA_WIDTH:integer:=4
);
Port ( clk : in STD_LOGIC;
-- clk_div : inout STD_LOGIC;
reset : in STD_LOGIC;
enr : in STD_LOGIC;
enw : in STD_LOGIC;
dataout : out STD_LOGIC_VECTOR (3 downto 0);
datain : in STD_LOGIC_VECTOR (3 downto 0);
empty : out STD_LOGIC;
error : out STD_LOGIC;
full : out STD_LOGIC);
end component;
signal clk:STD_LOGIC:='0';
signal reset:STD_LOGIC;
signal enr:STD_LOGIC;
signal enw:STD_LOGIC;
signal dataout:STD_LOGIC_VECTOR(3 downto 0);
signal datain:STD_LOGIC_VECTOR(3 downto 0);
signal empty:STD_LOGIC;
signal error:STD_LOGIC;
signal full:STD_LOGIC;
beginU1: fifoo port map(clk,reset,enr,enw,dataout,datain,empty,error,full);
process
begin
clk<='1';
wait for 20 ns;
clk<='0';
wait for 20 ns;
end process;
process
begin
reset<='1';
wait for 20 ns;
reset<='0';
datain<="1010";
enw<='1';
enr<='0';
wait for 200 ns;
enw<='0';
enr<='1';
wait for 200 ns;
end process;
end Behavioral;
MicroWind
CMOS inverter
NAND Gate
NOR Gate
HALF Adder
Inverter with Capacitor
2:1 MUX (CMOS)
2:1 MUX (TG)
Comments