EDA Playground lets you type in and run HDL code (using a selection of free and commercial simulators and synthesizers).
It's great for learning HDLs, it's great for testing out unfamiliar things and it's great for sharing code.
You can start typing straight away. But to run your code, you'll need to sign or log in. Logging in with a Google account gives you access to all non-commercial simulators and some commercial simulators:
To run commercial simulators, you need to register and log in with a username and password. Registration is free, and only pre-approved email's will have access to the commercial simulators.
204
----------------------------------------------------------
--
-- Testbench for full adder.
-- Nexys A7-50T, xc7a50ticsg324-1L
-- TerosHDL, Vivado v2020.2, EDA Playground
--
-- Copyright (c) 2019 Tomas Fryza
-- Dept. of Radio Electronics, Brno Univ. of Technology, Czechia
-- This work is licensed under the terms of the MIT license.
--
----------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
----------------------------------------------------------
-- Entity declaration for testbench
----------------------------------------------------------
entity tb_full_adder is
-- Entity of testbench is always empty
end entity tb_full_adder;
----------------------------------------------------------
-- Architecture body for testbench
----------------------------------------------------------
architecture testbench of tb_full_adder is
-- Local signals for full adder
signal sig_a : std_logic;
signal sig_b : std_logic;
signal sig_carry_in : std_logic;
signal sig_sum : std_logic;
signal sig_carry : std_logic;
begin
-- Connecting testbench signals with full_adder
-- entity (Unit Under Test)
uut_full : entity work.full_adder
port map (
a => sig_a,
b => sig_b,
carry_in => sig_carry_in,
sum => sig_sum,
carry => sig_carry
);
--------------------------------------------------------
-- Data generation process
--------------------------------------------------------
p_stimulus : process is
begin
report "Stimulus process started";
sig_carry_in <= '0';
sig_b <= '0';
sig_a <= '0';
wait for 100 ns;
assert (
(sig_carry = '0') and
(sig_sum = '0')
) -- Expected output
report "Test failed for input combination 000"
severity error;
sig_carry_in <= '0';
sig_b <= '0';
sig_a <= '1';
wait for 100 ns;
assert (
(sig_carry = '0') and
(sig_sum = '1')
)
report "Test failed for input combination 001"
severity error;
sig_carry_in <= '0';
sig_b <= '1';
sig_a <= '0';
wait for 100 ns;
assert (
(sig_carry = '0') and
(sig_sum = '1')
)
report "Test failed for input combination 010"
severity error;
sig_carry_in <= '0';
sig_b <= '1';
sig_a <= '1';
wait for 100 ns;
assert (
(sig_carry = '1') and
(sig_sum = '0')
)
report "Test failed for input combination 011"
severity error;
sig_carry_in <= '1';
sig_b <= '0';
sig_a <= '0';
wait for 100 ns;
assert (
(sig_carry = '0') and
(sig_sum = '1')
)
report "Test failed for input combination 100"
severity error;
sig_carry_in <= '1';
sig_b <= '0';
sig_a <= '1';
wait for 100 ns;
assert (
(sig_carry = '1') and
(sig_sum = '0')
)
report "Test failed for input combination 101"
severity error;
sig_carry_in <= '1';
sig_b <= '1';
sig_a <= '0';
wait for 100 ns;
assert (
(sig_carry = '1') and
(sig_sum = '0'))
report "Test failed for input combination 110"
severity error;
sig_carry_in <= '1';
sig_b <= '1';
sig_a <= '1';
wait for 100 ns;
assert (
(sig_carry = '1') and
(sig_sum = '1')
)
report "Test failed for input combination 111"
severity error;
report "Stimulus process finished";
wait;
end process p_stimulus;
end architecture testbench;
xxxxxxxxxx
----------------------------------------------------------
--
-- Testbench for half adder.
-- Nexys A7-50T, xc7a50ticsg324-1L
-- TerosHDL, Vivado v2020.2, EDA Playground
--
-- Copyright (c) 2019 Tomas Fryza
-- Dept. of Radio Electronics, Brno Univ. of Technology, Czechia
-- This work is licensed under the terms of the MIT license.
--
----------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
----------------------------------------------------------
-- Entity declaration for testbench
----------------------------------------------------------
entity tb_half_adder is
-- Entity of testbench is always empty
end entity tb_half_adder;
----------------------------------------------------------
-- Architecture body for testbench
----------------------------------------------------------
architecture testbench of tb_half_adder is
-- Local signals for half adder
signal sig_a : std_logic;
signal sig_b : std_logic;
signal sig_sum : std_logic;
signal sig_carry : std_logic;
begin
-- Connecting testbench signals with half_adder
-- entity (Unit Under Test)
uut_half : entity work.half_adder
port map (
a => sig_a,
b => sig_b,
sum => sig_sum,
carry => sig_carry
);
--------------------------------------------------------
-- Data generation process
--------------------------------------------------------
p_stimulus : process is
begin
report "Stimulus process started";
sig_b <= '0';
sig_a <= '0';
wait for 100 ns;
assert (
(sig_carry = '0') and
(sig_sum = '0')
) -- Expected output
report "Test failed for input combination 00"
severity error;
sig_b <= '0';
sig_a <= '1';
wait for 100 ns;
assert (
(sig_carry = '0') and
(sig_sum = '1')
)
report "Test failed for input combination 01"
severity error;
sig_b <= '1';
sig_a <= '0';
wait for 100 ns;
assert (
(sig_carry = '0') and
(sig_sum = '1')
)
report "Test failed for input combination 10"
severity error;
sig_b <= '1';
sig_a <= '1';
wait for 100 ns;
assert (
(sig_carry = '1') and
(sig_sum = '0')
)
report "Test failed for input combination 11"
severity error;
report "Stimulus process finished";
wait;
end process p_stimulus;
end architecture testbench;
xxxxxxxxxx
----------------------------------------------------------
--
--! @title Full adder
--! @author Tomas Fryza
--! Dept. of Radio Electronics, Brno Univ. of Technology, Czechia
--!
--! @copyright (c) 2019 Tomas Fryza
--! This work is licensed under the terms of the MIT license
--!
--! Implementation of full adder.
--
-- Hardware: Nexys A7-50T, xc7a50ticsg324-1L
-- Software: TerosHDL, Vivado 2020.2, EDA Playground
library ieee;
use ieee.std_logic_1164.all;
----------------------------------------------------------
-- Entity declaration for full adder
----------------------------------------------------------
entity full_adder is
port (
a : in std_logic;
b : in std_logic;
carry_in : in std_logic;
sum : out std_logic;
carry : out std_logic
);
end entity full_adder;
----------------------------------------------------------
-- Architecture body for full adder
----------------------------------------------------------
architecture behavioral of full_adder is
-- Internal signals between half adders
signal sig_sum0_a1 : std_logic; -- From sum0 to a1
signal sig_carry0 : std_logic;
signal sig_carry1 : std_logic;
begin
--------------------------------------------------------
-- Instance (copy) of the first half adder
half_adder0 : entity work.half_adder
port map (
a => a,
b => b,
sum => sig_sum0_a1,
carry => sig_carry0
);
--------------------------------------------------------
-- Instance (copy) of the second half adder
half_adder1 : entity work.half_adder
port map (
a => sig_sum0_a1,
b => carry_in,
sum => sum,
carry => sig_carry1
);
-- Output carry
carry <= sig_carry0 or sig_carry1;
end architecture behavioral;
xxxxxxxxxx
----------------------------------------------------------
--
--! @title Half adder
--! @author Tomas Fryza
--! Dept. of Radio Electronics, Brno Univ. of Technology, Czechia
--!
--! @copyright (c) 2019 Tomas Fryza
--! This work is licensed under the terms of the MIT license
--!
--! Implementation of half adder.
--
-- Hardware: Nexys A7-50T, xc7a50ticsg324-1L
-- Software: TerosHDL, Vivado 2020.2, EDA Playground
library ieee;
use ieee.std_logic_1164.all;
----------------------------------------------------------
-- Entity declaration for half adder
----------------------------------------------------------
entity half_adder is
port (
a : in std_logic;
b : in std_logic;
sum : out std_logic;
carry : out std_logic
);
end entity half_adder;
----------------------------------------------------------
-- Architecture body for half adder
----------------------------------------------------------
architecture behavioral of half_adder is
begin
sum <= a xor b;
carry <= a and b;
end architecture behavioral;
Your account is not validated. If you wish to use commercial simulators, you need a validated account.
If you have already registered (or have recently changed your email address), but have not clicked on the link in the email we sent you, please do so. If you cannot find the email, please check your spam/junk folder. Or click here to resend the email.
If you have not already registered for a full account, you can do so by clicking below. You will then need to provide us with some identification information. You may wish to save your code first.
Creating, deleting, and renaming files is not supported during Collaboration. To encourage development of these features for Collaboration, tweet to @EDAPlayground
This playground may have been modified. Please save or copy before starting collaboration.
Your exercise has been submitted.