arrays - 模型模拟。数组长度不匹配
问题描述
我在 modelsim 中编写了一个程序,将数字相加并将结果放入 Ra/Sum 中。我使用了三态缓冲区,但我得到了这个:致命:(vsim-3420)数组长度不匹配。左边是 16(从 15 到 0)。右边是 8(从 7 到 0)。我知道这是因为它们的长度不同。但是它们也不能具有相同的长度,因为在添加 add1 和 add2 并将它们放入 Sum 时出现错误。那么我能做些什么来完成这项工作呢?
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.numeric_std.all;
entity MAC is
generic (width: integer := 8);
port(
clk, reset : in STD_LOGIC;
MLS_select : in STD_LOGIC;
Rn, Rm, Ra : in STD_LOGIC_VECTOR(width-1 downto 0);
Rd : out STD_LOGIC_VECTOR(width-1 downto 0)
);
end;
architecture behavioral of MAC is
signal mul1, mul2, add1 : UNSIGNED(width-1 downto 0);
signal add2, sum : UNSIGNED(width*2-1 downto 0);
begin
process(clk, reset)
begin
if reset = '1' then Rd <= (others => '0');
elsif rising_edge(clk) then
Rd <= STD_LOGIC_VECTOR(sum(width-1 downto 0));
end if;
end process;
mul1 <= UNSIGNED(Rn);
mul2 <= UNSIGNED(Rm);
add1 <= UNSIGNED(Ra);
add2 <= mul1*mul2;
sum <= add2 when clk = '1' else add2;
sum <= add1+add2;
end architecture;
解决方案
起初,... when clk = '1' else ...
会创建一个锁存器,但没有触发器。
你需要使用... when rising_edge(clk);
.
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity MAC is
generic (width: integer := 8);
port(
clk, reset : in STD_LOGIC;
MLS_select : in std_logic;
Rn, Rm, Ra : in std_logic_vector(width - 1 downto 0);
Rd : out std_logic_vector(width - 1 downto 0) := (others => '0')
);
end entity;
architecture rtl of MAC is
signal mul1, mul2, add1 : unsigned(width - 1 downto 0);
signal add2, sum : unsigned(width * 2 - 1 downto 0);
begin
process(clk, reset)
begin
if (reset = '1') then
Rd <= (others => '0');
elsif rising_edge(clk) then
Rd <= std_logic_vector(sum(Rd'range));
end if;
end process;
mul1 <= unsigned(Rn);
mul2 <= unsigned(Rm);
add1 <= unsigned(Ra);
add2 <= (mul1 * mul2) when rising_edge(clk);
sum <= resize(add1, add'length) + add2;
end architecture;
信号MLS_select
未使用。没有必要计算这么多位的总和。我建议add2
在添加之前截断,以减少未使用位的数量(以及它们产生的警告)。
推荐阅读
- javascript - 仅使用 URL 在表单数据中附加文件
- bootstrap-4 - Bootstrap 4 列排序用例
- python - 从两个列表创建目录
- javascript - 在 Node JS 中链接请求和事件数据
- php - 流明 - handler.php 不反映更新
- laravel - 带有参数的 http POST 到 /session 引发的 curl 错误:Facebook\WebDriver\Exception
- f# - 错误 FS0193:类型约束不匹配
- python - LUNA16 切片注释
- opencv - OpenCV:特征匹配+单应性帮助调整结果
- cloudera-cdh - 从 Knox 访问 Cloudera 上的 kerberized WebHDFS