I'm trying to implement a testbench using a Golden Model and a DUT, in this case I'm testing a full adder 4 bits. I'm always getting undefined at the signal s_dut while s_gm works just fine. I'm stuck on this for a while and I really don't know what the problem would be.
Here is the top module:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity topmodule is
end topmodule;
architecture Behavioral of topmodule is
component SomadorCompleto4bits_dut is
Port ( A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
Cin : in STD_LOGIC;
S : out STD_LOGIC_VECTOR (3 downto 0);
Cout : out STD_LOGIC);
end component;
component SomadorComOperador_golden_model is
Port ( A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
S : out STD_LOGIC_VECTOR (4 downto 0));
end component;
component testbench is
port (s_dut, s_gm : in STD_LOGIC_VECTOR (4 downto 0);
a, b : out STD_LOGIC_VECTOR (3 downto 0));
end component;
signal a, b : STD_LOGIC_VECTOR (3 downto 0);
signal s_dut, s_gm : STD_LOGIC_VECTOR (4 downto 0);
begin
U0: SomadorCompleto4bits_dut port map(a, b, '0', s_dut (3 downto 0), s_dut(4));
U1: SomadorComOperador_golden_model port map(a, b, s_gm);
U2: testbench port map(s_dut, s_gm, a, b);
end Behavioral;
and here the testbench:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity testbench is
port (s_dut, s_gm : in STD_LOGIC_VECTOR (4 downto 0);
a, b : out STD_LOGIC_VECTOR (3 downto 0));
end testbench;
architecture Behavioral of testbench is
begin
process
variable a_teste_in, b_teste_in : STD_LOGIC_VECTOR (3 downto 0);
begin
report "Iniciando teste..." severity NOTE;
a_teste_in := "0000";
b_teste_in := "0000";
for i in 1 to 16 loop
for j in 1 to 16 loop
a <= a_teste_in;
b <= b_teste_in;
wait for 500 ns;
assert (s_dut = s_gm) report "Falhou: i = " & integer'image(i) & " j = " & integer'image(j) severity ERROR;
a_teste_in := a_teste_in + 1;
end loop;
b_teste_in := b_teste_in + 1;
end loop;
report "Teste finalizado!" severity NOTE;
wait;
end process;
end Behavioral;
I believe the error is somewhat related with the line:
U0: SomadorCompleto4bits_dut port map(a, b, '0', s_dut (3 downto 0), s_dut(4));
---edited:
Here's the DUT:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--DEVICE UNDER TEST--
entity SomadorCompleto is
Port ( S : out STD_LOGIC;
Cout : out STD_LOGIC;
A : in STD_LOGIC;
B : in STD_LOGIC;
Cin : in STD_LOGIC);
end SomadorCompleto;
architecture Behavioral of SomadorCompleto is
begin
S <= A xor B xor Cin;
Cout <= (A and B) or (A and Cin) or (B and Cin);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity SomadorCompleto4bits_dut is
Port ( A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
Cin : in STD_LOGIC;
S : out STD_LOGIC_VECTOR (3 downto 0);
Cout : out STD_LOGIC);
end SomadorCompleto4bits_dut;
architecture Behavioral of SomadorCompleto4bits_dut is
signal fio_c1, fio_c2, fio_c3 : STD_LOGIC;
component SomadorCompletoSimples is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
cin : in STD_LOGIC;
s : out STD_LOGIC;
cout : out STD_LOGIC);
end component;
begin
U0: SomadorCompletoSimples port map(A(0),B(0),'0',S(0),fio_c1);
U1: SomadorCompletoSimples port map(A(1),B(1),fio_c1,S(1),fio_c2);
U2: SomadorCompletoSimples port map(A(2),B(2),fio_c2,S(2),fio_c3);
U3: SomadorCompletoSimples port map(A(3),B(3),fio_c3,S(3),Cout);
end Behavioral;
--------------------------------------
Thanks in advance!
I just forgot to put "Simples" on SomadorCompleto, because both are the same
Related
I am new to VHDL and i am trying to implement CMOS CD4543 into FPGA basys 3 ,
and i am stuck because i wrote 2 modules and the output remains U and this output is supposed to be input in the second module. I've made testbenches for both of them and separatly they are working corect. I will put the code here to see what is wrong. Thanks!
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity latch is
Port ( datain : in STD_LOGIC_VECTOR (3 downto 0);
load : in STD_LOGIC;
data_out : out STD_LOGIC_VECTOR(3 downto 0));
end latch;
architecture Behavioral of latch is
signal data : std_logic_vector (3 downto 0);
Begin
data <= datain when (load = '1') else data;
data_out <= data;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity to7segments is
Port ( datain : in STD_LOGIC_VECTOR (3 downto 0);
bl :in std_logic;
ph :in std_logic;
seg : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0));
end to7segments;
architecture behavioral of to7segments is
signal data: std_logic_vector(3 downto 0);
Begin
an<="1110";
decoder: process(bl,ph)
begin
if bl= '0' then
if ph ='1' then
data <= not(datain);
end if;
data<=datain;
case data is
when "0000" => seg <="0000001" ;
when "0001" => seg <= "1001111" ;
when "0010" => seg <= "0010010" ;
when "0011" => seg <= "0000110" ;
when "0100" => seg <= "1001100" ;
when "0101" => seg <= "0100100" ;
when "0110" => seg <= "0100000" ;
when "0111" => seg <= "0001111" ;
when "1000" => seg <= "0000000" ;
when "1001" => seg <= "0000100" ;
when "1010" => seg <= "0001000" ;
when "1011" => seg <= "1100000" ;
when "1100" => seg <= "0110001" ;
when "1101" => seg <= "1000010" ;
when "1110" => seg <= "0110000" ;
when "1111" => seg <= "0111000" ;
when others => seg <= "1111111" ;
end case;
elsif bl='1' then
seg<="1111111";
end if;
end process decoder;
end behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity top is
Port ( load : in STD_LOGIC;
ph : in STD_LOGIC;
bl : in STD_LOGIC;
datain :in std_logic_vector( 3 downto 0);
seg : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0));
end top;
architecture behavioral of top is
component latch PORT ( datain : in STD_LOGIC_VECTOR (3 downto 0);
load : in STD_LOGIC;
data_out : out STD_LOGIC_VECTOR(3 downto 0));
end component;
component to7segments PORT ( datain : inout STD_LOGIC_VECTOR (3 downto 0);
bl :in std_logic;
ph :in std_logic;
seg : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0));
end component;
signal datain2 : std_logic_vector(3 downto 0);
begin
latch1: latch PORT MAP(datain=>datain,
load =>load,
data_out=>datain2);
decoder: to7segments PORT MAP(datain=>datain2,
bl=>bl,
ph=>ph,
seg=>seg,
an=>an);
end behavioral;
I’m implementing IDEA algorithm using VHDL, I have a problem in my
keygenerator module, when I run the simulator I get values U in all of
the signals even though I assign other values to them.
library IEEE;
use IEEE.STD_LOGIC_1164.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 primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity keygenerator is
Port ( round : in STD_LOGIC_VECTOR (3 downto 0);
key : in STD_LOGIC_VECTOR (127 downto 0);
keyout1 : out STD_LOGIC_VECTOR (15 downto 0);
keyout2 : out STD_LOGIC_VECTOR (15 downto 0);
keyout3 : out STD_LOGIC_VECTOR (15 downto 0);
keyout4 : out STD_LOGIC_VECTOR (15 downto 0);
keyout5 : out STD_LOGIC_VECTOR (15 downto 0);
keyout6 : out STD_LOGIC_VECTOR (15 downto 0));
end keygenerator;
architecture Behavioral of keygenerator is
SIGNAL key0 : std_logic_vector (127 downto 0);
SIGNAL key1 : std_logic_vector (127 downto 0);
SIGNAL key2 : std_logic_vector (127 downto 0);
SIGNAL key3 : std_logic_vector (127 downto 0);
SIGNAL key4 : std_logic_vector (127 downto 0);
SIGNAL key5 : std_logic_vector (127 downto 0);
SIGNAL key6 : std_logic_vector (95 downto 0);
signal output : std_logic_vector (95 downto 0);
begin
process (round, key)
begin
key0 <= key;
key1 <= key0(102 downto 0) & key0(127 downto 103);
key2 <= key1(102 downto 0) & key1(127 downto 103);
key3 <= key2(102 downto 0) & key2(127 downto 103);
key4 <= key3(102 downto 0) & key3(127 downto 103);
key5 <= key4(102 downto 0) & key4(127 downto 103);
key6 <= key5(102 downto 7);
case round is
when "0000" => output <= key0(127 downto 32);
when "0001" => output <= key0(31 downto 0) & key1(127 downto 64);
when "0010" => output <= key1(63 downto 0) & key2(127 downto 96);
when "0011" => output <= key2(95 downto 0);
when "0100" => output <= key3(127 downto 32);
when "0101" => output <= key3(31 downto 0) & key4(127 downto 64);
when "0110" => output <= key4(63 downto 0) & key5(127 downto 96);
when "0111" => output <= key5(95 downto 0);
when "1000" => output <= key6;
when others => output <= (others => 'X');
end case;
end process;
keyout6 <= output(15 downto 0);
keyout5 <= output(31 downto 16);
keyout4 <= output(47 downto 32);
keyout3 <= output(63 downto 48);
keyout2 <= output(79 downto 64);
keyout1 <= output(95 downto 80);
end Behavioral;
That's my testbench:
-- Description:
--
-- VHDL Test Bench Created by ISE for module: keygenerator
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
-- Notes:
-- This testbench has been automatically generated using types std_logic and
-- std_logic_vector for the ports of the unit under test. Xilinx recommends
-- that these types always be used for the top-level I/O of a design in order
-- to guarantee that the testbench will bind correctly to the post-implementation
-- simulation model.
--------------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY tb_keygenerator IS
END tb_keygenerator;
ARCHITECTURE behavior OF tb_keygenerator IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT keygenerator
PORT(
round : IN std_logic_vector(3 downto 0);
key : IN std_logic_vector(127 downto 0);
keyout1 : OUT std_logic_vector(15 downto 0);
keyout2 : OUT std_logic_vector(15 downto 0);
keyout3 : OUT std_logic_vector(15 downto 0);
keyout4 : OUT std_logic_vector(15 downto 0);
keyout5 : OUT std_logic_vector(15 downto 0);
keyout6 : OUT std_logic_vector(15 downto 0)
);
END COMPONENT;
--Inputs
signal round : std_logic_vector(3 downto 0) := (others => '0');
signal key : std_logic_vector(127 downto 0) := (others => '0');
--Outputs
signal out1 : std_logic_vector(15 downto 0);
signal out2 : std_logic_vector(15 downto 0);
signal out3 : std_logic_vector(15 downto 0);
signal out4 : std_logic_vector(15 downto 0);
signal out5 : std_logic_vector(15 downto 0);
signal out6 : std_logic_vector(15 downto 0);
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
constant I_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: keygenerator PORT MAP (
round => round,
key => key,
keyout1 => out1,
keyout2 => out2,
keyout3 => out3,
keyout4 => out4,
keyout5 => out5,
keyout6 => out6
);
-- Clock process definitions
I_process :process
begin
key <= X"12345678912345678912345678912345";
round <="1100";
wait for I_period/2;
key <= X"12345678912345678912345678912345";
round <="1001";
wait for I_period/2;
end process;
END;
my program is
entity mult is
Port ( a,b : in STD_LOGIC_VECTOR (07 downto 0);
p: out STD_LOGIC_VECTOR (15 downto 0));
end mult;
architecture Behavioral of mult is
signal m1,m6,m8:std_logic_vector(7 downto 4);
signal m2,m3,m5,m7:std_logic_vector(7 downto 0);
signal m4:std_logic_vector(3 downto 0);
signal c,d,x:std_logic;
component fourbitmult
Port ( a,b : in STD_LOGIC_VECTOR (3 downto 0);
p : out STD_LOGIC_VECTOR (7 downto 0));
end component;
component csa
Port ( a,b : in STD_LOGIC_VECTOR (07 downto 0);
cin : in STD_LOGIC='0';
s : out STD_LOGIC_VECTOR (07 downto 0);
cout : out STD_LOGIC);
end component;
component rca
port ( a,b : in STD_LOGIC_VECTOR (3 downto 0);
s : out STD_LOGIC_VECTOR (3 downto 0);
carry : out STD_LOGIC);
end component;
begin
v1:fourbitmult port map(a(3 downto 0),b(3 downto 0),p(3 downto 0),m1(7 downto 4));
v2:fourbitmult port map(a(7 downto 4),b(3 downto 0),m2(7 downto 0));
v3:fourbitmult port map(a(3 downto 0),b(7 downto 4),m3(7 downto 0));
v4:fourbitmult port map(a(7 downto 4),b(7 downto 4),m4(3 downto 0),m8(7 downto 4));
a1:csa port map(m2(7 downto 0),m3(7 downto 0),m5(7 downto 0),c);
a2:csa port map(m1(7 downto 4),m5(7 downto 0),m4(3 downto 0),p(11 downto 4),d);
x<=c or d;
r1:rca port map(m8(7 downto 4),x,p(15 downto 12));
end Behavioral;
my syntax is correct.i tried my level best to solve this error.
still i am getting error
Line 46. parse error, unexpected EQ, expecting SEMICOLON or CLOSEPAR
what could be wrong?
My lab partner and I can't figure out why we're not getting any output in our waveform simulation of this component. We simulated the component by itself and obtained the expected behavior, but nested inside the entity, the output signal was not being initialized and only had uninitialized 'X' response.
This is the component declaration in the top level entity:
99 component CH is
100 Port ( clk : in std_logic;
101 X : in std_logic_vector(31 downto 0);
102 Y : in std_logic_vector(31 downto 0);
103 Z : in std_logic_vector(31 downto 0);
104 CH_OUT : out std_logic_vector(31 downto 0)
105 );
106 end component;
This is the process we use to assign input/output:
289 round_compute2 : process (clk, CH_OUT_sig, e_sig, f_sig, g_sig, T1_sig)
290 begin
291 CH_X_in <= e_sig;
292 CH_Y_in <= f_sig;
293 CH_Z_in <= g_sig;
294 T1_sig <= std_logic_vector(unsigned(CH_OUT_sig));
295 end process;
This is the code for the CH component
1 library IEEE;
2 use IEEE.STD_LOGIC_1164.ALL;
3 use IEEE.STD_LOGIC_ARITH.ALL;
4 use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
6 -- CH is defined as (X AND Y) XOR (X' AND Z)
7 -- Verified working
8
9 entity CH is
10 Port ( clk : in std_logic;
11 X : in std_logic_vector(31 downto 0);
12 Y : in std_logic_vector(31 downto 0);
13 Z : in std_logic_vector(31 downto 0);
14 CH_OUT : out std_logic_vector(31 downto 0)
15 );
16 end CH;
17
18 architecture Behavioral of CH is
19
20 begin
21
22 Compute : process (clk, X, Y, Z)
23 begin
24
25 CH_OUT <= (X and Y) xor ((not X) and Z);
26
27 end process;
28
29 end Behavioral;
These questions are similar, but do not address the issue in this post because-
VHDL component and outputs based on generic
- Does not involve processes
Simple VHDL Problem with synchronous/asynchronous logic
- Does not involve components and signals that are assigned from the system to the component
Why doesn't my code produce output?
- Our code has the correct sensitivity list, I think
You should look through your tool's output for warnings. It sounds like you have an unbound component CH.
With:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- 3 use IEEE.STD_LOGIC_ARITH.ALL;
-- 4 use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- CH is defined as (X AND Y) XOR (X' AND Z)
-- Verified working
entity CH is
Port ( clk : in std_logic;
X : in std_logic_vector(31 downto 0);
Y : in std_logic_vector(31 downto 0);
Z : in std_logic_vector(31 downto 0);
CH_OUT : out std_logic_vector(31 downto 0)
);
end CH;
architecture Behavioral of CH is
begin
Compute : process (clk, X, Y, Z)
begin
CH_OUT <= (X and Y) xor ((not X) and Z);
end process;
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity ch_comp is
end entity;
architecture foo of ch_comp is
component CH is
Port ( clk : in std_logic;
X : in std_logic_vector(31 downto 0);
Y : in std_logic_vector(31 downto 0);
Z : in std_logic_vector(31 downto 0);
CH_OUT : out std_logic_vector(31 downto 0)
);
end component;
signal CH_X_in: std_logic_vector(31 downto 0);
signal CH_Y_in: std_logic_vector(31 downto 0);
signal CH_Z_in: std_logic_vector(31 downto 0);
signal CH_OUT_sig: std_logic_vector(31 downto 0);
signal e_sig: std_logic_vector(31 downto 0) := X"feedface";
signal f_sig: std_logic_vector(31 downto 0) := X"deadbeef";
signal g_sig: std_logic_vector(31 downto 0) := X"ffffffff";
signal T1_sig: std_logic_vector(31 downto 0);
signal clk: std_logic := '0';
begin
round_compute2 : process (clk, CH_OUT_sig, e_sig, f_sig, g_sig) --, T1_sig)
begin
CH_X_in <= e_sig;
CH_Y_in <= f_sig;
CH_Z_in <= g_sig;
T1_sig <= std_logic_vector(unsigned(CH_OUT_sig));
end process;
UUT:
CH
port map (
clk => clk,
X => CH_X_in,
Y => CH_Y_in,
Z => CH_Z_in,
CH_OUT => CH_OUT_sig
);
TEST:
process
begin
wait for 10 ns;
e_sig <= X"deadface";
f_sig <= X"facebeef";
g_sig <= X"EEEEFFFF";
wait for 10 ns;
wait;
end process;
end architecture;
I got:
Which is to say, it appears not to exhibit only uninitialized 'X's on CH_out_sig or T1_sig.
And it would appear you haven't revealed either enough or your VHDL design description or enough of the tool build and simulation process for a third party to see where you went wrong.
I have two nested procedures, where the "main" procedure
makes use of "subproc" to accumulates a result in variables
t0 and t1, which is then returned at the end. This should all
be computed in one clock cycle, and the circuit more or less
just consists of simple logic gates (xor, or, and). When I try
to describe the circuit as below I get the following error:
Acutal (variable t0) for formal "a" is not a signal
That makes sense as the subprocure requires signals as input,
but I wanna pass it a variable during the main procedure. Is
there a simple way to circumvent this problem with casting for
example?
Thanks
procedure subproc
(
signal a : in std_logic_vector(31 downto 0);
signal b : in std_logic_vector(31 downto 0);
signal c : in std_logic_vector(31 downto 0);
signal d : in std_logic_vector(31 downto 0);
signal e : out std_logic_vector(31 downto 0);
signal f : out std_logic_vector(31 downto 0)
)
is
variable x : std_logic_vector(31 downto 0);
variable y : std_logic_vector(31 downto 0);
begin
x := (others => '0');
y := (others => '0');
for i in 0 to 31 loop
x(i) := (a(i) xor b(i)) and (c(i) xor d(i));
y(i) := (a(i) xor b(i)) or ((d(i) xor c(i)) xor b(i));
end loop;
e <= x(31 downto 0);
f <= y(31 downto 0);
end;
procedure main
(
signal a : in std_logic_vector(31 downto 0);
signal b : in std_logic_vector(31 downto 0);
signal r : out std_logic_vector(31 downto 0)
)
is
variable res : std_logic_vector(31 downto 0);
variable t0, t1 : std_logic_vector(31 downto 0);
constant c : std_logic_vector(31 downto 0) := X"fedcba90";
constant d : std_logic_vector(31 downto 0) := X"7654321f";
begin
t0 := (others => '0');
t1 := (others => '0');
for i in 0 to 31 loop
if ( (c(i) = '0') && (d(i) = '1') ) then
subproc( t0, t1,
a, b, t0, t1 );
end if;
end loop;
r <= t0;
end;
First off, your "if" clause is written in C-style. You want to say:
if (c(i) = '0') and (d(i) = '1') then
But the problem really is that you describe the procedure as taking SIGNALs as arguments. If you want the results to be assigned to variables, you need to declare a different procedure signature:
procedure subproc (
signal a : in std_logic_vector(31 downto 0);
signal b : in std_logic_vector(31 downto 0);
signal c : in std_logic_vector(31 downto 0);
signal d : in std_logic_vector(31 downto 0);
variable e : out std_logic_vector(31 downto 0);
variable f : out std_logic_vector(31 downto 0))
But then, you also need to change all assignments to e and f, so that they are variable assignments:
e := x(31 downto 0);
Why don't you just define the subproc parameters as variables instead of signals?