Hello. I am designing a vhdl code that has a generic size setting a bunch of operations. I cannot synthetize it with quartus (Error (10346): VHDL error at mac.vhd(7): formal port or parameter "width" must have actual or default value), but I am able to compile with modelsim. My question is, can I put a generic component inside another? If dont, how should I proceed?
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 | use ieee.numeric_std.all; |
6 | |
7 | ENTITY main IS |
8 | generic ( |
9 | size : integer := 4); |
10 | port ( |
11 | clk : in std_logic; |
12 | rst : in std_logic; |
13 | a_i : in std_logic_vector(size-1 downto 0); |
14 | b_i : in std_logic_vector(size-1 downto 0); |
15 | out_o : out std_logic_vector(2*size-1 downto 0) |
16 | );
|
17 | END main; |
18 | |
19 | |
20 | ARCHITECTURE bhv OF main IS |
21 | COMPONENT mac |
22 | generic ( |
23 | width : integer); |
24 | port ( |
25 | clk : in std_logic; |
26 | rst : in std_logic; |
27 | a_i : in std_logic_vector(width-1 downto 0); |
28 | b_i : in std_logic_vector(width-1 downto 0); |
29 | acc : in std_logic_vector(2*width-1 downto 0); |
30 | out_o : out std_logic_vector(2*width-1 downto 0) |
31 | );
|
32 | END COMPONENT; |
33 | |
34 | signal acc : std_logic_vector(2*size-1 downto 0) := (others => '0'); |
35 | |
36 | |
37 | BEGIN
|
38 | |
39 | mac1: mac GENERIC MAP (size) PORT MAP (clk, rst, a_i, b_i, acc, out_o); |
40 | |
41 | END bhv; |
42 | |
43 | library ieee; |
44 | use ieee.std_logic_1164.all; |
45 | use ieee.std_logic_arith.all; |
46 | use ieee.std_logic_unsigned.all; |
47 | use ieee.numeric_std.all; |
48 | |
49 | ENTITY mac IS |
50 | generic ( |
51 | width : integer); |
52 | port ( |
53 | clk : in std_logic; |
54 | rst : in std_logic; |
55 | a_i : in std_logic_vector(width-1 downto 0); |
56 | b_i : in std_logic_vector(width-1 downto 0); |
57 | acc : in std_logic_vector(2*width-1 downto 0); |
58 | out_o : out std_logic_vector(2*width-1 downto 0) |
59 | );
|
60 | END mac; |
61 | |
62 | |
63 | ARCHITECTURE bhv OF mac IS |
64 | COMPONENT mul |
65 | generic ( |
66 | W_g : integer); |
67 | port ( |
68 | clk : in std_logic; |
69 | rst : in std_logic; |
70 | a_i : in std_logic_vector(W_g-1 downto 0); |
71 | b_i : in std_logic_vector(W_g-1 downto 0); |
72 | outm_o : out std_logic_vector(2*W_g-1 downto 0) |
73 | );
|
74 | END COMPONENT; |
75 | |
76 | COMPONENT soma |
77 | generic ( |
78 | W_gs : integer); |
79 | port ( |
80 | clk : in std_logic; |
81 | rst : in std_logic; |
82 | outm_o : in std_logic_vector(2*W_gs-1 downto 0); |
83 | acc : in std_logic_vector(2*W_gs-1 downto 0); |
84 | outs_o : out std_logic_vector(2*W_gs-1 downto 0) |
85 | );
|
86 | END COMPONENT; |
87 | |
88 | signal outm_o, outs_o : std_logic_vector (2*width-1 downto 0) := (OTHERS => '0'); |
89 | |
90 | |
91 | BEGIN
|
92 | mul1: mul GENERIC MAP (width) PORT MAP (clk, rst, a_i, b_i, outm_o); |
93 | soma1: soma GENERIC MAP (width) PORT MAP (clk, rst, outm_o, acc, outs_o); |
94 | out_o <= outs_o; |
95 | END bhv; |
> use ieee.std_logic_1164.all; > use ieee.std_logic_arith.all; > use ieee.std_logic_unsigned.all; > use ieee.numeric_std.all; 1) Only use libraries you really need! In your case this is only the first one 2) Don't use ieee.std_logic_arith and ieee.std_logic_unsigned at all 3) Don't use positional assignments. Use the named assignment! Makes you code much more readable. 4) Show us to which line your error message exactly belongs!
Un, ok. What do you mean by "3) Don't use positional assignments. Use the named assignment! Makes you code much more readable." Quartus points to this generic value:
1 | ENTITY mac IS |
2 | generic ( |
3 | width : integer); |
4 | port ( |
5 | clk : in std_logic; |
6 | rst : in std_logic; |
7 | a_i : in std_logic_vector(width-1 downto 0); |
8 | b_i : in std_logic_vector(width-1 downto 0); |
9 | acc : in std_logic_vector(2*width-1 downto 0); |
10 | out_o : out std_logic_vector(2*width-1 downto 0) |
11 | );
|
12 | END mac; |
> What do you mean by "3) Don't use positional assignments. Use the named > assignment! Makes you code much more readable." I mean the following syntax:
1 | mac1: mac |
2 | GENERIC MAP (width => size) |
3 | PORT MAP (clk => clk, |
4 | rst => rst, |
5 | a_i => a_i, |
6 | b_i => b_i, |
7 | acc => acc, |
8 | out_o => out_o); |
So the order of assignments in the generic and port map is unimportant, because it is described explicit, which signal is connected to which port. But that's not the origin of your error message. Just a general advice ;-) > 1) Only use libraries you really need! In your case this is only the > first one I'm sorry. I did't see the integer generic. So you need ieee.std_logic_1164 and ieee.numeric_std Regarding your error message: In general it is no problem, to use a generic value like this. Maybe Quartus has a problem with generics on top level entities? This is just a guess. Because the code look ok for me.
Thanks for the advice. I am out of ideas to fix this =[
Got it!!! Just had to set main vhdl file as top level entity! But thanks for those hints =D