S
sensor
Hi. When I was simulating a design of cripple adder using Modelsim, I found the list output hard to understand. Code of the design was copied from <<Circuit Design with VHDL>> by Volnei A. Pedroni.
-- adder_cripple.vhd
library ieee;
use ieee.std_logic_1164.all;
-------------------------------------------------
entity adder_cripple is
generic(n: integer := 4);
port (a, b: in std_logic_vector(n-1 downto 0);
cin: in std_logic;
s: out std_logic_vector(n-1 downto 0);
cout: out std_logic);
end adder_cripple;
-------------------------------------------------
architecture adder of adder_cripple is
signal c: std_logic_vector(n downto 0);
begin
c(0) <= cin;
g1: for i in 0 to n-1 generate
s(i) <= a(i) xor b(i) xor c(i);
c(i+1) <= ( a(i) and b(i) ) or
( a(i) and c(i) ) or
( b(i) and c(i) );
end generate g1;
cout <= c(n);
end adder;
-------------------------------------------------
-- testbench
-------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
-------------------------------------------------
entity adder_tb is
generic (m: integer := 4);
end;
-------------------------------------------------
architecture adder_tb1 of adder_tb is
component adder_cripple is
generic(n: integer := 4);
port(a, b: in std_logic_vector(n-1 downto 0);
cin: in std_logic;
s: out std_logic_vector(n-1 downto 0);
cout: out std_logic);
end component adder_cripple;
signal a, b: std_logic_vector(m-1 downto 0);
signal cin: std_logic;
signal s: std_logic_vector(m-1 downto 0);
signal cout: std_logic;
begin
UUT: adder_cripple
generic map(n => m)
port map(
a => a,
b => b,
cin => cin,
s => s,
cout => cout);
a_proc: process
begin
a <= "0011";
wait for 200 ns;
a <= "0110";
wait;
end process a_proc;
b_proc: process
begin
b <= "1000";
wait for 120 ns;
b <= "1100";
wait;
end process b_proc;
cin_proc: process
begin
cin <= '0';
wait for 200 ns;
cin <= '1';
wait;
end process cin_proc;
end adder_tb1;
-------------------------------------------------
list output:
ns | delta | a | b | cin | s | cout |
----|--------|------|------|-----|------|------|
0 | +0 | UUUU | UUUU | U | UUUU | U |
0 | +1 | 0011 | 1000 | 0 | UUUU | U |
0 | +3 | 0011 | 1000 | 0 | 1UU1 | U |
0 | +4 | 0011 | 1000 | 0 | 1U11 | 0 |
0 | +5 | 0011 | 1000 | 0 | 1011 | 0 |
120 | +1 | 0011 | 1100 | 0 | 1011 | 0 |
120 | +2 | 0011 | 1100 | 0 | 1111 | 0 |
200 | +1 | 0110 | 1100 | 1 | 1111 | 0 |
200 | +2 | 0110 | 1100 | 1 | 1010 | 0 |
200 | +3 | 0110 | 1100 | 1 | 0011 | 0 |
200 | +4 | 0110 | 1100 | 1 | 0011 | 1 |
----|--------|------|------|-----|------|------|
Why s(3) is computed together with s(0) at 0 ns + 3 delta? Any help will be appretiated. Thx.
-- adder_cripple.vhd
library ieee;
use ieee.std_logic_1164.all;
-------------------------------------------------
entity adder_cripple is
generic(n: integer := 4);
port (a, b: in std_logic_vector(n-1 downto 0);
cin: in std_logic;
s: out std_logic_vector(n-1 downto 0);
cout: out std_logic);
end adder_cripple;
-------------------------------------------------
architecture adder of adder_cripple is
signal c: std_logic_vector(n downto 0);
begin
c(0) <= cin;
g1: for i in 0 to n-1 generate
s(i) <= a(i) xor b(i) xor c(i);
c(i+1) <= ( a(i) and b(i) ) or
( a(i) and c(i) ) or
( b(i) and c(i) );
end generate g1;
cout <= c(n);
end adder;
-------------------------------------------------
-- testbench
-------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
-------------------------------------------------
entity adder_tb is
generic (m: integer := 4);
end;
-------------------------------------------------
architecture adder_tb1 of adder_tb is
component adder_cripple is
generic(n: integer := 4);
port(a, b: in std_logic_vector(n-1 downto 0);
cin: in std_logic;
s: out std_logic_vector(n-1 downto 0);
cout: out std_logic);
end component adder_cripple;
signal a, b: std_logic_vector(m-1 downto 0);
signal cin: std_logic;
signal s: std_logic_vector(m-1 downto 0);
signal cout: std_logic;
begin
UUT: adder_cripple
generic map(n => m)
port map(
a => a,
b => b,
cin => cin,
s => s,
cout => cout);
a_proc: process
begin
a <= "0011";
wait for 200 ns;
a <= "0110";
wait;
end process a_proc;
b_proc: process
begin
b <= "1000";
wait for 120 ns;
b <= "1100";
wait;
end process b_proc;
cin_proc: process
begin
cin <= '0';
wait for 200 ns;
cin <= '1';
wait;
end process cin_proc;
end adder_tb1;
-------------------------------------------------
list output:
ns | delta | a | b | cin | s | cout |
----|--------|------|------|-----|------|------|
0 | +0 | UUUU | UUUU | U | UUUU | U |
0 | +1 | 0011 | 1000 | 0 | UUUU | U |
0 | +3 | 0011 | 1000 | 0 | 1UU1 | U |
0 | +4 | 0011 | 1000 | 0 | 1U11 | 0 |
0 | +5 | 0011 | 1000 | 0 | 1011 | 0 |
120 | +1 | 0011 | 1100 | 0 | 1011 | 0 |
120 | +2 | 0011 | 1100 | 0 | 1111 | 0 |
200 | +1 | 0110 | 1100 | 1 | 1111 | 0 |
200 | +2 | 0110 | 1100 | 1 | 1010 | 0 |
200 | +3 | 0110 | 1100 | 1 | 0011 | 0 |
200 | +4 | 0110 | 1100 | 1 | 0011 | 1 |
----|--------|------|------|-----|------|------|
Why s(3) is computed together with s(0) at 0 ns + 3 delta? Any help will be appretiated. Thx.