【发布时间】:2017-01-28 20:19:41
【问题描述】:
我是 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;
【问题讨论】:
-
要么将
sw和sx初始化为 natural'left 和 natural'right 内的值,要么将它们定义为 natural 类型:signal sw: natural; signal sx: natural;。问题是sw和sx的默认值超出了to_unsigned转换的自然范围。请注意,w(31) 将始终为“0”。 -
@user1155120 : 你确定 w(31) 总是'0',给定(比如说)c = d = x"ffff"(两个有效的 16 位无符号值)?跨度>
-
sw作为整数只能为无符号数提供 31 位(自然范围)。负数表示我们在此处看到的边界检查失败。 (所有这一切都假设一个整数的最小保证范围 –2147483647 到 +2147483647,这在常见的模拟器中是通用的。一个正数只能是 31 位)。
标签: integer vhdl unsigned signed bitvector