Guest
Hi,
I found several posts about array indexing but I am still confused on
how to use an one-hot address to index the array. The reason why I
want o use a hot-one address is that I have to generate the addresses
myself in another part of the project and therefore there is no need
for an address encoder/decoder if I use the one-hot address. However,
from the posts I read, it seams that I can only index an array with
integer and enumerate types. Is this correct? How can I get avoid the
use of an address encoder/decoder?
In the following code both R_ADR and W_ADR are a 32 bits hot-one
address:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity memory is
generic( addr_width : integer := 5;
data_width : integer := 4);
port(
Q : out std_logic_vector(data_width - 1 downto 0 );
R_ADR : in std_logic_vector(2**addr_width - 1 downto 0); --
This is a hot-one address
W_ADR : in std_logic_vector(2**addr_width - 1 downto 0); --
This is a hot-one address
D : in std_logic_vector(data_width - 1 downto 0 );
W : in std_logic;
R : in std_logic;
ME : in std_logic;
CLK : in std_logic
);
end memory;
architecture synth_mem of memory is
type mem_array is array (std_logic_vector range <>
of
std_logic_vector(data_width - 1 downto 0 );
signal ram : mem_array(2**addr_width - 1 downto 0);
begin
process (ME, CLK)
begin
if ME = '1' then
Q <= (others => '1');
elsif CLK'event and CLK = '1' then
if R = '1' then
Q <= ram(R_ADR);
else
Q <= (others => '1');
end if;
if W = '1' then
ram(W_ADR) <= D;
end if;
end if;
end process;
end synth_mem;
I have the following errors:
Entity <memory> compiled.
ERROR:HDLParsers:201 - "RTL/memory.vhdl" Line 25. Array index subtype
std_logic_vector is not a discrete range.
ERROR:HDLParsers:3312 - "RTL/memory.vhdl" Line 26. Undefined symbol
'mem_array'.
ERROR:HDLParsers:1209 - "RTL/memory.vhdl" Line 26. mem_array:
Undefined symbol (last report in this block)
ERROR:HDLParsers:3313 - "/RTL/memory.vhdl" Line 56. Undefined symbol
'ram'. Should it be: rem?
ERROR:HDLParsers:1209 - "RTL/memory.vhdl" Line 56. ram: Undefined
symbol (last report in this block)
How can I use an one-hot address to index my array?
Thank you in advance.
I found several posts about array indexing but I am still confused on
how to use an one-hot address to index the array. The reason why I
want o use a hot-one address is that I have to generate the addresses
myself in another part of the project and therefore there is no need
for an address encoder/decoder if I use the one-hot address. However,
from the posts I read, it seams that I can only index an array with
integer and enumerate types. Is this correct? How can I get avoid the
use of an address encoder/decoder?
In the following code both R_ADR and W_ADR are a 32 bits hot-one
address:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity memory is
generic( addr_width : integer := 5;
data_width : integer := 4);
port(
Q : out std_logic_vector(data_width - 1 downto 0 );
R_ADR : in std_logic_vector(2**addr_width - 1 downto 0); --
This is a hot-one address
W_ADR : in std_logic_vector(2**addr_width - 1 downto 0); --
This is a hot-one address
D : in std_logic_vector(data_width - 1 downto 0 );
W : in std_logic;
R : in std_logic;
ME : in std_logic;
CLK : in std_logic
);
end memory;
architecture synth_mem of memory is
type mem_array is array (std_logic_vector range <>
std_logic_vector(data_width - 1 downto 0 );
signal ram : mem_array(2**addr_width - 1 downto 0);
begin
process (ME, CLK)
begin
if ME = '1' then
Q <= (others => '1');
elsif CLK'event and CLK = '1' then
if R = '1' then
Q <= ram(R_ADR);
else
Q <= (others => '1');
end if;
if W = '1' then
ram(W_ADR) <= D;
end if;
end if;
end process;
end synth_mem;
I have the following errors:
Entity <memory> compiled.
ERROR:HDLParsers:201 - "RTL/memory.vhdl" Line 25. Array index subtype
std_logic_vector is not a discrete range.
ERROR:HDLParsers:3312 - "RTL/memory.vhdl" Line 26. Undefined symbol
'mem_array'.
ERROR:HDLParsers:1209 - "RTL/memory.vhdl" Line 26. mem_array:
Undefined symbol (last report in this block)
ERROR:HDLParsers:3313 - "/RTL/memory.vhdl" Line 56. Undefined symbol
'ram'. Should it be: rem?
ERROR:HDLParsers:1209 - "RTL/memory.vhdl" Line 56. ram: Undefined
symbol (last report in this block)
How can I use an one-hot address to index my array?
Thank you in advance.