我是 VHDL 的新手,我正在尝试如下模拟一个块:
- 它有四个
std_logic_vector
输入,分别命名为a
、和。输入和是有符号数,输入和是无符号数。b
c
d
a
b
c
d
- 它有四个输出,分别名为
u
、和。输出和 是有符号数,输出和是无符号数。v
w
x
u
v
w
x
输出定义如下:
u = a + b
v = a / 2
w = c * d
x = c * 2
内部信号是整数。
我能够编译模块和测试台。我遇到的问题是,当我尝试模拟电路时,会显示以下错误消息:
ncsim: *E,TRRANGEC: range constraint violation.
File: ./operator2.vhd, line = 38, pos = 36
Scope: :inst_operator:$PROCESS_007
Time: 0 FS + 0
结果,模拟器无法启动。我不明白这条线怎么可能是错误的:
x <= std_logic_vector(to_unsigned(sx, 17));
我尝试通过将这一行更改为其他执行相同操作的行,但我在同一行中得到错误。如果我删除此行,第 37 行会报告错误。请给我提示以找出我的错误吗?下面是模块的代码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity operator2 is
port(
a: in std_logic_vector(15 downto 0);
b: in std_logic_vector(15 downto 0);
c: in std_logic_vector(15 downto 0);
d: in std_logic_vector(15 downto 0);
u: out std_logic_vector(16 downto 0);
v: out std_logic_vector(14 downto 0);
w: out std_logic_vector(31 downto 0);
x: out std_logic_vector(16 downto 0)
);
end entity operator2;
architecture a2 of operator2 is
signal su: integer;
signal sv: integer;
signal sw: integer;
signal sx: integer;
begin
--signals affectation
su <= to_integer(signed(a)) + to_integer(signed(b));
sv <= to_integer(signed(a)) / 2;
sw <= to_integer(unsigned(c)) * to_integer(unsigned(d));
sx <= to_integer(unsigned(c)) * 2;
--outputs affectation
u <= std_logic_vector(to_signed(su, 17));
v <= std_logic_vector(to_signed(sv, 15));
w <= std_logic_vector(to_unsigned(sw, 32));
x <= std_logic_vector(to_unsigned(sx, 17)); --This is the line reporting the error during the simulation**
end architecture a2;