vhdl - std_logic_vector (to_unsigned(X, Y));
问题描述
这是一个测试台,我有这些信号:
signal DATA_INPUT :std_logic_vector(0 to 31);
signal rand_num :integer;
我试图通过以下方式将随机数放入这个 32 位信号中:
DATA_INPUT <= std_logic_vector(to_unsigned(rand_num, 32));
我的问题是,我需要超过 31 位的数字,但是当随机数超过这个数字时:2147483647 这是 INTEGER'high,我收到这个错误:
near "4294967295": (vcom-119) Integer value exceeds INTEGER'high.
# ** Error: tb.vhd: (vcom-1144) Value -1 (of type
std.STANDARD.NATURAL) is out of range 0 to 2147483647.
我尝试修改 TO_UNSIGNED() 函数并将 NATURAL 输入更改为其他内容,但没有。
这是来自 IEEE 和 RANDOOM GENERATOR 进程的 TO_UNSIGNED 函数:
function TO_UNSIGNED(ARG, SIZE: NATURAL) return UNSIGNED is
variable RESULT: UNSIGNED (SIZE-1 downto 0);
variable i_val: NATURAl := ARG;
begin
if (SIZE < 1) then return NAU; end if;
for i in 0 to RESULT'left loop
if (i_val MOD 2) = 0 then
RESULT(i) := '0';
else RESULT(i) := '1';
end if;
i_val := i_val/2;
end loop;
if not(i_val=0) then
assert NO_WARNING
report "numeric_std.TO_UNSIGNED : vector truncated"
severity WARNING;
end if;
return RESULT;
end TO_UNSIGNED;
随机发生器:
process
variable seed1, seed2 :positive;
variable rand :real;
variable range_of_rand :real:= 46340.0;
begin
uniform(seed1, seed2, rand);
rand_num <= integer(rand*range_of_rand);
wait for 1 ns;
end process;
解决方案
您可以通过组合两个来制作一个新的更大的随机数。
最简单的解决方案是将两个随机整数转换为向量,然后连接,直到获得所需的位数。这为您提供了 64 位:
DATA_INPUT <= std_logic_vector(to_unsigned(rand_num, 32)) & std_logic_vector(to_unsigned(rand_num, 32));
推荐阅读
- reactjs - 在 React 中将光标更改为自定义光标
- c# - 如何向 wpf 添加对另一个应用程序的引用,该应用程序已在 powerbuilder 中编写
- php - 如何为子目录配置 .htaccess
- javascript - 使用 fs.mkdir 创建文件夹仅限于只读,因此我无法删除文件夹。节点.js
- c# - Rhino 是否有任何插件或 api 可以将图像直接上传和导入到编辑器
- php - 不要不明白为什么没有正确提交扩展的 ChoiceType 值
- javascript - 为什么 JavaScript 中的下划线功能不起作用?
- c - 从孩子到父母的丢失信号
- dialogflow-es - 是否可以在 Google Home Hub 上创建“粘性”通知?
- python-3.x - 使用 cookiejar 和 urllib.request 的 Python3 问题