【发布时间】:2015-12-27 21:10:59
【问题描述】:
背景:
我有一个由四个 4 位 std_logic_vector 组成的类型数组:
type my_arr_type is array (0 to 3) of std_logic_vector (3 downto 0);
以及相应的信号:
signal my_signal : my_arr_type;
我还有一个 2 位向量用作数组索引:
signal index : std_logic_vector (1 downto 0) := "00";
这允许我像这样动态访问每个 4 位向量:
my_signal(to_integer(unsigned(index))) <= "0001";
在这种情况下,索引的 4 位向量将获得值 b“0001”。
问题:
当某些条件为真时,我想将当前索引的 4 位向量的值增加 1,例如。开关高。
我想我可以这样做:
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;
但是,我一定是做错了什么,因为将结果信号传递给输出会给出错误消息 - 大致如下:
Signal X is connected to multiple drivers. ERROR:HDLCompiler:1401
问题:
在上述尝试中我做错了什么?什么是正确的解决方案?
我在网上找不到任何与索引数组中递增单元格相关的示例。
(在 ISE Proj Nav 中设计合成到 Digilent Nexys 3)
(编辑)更长的代码 sn-p 以便更仔细:
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;
编辑: 所有答案和 cmets 都有帮助。谢谢!
【问题讨论】:
-
您的综合工具无法识别
index是一个常数值。所以它计算每个信号名称而不是每个索引名称的多个驱动程序。请将您的信号index更改为常量,它应该能够识别它(它只是为了测试)。 -
@Paebbels 好的。这就说得通了。你是对的 - 将
index更改为常数值确实可以使代码合成。当索引不是常数时,关于如何克服这个问题的任何建议? -
即使索引不变,我的工具也会在“放置和布线”期间停止。
-
解决方案:将
my_signal的分配移动到进程中。仅分配index从未解决的索引。 -
你用什么工具?
标签: arrays multidimensional-array vhdl synthesis