hi,
I made simple Gray code to implement gray code increment circuit as
Code:
library ieee;
use ieee.std_logic_1164.all;
entity graycode_inc is
generic( n:natural := 3);
port( g: in std_logic_vector(n-1 downto 0);
gn : out std_logic_vector(n-1 downto 0)
);
end graycode_inc;
architecture behav of graycode_inc is
begin
with g select
gn <= "001" when "000",
"011" when "001",
"010" when "011",
"110" when "010",
"111" when "110",
"101" when "111",
"100" when "101",
"000" when others;
end behav;
however, i get error:
Code:
Selector (Signal 'g' of type std_logic_vector) is an unconstrained array
1) how is it unconstrained when it was constrained through generic.
2) if do something like this
Code:
port( g: in std_logic_vector(2 downto 0);
gn : out std_logic_vector(n-1 downto 0)
);
it works fine.but, shouldn't compiler complain for gn as being unconstrained too?
any help?
1. what happens when g is set to 2? 4? 16? That is why g is unconstrained. Inside the graycode_inc entity g is unconstrained. The 3 value you gave it is just a default that gets used when it is instantiated without a specific value, so n at the moment is not any specific value.
2. Yes. If it doesnt compain when its compiled, it will complain when you try and run/synthesis it when n is something other than 3.
entity graycode_inc is
generic(
n :integer := 3
);
port(
g: in std_logic_vector(n-1 downto 0);
gn : out std_logic_vector(n-1 downto 0)
);
end graycode_inc;
architecture behav of graycode_inc is
begin
gn <= "001" when g = "000" else
"011" when g = "001" else
"010" when g = "011" else
"110" when g = "010" else
"111" when g = "110" else
"101" when g = "111" else
"100" when g = "101" else
"000";
end behav;
TrickyDicky - I know that but I only editted above code that can be synthesized. If some one need complete code should use for loop and compare section inside loop using parameters.
I didn't changed natural into integer for synthesizablity I replaced "with select" by "when else" for synthesize error that mentioned above.because I write most of my codes(some variables) with integer it was a copy paste from my modules.
---------- Post added at 06:24 ---------- Previous post was at 06:18 ----------
I didn't changed natural into integer for synthesizablity I replaced "with select" by "when else" for synthesize error that mentioned above.because I write most of my codes(some variables) with integer it was a copy paste from my modules.