在 VHDL 中使用矩阵
Using matrix in VHDL
我正在尝试在 VHDL 中使用矩阵,这是我目前所做的:
type MAT is array ( 7 downto 0 ) of bit_vector( 9 downto 0);
signal MAT_WORD:MAT:= (others=>X"00");
signal BREAKCODe :NATURAL:=0;
for I in 9 downto 0 loop
if(MAT_WORD(I) = x"88") then
BREAKCODE <= I;
end if ;
end loop;
............
我得到的错误是:
Implicit array operator "=" always returns FALSE (left length 10 is not equal to right length 8
知道如何将循环或矩阵用作具有 8 列和 10 行的一个吗?
这不是数据宽度的问题吗? MAT_WORD(I)
是 10 位宽,对吧? x"88"
是 0x88
的十六进制常量,它是一个八位常量。
尝试
if (MAT_WORD(I) = 10x"88")
我不是 VHDL 用户,如果这完全错误,请见谅
编辑:修改代码以添加新的 10x"88"
语法
正如 Brian 所说,您需要与 10 位值进行比较,因为您的矩阵由 10 位 bit_vector
.
的数组组成
您正在比较的十六进制文字 x"88"
只有 8 位长,因此出现错误。
试试 if(MAT_WORD(I) = "10001000")
- "10001000"
是 x"88"
的二进制表示。
如果您可以使用 VHDL 2000,您还有另一种选择 - 使用大小文字,例如10x"088"
.
此外,当您的 MAT_WORD
数组定义为 7 downto 0
...
时,您正在遍历 9 downto 0
我认为您混淆了尺寸。您定义了一个包含 8 个元素的矩阵 (7 downto 0)
,其中每个元素存储一个 10 位向量 (9 downto 0)
。
在您的 for 循环中,您只能遍历元素并根据 10 位向量检查每个元素。例如:
process(MAT_WORD)
begin
BREAK_CODE <= 0; -- move initialization here or the following
-- must be encapsulated into a clocked process
for i in 7 downto 0 loop -- order may be important
if MAT_WORD(i) = "0010001000" then -- x"88" with two '0' prepended
BREAK_CODE <= i;
end if;
end loop;
end process;
同样在 MAT_WORD
的初始化中,您必须分配 10 位向量,例如,
signal MAT_WORD:MAT:= (others=> "0000000000");
或更通用:
signal MAT_WORD:MAT:= (others=> (others => '0'));
到目前为止您收到的答案提供了一些零碎的信息,部分原因是您的代码不是 Minimal, Complete, and Verifiable example。
存在标准版本问题和全面的答案,否则 Matthew Sainsbury 的答案对于符合 -2008 的模拟器和综合工具来说是正确的。在 IEEE Std 1076-2008,15.8 位字符串文字中,添加了一个整数值的选项长度前缀,允许在基数 X 为 0 的情况下填充结果位串,其长度比以下位提供的值长字符串文字值。
代替 -2008 工具,您可以使用连接(这就是位字符串文字在 -2008 中的长度 'stretched' 的方式)或在有限数量的情况下使用 others
聚合选择(并且 none 这些情况出现在以下示例中):
entity engine is
end entity;
architecture foo of engine is
type MAT is array ( 9 downto 0 ) of bit_vector( 9 downto 0);
signal MAT_WORD: MAT := (others => ( others => '0'));
signal BREAKCODE: NATURAL := 0;
begin
MAT_WORD(5) <= "00" & x"88";
SCAN:
process(MAT_WORD)
begin
BREAKCODE <= 0; -- when no "0010001000" occurs, clear BREAKCODE
for I in MAT_WORD'range loop
if MAT_WORD(I) = "00" & x"88" then
BREAKCODE <= I;
end if;
end loop;
end process;
NARK:
process (BREAKCODE)
begin
if BREAKCODE > 0 then
report "MAT_WORD(" & integer'image(BREAKCODE) &
") = ""00"" & x""88""";
end if;
end process;
end architecture;
以上代码分析、阐述和运行:
ghdl -a engine.vhdl
ghdl -e engine
ghdl -r engine
engine.vhdl:27:13:@0ms:(report note): MAT_WORD(5) = "00" & x"88"
你可以看到它报告并发信号分配写入的位置。
请注意,您在循环语句中将 I
的范围声明为 9 downto 0
超出类型 MAT
范围的代码中还有一个错误.此处已通过使用更正 MAT
的范围更正了这一点。 (循环常量 I
已被修改为使用声明对象的范围,允许您在一个地方更改矩阵的大小)。
您也可以使用不完整的类型声明:
type MAT is array (natural range <>) of bit_vector (9 downto 0);
并在对象声明中指定范围:
signal MAT_WORD: MAT (9 downto 0) := (others => (others => '0'));
在类型声明中固定范围似乎更合适。
我正在尝试在 VHDL 中使用矩阵,这是我目前所做的:
type MAT is array ( 7 downto 0 ) of bit_vector( 9 downto 0);
signal MAT_WORD:MAT:= (others=>X"00");
signal BREAKCODe :NATURAL:=0;
for I in 9 downto 0 loop
if(MAT_WORD(I) = x"88") then
BREAKCODE <= I;
end if ;
end loop;
............
我得到的错误是:
Implicit array operator "=" always returns FALSE (left length 10 is not equal to right length 8
知道如何将循环或矩阵用作具有 8 列和 10 行的一个吗?
这不是数据宽度的问题吗? MAT_WORD(I)
是 10 位宽,对吧? x"88"
是 0x88
的十六进制常量,它是一个八位常量。
尝试
if (MAT_WORD(I) = 10x"88")
我不是 VHDL 用户,如果这完全错误,请见谅
编辑:修改代码以添加新的 10x"88"
语法
正如 Brian 所说,您需要与 10 位值进行比较,因为您的矩阵由 10 位 bit_vector
.
您正在比较的十六进制文字 x"88"
只有 8 位长,因此出现错误。
试试 if(MAT_WORD(I) = "10001000")
- "10001000"
是 x"88"
的二进制表示。
如果您可以使用 VHDL 2000,您还有另一种选择 - 使用大小文字,例如10x"088"
.
此外,当您的 MAT_WORD
数组定义为 7 downto 0
...
9 downto 0
我认为您混淆了尺寸。您定义了一个包含 8 个元素的矩阵 (7 downto 0)
,其中每个元素存储一个 10 位向量 (9 downto 0)
。
在您的 for 循环中,您只能遍历元素并根据 10 位向量检查每个元素。例如:
process(MAT_WORD)
begin
BREAK_CODE <= 0; -- move initialization here or the following
-- must be encapsulated into a clocked process
for i in 7 downto 0 loop -- order may be important
if MAT_WORD(i) = "0010001000" then -- x"88" with two '0' prepended
BREAK_CODE <= i;
end if;
end loop;
end process;
同样在 MAT_WORD
的初始化中,您必须分配 10 位向量,例如,
signal MAT_WORD:MAT:= (others=> "0000000000");
或更通用:
signal MAT_WORD:MAT:= (others=> (others => '0'));
到目前为止您收到的答案提供了一些零碎的信息,部分原因是您的代码不是 Minimal, Complete, and Verifiable example。
存在标准版本问题和全面的答案,否则 Matthew Sainsbury 的答案对于符合 -2008 的模拟器和综合工具来说是正确的。在 IEEE Std 1076-2008,15.8 位字符串文字中,添加了一个整数值的选项长度前缀,允许在基数 X 为 0 的情况下填充结果位串,其长度比以下位提供的值长字符串文字值。
代替 -2008 工具,您可以使用连接(这就是位字符串文字在 -2008 中的长度 'stretched' 的方式)或在有限数量的情况下使用 others
聚合选择(并且 none 这些情况出现在以下示例中):
entity engine is
end entity;
architecture foo of engine is
type MAT is array ( 9 downto 0 ) of bit_vector( 9 downto 0);
signal MAT_WORD: MAT := (others => ( others => '0'));
signal BREAKCODE: NATURAL := 0;
begin
MAT_WORD(5) <= "00" & x"88";
SCAN:
process(MAT_WORD)
begin
BREAKCODE <= 0; -- when no "0010001000" occurs, clear BREAKCODE
for I in MAT_WORD'range loop
if MAT_WORD(I) = "00" & x"88" then
BREAKCODE <= I;
end if;
end loop;
end process;
NARK:
process (BREAKCODE)
begin
if BREAKCODE > 0 then
report "MAT_WORD(" & integer'image(BREAKCODE) &
") = ""00"" & x""88""";
end if;
end process;
end architecture;
以上代码分析、阐述和运行:
ghdl -a engine.vhdl
ghdl -e engine
ghdl -r engine
engine.vhdl:27:13:@0ms:(report note): MAT_WORD(5) = "00" & x"88"
你可以看到它报告并发信号分配写入的位置。
请注意,您在循环语句中将 I
的范围声明为 9 downto 0
超出类型 MAT
范围的代码中还有一个错误.此处已通过使用更正 MAT
的范围更正了这一点。 (循环常量 I
已被修改为使用声明对象的范围,允许您在一个地方更改矩阵的大小)。
您也可以使用不完整的类型声明:
type MAT is array (natural range <>) of bit_vector (9 downto 0);
并在对象声明中指定范围:
signal MAT_WORD: MAT (9 downto 0) := (others => (others => '0'));
在类型声明中固定范围似乎更合适。