In this project, we will see how to implement all logic gates with testbench code on Xilinx Vivado design tool. Below diagram shows all logic gates along with there truth tables, symbol and Boolean equation.
Now let us see how we will implement these gates using Xilinx Vivado design tool.
Step 1: Click on New Project -> Next
Step 2: Enter Project Name and Select appropriate Project Location -> Next
Step 3: Select RTL Project -> Next
Step 4: Click on Create File and create file with file name and_gate -> Next
Step 5: We will not add the Constraint file So click on Next
Step 6: For Default Part click on Next as we are not using any development Board
Step 7: Check the New Project Summary and click on Finish.
Step 8: Now you will be prompted with the Define module page but we will create the complete code from scratch so click on cancel and Yes
Step 9: Now on the Home Page click on Sources -> Design Sources -> Non-module Files
Step 10: Enter the below codes in the “and_gate.vhd” files.
and_gate.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and_gate is
Port (
a: in std_logic;
b: in std_logic;
c: out std_logic);
end and_gate;
architecture Behavioral of and_gate is
begin
c<= a and b;
end Behavioral;
Step 11: Now to write the testbench code for and gate right click on Design Sources -> Add Sources -> Add or create design sources -> Create File -> Add File name as tb_and_gate -> Finish -> Ok -> Yes
Step 12: Now open the testbench file and enter the below testbench code
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_and_gate is
end tb_and_gate;
architecture Behavioral of tb_and_gate is
component and_gate is
Port(a: in std_logic;
b: in std_logic;
c: out std_logic);
end component;
signal tb_a,tb_b,tb_c : std_logic:=’0';
begin
uut : and_gate port map(
a=>tb_a, b=>tb_b, c=>tb_c
);
stim_process: process
begin
tb_a<=’0' ; tb_b<=’0'; wait for 100ns;
tb_a<=’0' ; tb_b<=’1'; wait for 100ns;
tb_a<=’1' ; tb_b<=’0'; wait for 100ns;
tb_a<=’1' ; tb_b<=’1'; wait for 100ns;
end process;
end Behavioral;
Here, in testbench code we do not define values in entity hence we have kept it empty. Then in architecture we have copied the components of and_gate and defined signals for connecting the ports of and gate. Inside the process statement we write all 4 test cases from truth table and define the delay as 100ns.
Step 13: Now as we have written all the codes let’s launch the simulation. Enter launch_simulation in the Tcl Console and press Enter.
We have successfully implemented and gate with testbench code. Click on Zoom Fit to see the output waveform more clearly and verify the outputs.
No comments:
Post a Comment