A
Andy
Guest
Hello All,
I've a question with regards to conditional generates. I'm using a 'for
generate' to interconnect an array of signals. I'm then using the index
of this generate to set the connectivity of the array.
The following is an example to demonstrate the problem (A complete
example module is described below). It seems that 'Method One' should
work, as x-1 is only used when x>0. However, Modelsim complains about
the indexing being out of range. If, however, I use method Two,
everything is OK.
VectorNextLogic : for x in 0 to 7 generate
begin
-- Method One (doesn't work)
dataVector(x) <= dIn(x) xor dataVector(7) when (x=0) else
dIn(x) xor dataVector(x-1);
-- Method Two (does work)
BitConnect0 : if (x=0) generate
begin
dataVectorNext(x) <= dIn(x) xor dataVector(7);
end generate;
BitConnect1 : if (x>0) generate
begin
dataVectorNext(x) <= dIn(x) xor dataVector(x-1);
end generate;
end generate;
I'm guessing that 'Method One' is not legal/valid VHDL, but would like
to know for sure. Also, is 'method Two' the only available approach to
this problem? It seems far more prone to error, and in the real module
in which I need to do this, it would require a great deal more code.
Any help/advice/comments much appreciated.
Many Thanks
Andy
References:
http://groups.google.co.uk/group/comp.lang.vhdl/browse_thread/thread/e66302c5b11aa0c1/50ee70d2b0aa9287
For Module:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Test is
port ( clk : in std_logic;
nReset : in std_logic;
dIn : in std_logic_vector(7 downto 0);
dOut : out std_logic_vector(7 downto 0));
end Test;
architecture General of Test is
signal dataVectorNext : std_logic_vector(7 downto 0);
signal dataVector : std_logic_vector(7 downto 0);
begin
dOut <= dataVector;
process (clk)
begin
if (clk'event and clk='1') then
if (nReset='0') then
dataVector <= (others => '0');
else
dataVector <= dataVectorNext;
end if;
end if;
end process;
VectorNextLogic : for x in 0 to 7 generate
begin
-- Method One (doesn't work)
dataVector(x) <= dIn(x) xor dataVector(7) when (x=0) else
dIn(x) xor dataVector(x-1);
-- Method Two (does work)
BitGen0 : if (x=0) generate
begin
dataVectorNext(x) <= dIn(x) xor dataVector(7);
end generate;
BitGen1 : if (x>0) generate
begin
dataVectorNext(x) <= dIn(x) xor dataVector(x-1);
end generate;
end generate;
end General;
I've a question with regards to conditional generates. I'm using a 'for
generate' to interconnect an array of signals. I'm then using the index
of this generate to set the connectivity of the array.
The following is an example to demonstrate the problem (A complete
example module is described below). It seems that 'Method One' should
work, as x-1 is only used when x>0. However, Modelsim complains about
the indexing being out of range. If, however, I use method Two,
everything is OK.
VectorNextLogic : for x in 0 to 7 generate
begin
-- Method One (doesn't work)
dataVector(x) <= dIn(x) xor dataVector(7) when (x=0) else
dIn(x) xor dataVector(x-1);
-- Method Two (does work)
BitConnect0 : if (x=0) generate
begin
dataVectorNext(x) <= dIn(x) xor dataVector(7);
end generate;
BitConnect1 : if (x>0) generate
begin
dataVectorNext(x) <= dIn(x) xor dataVector(x-1);
end generate;
end generate;
I'm guessing that 'Method One' is not legal/valid VHDL, but would like
to know for sure. Also, is 'method Two' the only available approach to
this problem? It seems far more prone to error, and in the real module
in which I need to do this, it would require a great deal more code.
Any help/advice/comments much appreciated.
Many Thanks
Andy
References:
http://groups.google.co.uk/group/comp.lang.vhdl/browse_thread/thread/e66302c5b11aa0c1/50ee70d2b0aa9287
For Module:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Test is
port ( clk : in std_logic;
nReset : in std_logic;
dIn : in std_logic_vector(7 downto 0);
dOut : out std_logic_vector(7 downto 0));
end Test;
architecture General of Test is
signal dataVectorNext : std_logic_vector(7 downto 0);
signal dataVector : std_logic_vector(7 downto 0);
begin
dOut <= dataVector;
process (clk)
begin
if (clk'event and clk='1') then
if (nReset='0') then
dataVector <= (others => '0');
else
dataVector <= dataVectorNext;
end if;
end if;
end process;
VectorNextLogic : for x in 0 to 7 generate
begin
-- Method One (doesn't work)
dataVector(x) <= dIn(x) xor dataVector(7) when (x=0) else
dIn(x) xor dataVector(x-1);
-- Method Two (does work)
BitGen0 : if (x=0) generate
begin
dataVectorNext(x) <= dIn(x) xor dataVector(7);
end generate;
BitGen1 : if (x>0) generate
begin
dataVectorNext(x) <= dIn(x) xor dataVector(x-1);
end generate;
end generate;
end General;