Brno_Univ_of_Technology_Full adder example - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

204


151
 
1
----------------------------------------------------------
2
--
3
-- Testbench for full adder.
4
-- Nexys A7-50T, xc7a50ticsg324-1L
5
-- TerosHDL, Vivado v2020.2, EDA Playground
6
--
7
-- Copyright (c) 2019 Tomas Fryza
8
-- Dept. of Radio Electronics, Brno Univ. of Technology, Czechia
9
-- This work is licensed under the terms of the MIT license.
10
--
11
----------------------------------------------------------
12
13
library ieee;
14
  use ieee.std_logic_1164.all;
15
16
----------------------------------------------------------
17
-- Entity declaration for testbench
18
----------------------------------------------------------
19
20
entity tb_full_adder is
21
-- Entity of testbench is always empty
22
end entity tb_full_adder;
23
24
----------------------------------------------------------
25
-- Architecture body for testbench
26
----------------------------------------------------------
27
28
architecture testbench of tb_full_adder is
29
30
  -- Local signals for full adder
31
  signal sig_a        : std_logic;
32
  signal sig_b        : std_logic;
33
  signal sig_carry_in : std_logic;
34
  signal sig_sum      : std_logic;
35
  signal sig_carry    : std_logic;
36
37
begin
38
39
  -- Connecting testbench signals with full_adder
40
  -- entity (Unit Under Test)
41
  uut_full : entity work.full_adder
42
    port map (
43
      a        => sig_a,
44
      b        => sig_b,
45
      carry_in => sig_carry_in,
46
      sum      => sig_sum,
47
      carry    => sig_carry
48
    );
49
50
  --------------------------------------------------------
51
  -- Data generation process
52
  --------------------------------------------------------
53
  p_stimulus : process is
54
  begin
55
56
    report "Stimulus process started";
57
58
    sig_carry_in <= '0';
59
    sig_b        <= '0';
60
    sig_a        <= '0';
61
    wait for 100 ns;
62
    assert (
63
        (sig_carry = '0') and
64
        (sig_sum   = '0')
65
      )  -- Expected output
66
      report "Test failed for input combination 000"
67
      severity error;
68
69
    sig_carry_in <= '0';
70
    sig_b        <= '0';
71
    sig_a        <= '1';
72
    wait for 100 ns;
73
    assert (
74
        (sig_carry = '0') and
75
        (sig_sum   = '1')
76
      )
77
      report "Test failed for input combination 001"
78
      severity error;
79
80
    sig_carry_in <= '0';
81
    sig_b        <= '1';
82
    sig_a        <= '0';
83
    wait for 100 ns;
84
    assert (
85
        (sig_carry = '0') and
86
        (sig_sum   = '1')
87
      )
88
      report "Test failed for input combination 010"
89
      severity error;
90
91
    sig_carry_in <= '0';
92
    sig_b        <= '1';
93
    sig_a        <= '1';
94
    wait for 100 ns;
95
    assert (
96
        (sig_carry = '1') and
97
        (sig_sum   = '0')
98
      )
99
      report "Test failed for input combination 011"
100
      severity error;
101
102
    sig_carry_in <= '1';
103
    sig_b        <= '0';
104
    sig_a        <= '0';
105
    wait for 100 ns;
106
    assert (
107
        (sig_carry = '0') and
108
        (sig_sum   = '1')
109
      )
110
      report "Test failed for input combination 100"
111
      severity error;
112
113
    sig_carry_in <= '1';
114
    sig_b        <= '0';
115
    sig_a        <= '1';
116
    wait for 100 ns;
117
    assert (
118
        (sig_carry = '1') and
119
        (sig_sum   = '0')
120
      )
121
      report "Test failed for input combination 101"
122
      severity error;
123
124
    sig_carry_in <= '1';
125
    sig_b        <= '1';
126
    sig_a        <= '0';
127
    wait for 100 ns;
128
    assert (
129
        (sig_carry = '1') and
130
        (sig_sum   = '0'))
131
      report "Test failed for input combination 110"
132
      severity error;
133
134
    sig_carry_in <= '1';
135
    sig_b        <= '1';
136
    sig_a        <= '1';
137
    wait for 100 ns;
138
    assert (
139
        (sig_carry = '1') and
140
        (sig_sum   = '1')
141
      )
142
      report "Test failed for input combination 111"
143
      severity error;
144
145
    report "Stimulus process finished";
146
    wait;
147
148
  end process p_stimulus;
149
150
end architecture testbench;
151
xxxxxxxxxx
1
69
 
1
----------------------------------------------------------
2
--
3
--! @title Full adder
4
--! @author Tomas Fryza
5
--! Dept. of Radio Electronics, Brno Univ. of Technology, Czechia
6
--!
7
--! @copyright (c) 2019 Tomas Fryza
8
--! This work is licensed under the terms of the MIT license
9
--!
10
--! Implementation of full adder.
11
--
12
-- Hardware: Nexys A7-50T, xc7a50ticsg324-1L
13
-- Software: TerosHDL, Vivado 2020.2, EDA Playground
14
15
library ieee;
16
  use ieee.std_logic_1164.all;
17
18
----------------------------------------------------------
19
-- Entity declaration for full adder
20
----------------------------------------------------------
21
22
entity full_adder is
23
  port (
24
    a        : in    std_logic;
25
    b        : in    std_logic;
26
    carry_in : in    std_logic;
27
    sum      : out   std_logic;
28
    carry    : out   std_logic
29
  );
30
end entity full_adder;
31
32
----------------------------------------------------------
33
-- Architecture body for full adder
34
----------------------------------------------------------
35
36
architecture behavioral of full_adder is
37
38
  -- Internal signals between half adders
39
  signal sig_sum0_a1 : std_logic;  -- From sum0 to a1
40
  signal sig_carry0  : std_logic;
41
  signal sig_carry1  : std_logic;
42
43
begin
44
45
  --------------------------------------------------------
46
  -- Instance (copy) of the first half adder
47
  half_adder0 : entity work.half_adder
48
    port map (
49
      a     => a,
50
      b     => b,
51
      sum   => sig_sum0_a1,
52
      carry => sig_carry0
53
    );
54
55
  --------------------------------------------------------
56
  -- Instance (copy) of the second half adder
57
  half_adder1 : entity work.half_adder
58
    port map (
59
      a     => sig_sum0_a1,
60
      b     => carry_in,
61
      sum   => sum,
62
      carry => sig_carry1
63
    );
64
65
  -- Output carry
66
  carry <= sig_carry0 or sig_carry1;
67
68
end architecture behavioral;
69
321 views and 0 likes     
 
Example of dataflow style modeling for half adder and structural style of modeling for full adder. Testbenches for both, half and full added entities.
For half adder simulation, parameter **Top entity** will be **tb_half_adder**.
For full adder simulation, parameter **Top entity** will be **tb_full_adder**.

Example of dataflow style modeling for half adder and structural style of modeling for full adder. Testbenches for both, half and full added entities.

For half adder simulation, parameter Top entity will be tb_half_adder.
For full adder simulation, parameter Top entity will be tb_full_adder.

4440:0