Guest
Hello, I need help with this generic thing. I'm much more comfortable
in verilog, and I do this a lot using 'parameter' and 'defparam'.
Somehow I can't do the same thing in VHDL. I've simplified the problem
to the code below:
I have a lower level module, count_ud.vhd with generic=8. On a top
level (top_count_bad), I instantiate two of count_ud.vhd, and I want to
make one 8-bit counter, the other one 7-bit counter. Synplify gives me
an error message for the 7-bit counter with the following message.
@E: CD395 :"C:\PROJECTS\test\count_ud.vhd":38:22:38:31|Constant width 8
does not match context width 7.
When I instantiate two 8-bit counters (top_count_ok below), everything
seems fine. Whenever I try to override with anything other than 8,
synplify complans. Your help is much appreciated. Btw, Modelsim
doesn't give me error/warning in either of the two below. Thanks.
======================================================================
Here is instantiation of one 8-bit and one 7-bit counter that give me
an error message. After this is the code that instantiates two 8-bit
counters that synthesizes fine.
======================================================================
top_count_bad
======================================================================
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity top_count_bad is
generic (
TOTAL_WIDTH : integer := 9);
port (
clk : in std_logic;
rst_n : in std_logic;
up_0 : in std_logic;
up_1 : in std_logic;
down_0 : in std_logic;
down_1 : in std_logic;
top_count : out std_logic_vector(8 downto 0) );
end top_count_bad;
architecture rtl of top_count_bad is
signal count_1 : std_logic_vector(7 downto 0);
signal count_0 : std_logic_vector(6 downto 0);
component count_ud
generic ( WIDTH : integer );
port (
clk : in std_logic;
rst_n : in std_logic;
up : in std_logic;
down : in std_logic;
count : out std_logic_vector(WIDTH-1 downto 0) );
end component;
begin
-- 8-bit counter
counter_1 : count_ud
generic map ( WIDTH => 8 )
port map (
clk => clk,
rst_n => rst_n,
up => up_1,
down => down_1,
count => count_1);
-- 8-bit counter
counter_0 : count_ud
generic map ( WIDTH => 7 )
port map (
clk => clk,
rst_n => rst_n,
up => up_0,
down => down_0,
count => count_0);
top_count <= std_logic_vector( unsigned("0" & count_1) +
unsigned("00" & count_0) );
end rtl;
======================================================================
And here is instantiation of two 8-bit counters that work fine.
I get 16 registers as I expect in synplify.
======================================================================
top_count_ok
======================================================================
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity top_count_ok is
generic (
TOTAL_WIDTH : integer := 9);
port (
clk : in std_logic;
rst_n : in std_logic;
up_0 : in std_logic;
up_1 : in std_logic;
down_0 : in std_logic;
down_1 : in std_logic;
top_count : out std_logic_vector(8 downto 0) );
end top_count_ok;
architecture rtl of top_count_ok is
signal count_1 : std_logic_vector(7 downto 0);
signal count_0 : std_logic_vector(7 downto 0);
component count_ud
generic ( WIDTH : integer );
port (
clk : in std_logic;
rst_n : in std_logic;
up : in std_logic;
down : in std_logic;
count : out std_logic_vector(WIDTH-1 downto 0) );
end component;
begin
-- 8-bit counter
counter_1 : count_ud
generic map ( WIDTH => 8 )
port map (
clk => clk,
rst_n => rst_n,
up => up_1,
down => down_1,
count => count_1);
-- 8-bit counter
counter_0 : count_ud
generic map ( WIDTH => 8 )
port map (
clk => clk,
rst_n => rst_n,
up => up_0,
down => down_0,
count => count_0);
top_count <= std_logic_vector( unsigned("0" & count_1) +
unsigned("0" & count_0) );
end rtl;
in verilog, and I do this a lot using 'parameter' and 'defparam'.
Somehow I can't do the same thing in VHDL. I've simplified the problem
to the code below:
I have a lower level module, count_ud.vhd with generic=8. On a top
level (top_count_bad), I instantiate two of count_ud.vhd, and I want to
make one 8-bit counter, the other one 7-bit counter. Synplify gives me
an error message for the 7-bit counter with the following message.
@E: CD395 :"C:\PROJECTS\test\count_ud.vhd":38:22:38:31|Constant width 8
does not match context width 7.
When I instantiate two 8-bit counters (top_count_ok below), everything
seems fine. Whenever I try to override with anything other than 8,
synplify complans. Your help is much appreciated. Btw, Modelsim
doesn't give me error/warning in either of the two below. Thanks.
======================================================================
Here is instantiation of one 8-bit and one 7-bit counter that give me
an error message. After this is the code that instantiates two 8-bit
counters that synthesizes fine.
======================================================================
top_count_bad
======================================================================
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity top_count_bad is
generic (
TOTAL_WIDTH : integer := 9);
port (
clk : in std_logic;
rst_n : in std_logic;
up_0 : in std_logic;
up_1 : in std_logic;
down_0 : in std_logic;
down_1 : in std_logic;
top_count : out std_logic_vector(8 downto 0) );
end top_count_bad;
architecture rtl of top_count_bad is
signal count_1 : std_logic_vector(7 downto 0);
signal count_0 : std_logic_vector(6 downto 0);
component count_ud
generic ( WIDTH : integer );
port (
clk : in std_logic;
rst_n : in std_logic;
up : in std_logic;
down : in std_logic;
count : out std_logic_vector(WIDTH-1 downto 0) );
end component;
begin
-- 8-bit counter
counter_1 : count_ud
generic map ( WIDTH => 8 )
port map (
clk => clk,
rst_n => rst_n,
up => up_1,
down => down_1,
count => count_1);
-- 8-bit counter
counter_0 : count_ud
generic map ( WIDTH => 7 )
port map (
clk => clk,
rst_n => rst_n,
up => up_0,
down => down_0,
count => count_0);
top_count <= std_logic_vector( unsigned("0" & count_1) +
unsigned("00" & count_0) );
end rtl;
======================================================================
And here is instantiation of two 8-bit counters that work fine.
I get 16 registers as I expect in synplify.
======================================================================
top_count_ok
======================================================================
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity top_count_ok is
generic (
TOTAL_WIDTH : integer := 9);
port (
clk : in std_logic;
rst_n : in std_logic;
up_0 : in std_logic;
up_1 : in std_logic;
down_0 : in std_logic;
down_1 : in std_logic;
top_count : out std_logic_vector(8 downto 0) );
end top_count_ok;
architecture rtl of top_count_ok is
signal count_1 : std_logic_vector(7 downto 0);
signal count_0 : std_logic_vector(7 downto 0);
component count_ud
generic ( WIDTH : integer );
port (
clk : in std_logic;
rst_n : in std_logic;
up : in std_logic;
down : in std_logic;
count : out std_logic_vector(WIDTH-1 downto 0) );
end component;
begin
-- 8-bit counter
counter_1 : count_ud
generic map ( WIDTH => 8 )
port map (
clk => clk,
rst_n => rst_n,
up => up_1,
down => down_1,
count => count_1);
-- 8-bit counter
counter_0 : count_ud
generic map ( WIDTH => 8 )
port map (
clk => clk,
rst_n => rst_n,
up => up_0,
down => down_0,
count => count_0);
top_count <= std_logic_vector( unsigned("0" & count_1) +
unsigned("0" & count_0) );
end rtl;