Background:
I have a type array of four 4-bit std_logic_vector's:
type my_arr_type is array (0 to 3) of std_logic_vector (3 downto 0);
and a corresponding signal:
signal my_signal : my_arr_type;
I also have a 2-bit vector to be used as an array index:
signal index : std_logic_vector (1 downto 0) := "00";
This allows me to access each 4-bit vector dynamically like so:
my_signal(to_integer(unsigned(index))) <= "0001";
In this case the indexed 4-bit vector will get the value b"0001".
The problem:
I would like to increment the value of the currently indexed 4-bit vector by 1, when some condition is true eg. switch is high.
I thought I could this with something like:
process(clk)
begin
if(rising_edge(clk)) then
if switch = '1' then --switch flicked (increment)
my_signal(to_integer(unsigned(index)))
<= std_logic_vector(unsigned( my_signal(to_integer(unsigned(index))) ) + 1);
else --remain the same
my_signal(to_integer(unsigned(index)))
<= my_signal(to_integer(unsigned(index)));
end if;
end if;
end process;
However, I must be doing something wrong since passing the resulting signal to an output gives an error message - along the lines:
Signal X is connected to multiple drivers. ERROR:HDLCompiler:1401
The question:
What am I doing wrong in the above attempt? What would be a correct solution?
I cannot find any examples online which relate to incrementing cells in an indexed array.
(Designing for synthesis to Digilent Nexys 3 in ISE Proj Nav)
(edit)Longer code snippet for greater scrunity:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity ui_top is
Port ( clk : in std_logic;
buttons : in std_logic_vector (4 downto 0); -- centre, left, up, right, down
switches : in std_logic_vector (7 downto 0);
leds : out std_logic_vector (7 downto 0);
digit : out std_logic_vector (3 downto 0) := "1110";
segments : out std_logic_vector (7 downto 0) := (others => '0');
uart_tx : out std_logic);
end ui_top;
architecture Behavioral of ui_top is
type my_arr_type is array (0 to 3) of std_logic_vector(3 downto 0);
signal my_signal : my_arr_type;
signal index : std_logic_vector (1 downto 0) := "00";
begin
-- send indexed signal to leds
leds(3 downto 0) <= my_signal(to_integer(unsigned(index)));
-- set other outputs arbitrarily
leds(7 downto 4) <= (others => '1');
uart_tx <= '1';
digit <= "1110";
segments <= (others => '0');
-- set index
index <= "00";
process(clk)
begin
if (rising_edge(clk)) then
if switches(1) = '1' then -- up
my_signal(to_integer(unsigned(index)))
<= std_logic_vector(unsigned( my_signal(to_integer(unsigned(index))) ) + 1);
end if;
end if; -- rising clock edge
end process;
-- set non indexed values arbitrarily
my_signal(1) <= "0000";
my_signal(2) <= "0000";
my_signal(3) <= "0000";
end Behavioral;
edit: All answers and comments have been helpful. Thank you!