0
\$\begingroup\$

I have a code mult.vhd that should assign '0' on some locations of three arrays called "c", "mult" and "sum". Nonetheless the assignments on the corresponding locations of those 3 arrays only work with the array called "c". Each assignment on the arrays "mult" and "sum" leaves the corresponding location with "U" value, that means the array values do not change after running the corresponding assignment sentence.

Does anyone know why the assignments on the arrays "mult" and "sum" do not work?

I have a file called test_bench.vhd. Find as follows the code of mult.vhd:

----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date: 06/01/2021 09:33:03 PM
-- Design Name: 
-- Module Name: mult - structure
-- Project Name: 
-- Target Devices: 
-- Tool Versions: 
-- Description: 
-- 
-- Dependencies: 
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
-- 
----------------------------------------------------------------------------------


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 leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity mult is
port (a: in std_logic_vector (4 downto 0);
b: in std_logic_vector (4 downto 0);
result : out std_logic_vector (9 downto 0));
end mult;

architecture structure of mult is

type t_matrix is array (0 to 5-1, 5*2-2 downto 0) of std_logic;
constant zero : std_logic := '0';
signal c, sum , mul : t_matrix;
signal caca: std_logic;
begin

p_set_zeros: process
    begin
    ---------------------carry=zero
    c(0,0)<=zero;  
    
    loop_carry_1_to_size: for j1 in 5 to 5*2-2 loop
        c(0,j1)<=zero;
    end loop loop_carry_1_to_size;

    loop_rigt_bottom_triangle_c: for i2 in 1 to 5-2 loop
        for j2 in 0 to i2 loop
                c(i2,j2)<=zero;     
        end loop;                        
    end loop loop_rigt_bottom_triangle_c;    
    c(5-1,0)<=zero;       



    ---------------------mul=zero
    right_bottom_corner_mul_1: for i3 in 0 to 5-2 loop
        right_bottom_corner_mul_2: for j3 in 0 to i3 loop
            mul(i3,j3)<=zero;            
        end loop right_bottom_corner_mul_2;
    end loop right_bottom_corner_mul_1;    
    mul(5-1,0)<=zero;
       

   left_top_corner_mul_1: for i4 in 0 to (5-3) loop
        left_top_corner_mul_2: for j4 in 5+i4+1 to 5*2-2 loop
            mul(i4,j4)<=zero;            
        end loop left_top_corner_mul_2;
    end loop left_top_corner_mul_1;

   ---------------sum=zero
   loop_first_row_zeros: for j5 in 5 to ((5)*2-2) loop
                sum(0,j5)<=zero;                
   end loop loop_first_row_zeros;
   caca<='1';
   

   wait;  
    
end process p_set_zeros;


p_multiplications : process (a, b)
--variable v_producto : t_pp := (( others => (others => ’0’)));
begin -- process multiplications
    for i6 in 0 to 5-2 loop
        for j6 in 0 to 4 loop
        if i6 = 0 then
            sum(i6, j6) <= a(i6) and b(j6);
        end if;
        mul(i6, j6+i6+1) <= a(i6+1) and b(j6);
    end loop; -- j
end loop; -- i

end process p_multiplications ;
end structure;

Find as follows the code of test_bench.vhd:

----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date: 06/02/2021 01:47:53 PM
-- Design Name: 
-- Module Name: test_bench - structure
-- Project Name: 
-- Target Devices: 
-- Tool Versions: 
-- Description: 
-- 
-- Dependencies: 
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
-- 
----------------------------------------------------------------------------------


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 leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity test_bench is
end test_bench;

architecture structure of test_bench is
COMPONENT mult
port (a: in std_logic_vector (4 downto 0);
b: in std_logic_vector (4 downto 0);
result : out std_logic_vector (9 downto 0));
end COMPONENT;
signal a, b: std_logic_vector(4 downto 0);
signal  result: std_logic_vector(9 downto 0);

begin

i_mult: mult port map(a,b,result);

p_input: process
begin
a<="00100";
b<="01000";
wait for 25 ns;

a<="00011";
b<="11000";
wait for 25 ns;

a<="00111";
b<="00011";
wait for 25 ns;

a<="00110";
b<="01000";
wait for 25 ns;

a<="01001";
b<="00001";
wait for 25 ns;

a<="10010";
b<="01000";
wait for 25 ns;

a<="10011";
b<="00010";
wait for 25 ns;

a<="10000";
b<="00100";
wait for 25 ns;

a<="00010";
b<="11000";
wait for 25 ns;

a<="00001";
b<="10000";
wait for 25 ns;

a<="00100";
b<="00010";
wait for 25 ns;

a<="00010";
b<="00010";
wait for 25 ns;

a<="00110";
b<="00111";
wait for 25 ns;

a<="00011";
b<="00011";
wait for 25 ns;

a<="01001";
b<="01010";
wait for 25 ns;

a<="00110";
b<="10101";
wait for 25 ns;

a<="11010";
b<="00111";
wait for 25 ns;

a<="11010";
b<="11010";
wait;

end process p_input;


end structure;

```
\$\endgroup\$
1
  • \$\begingroup\$ You can't assign more than one driver at a time to drive a car, can you? Google 'multiple drivers in vhdl'. \$\endgroup\$
    – Mitu Raj
    Commented Jun 5, 2021 at 21:49

1 Answer 1

0
\$\begingroup\$

You are writing sum, mul but not c in two different processes.

Don't (until you REALLY know what you're doing. Search your VHDL book for "multiple drivers" and "signal resolution" for the backstory.

Rewrite so that only one process drives these signals.

Normally, (for example) initialising to '0' would be a reset action in the process which owns these signals.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks. Question: Can my code fail because of what you explained even if the locations of the array assigned on process 1 are different from the locations assigned on process 2? The thing is some locations need to be always zero and that is why I update them only in one process that gets run one single time. The other locations must get updated whenever there is a change of value in any signal in the sensitivity list "(a,b)" of the process. That is why I do not think it makes much sense to merge all assignments in one single process. \$\endgroup\$
    – goahead97
    Commented Jun 5, 2021 at 21:47
  • \$\begingroup\$ Short answer : yes. Longer answer; the zero locations only need to be written once, but MUST be written by the same process. (OR you could simply initialise the whole array to (others => '0') before starting, and leave those locations unwritten. This MAY not be synthesisable but what you have now certainly isn't.) \$\endgroup\$
    – user16324
    Commented Jun 5, 2021 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.