生成随机数VHDL

生成随机数VHDL,vhdl,Vhdl,我需要在测试台上生成13位的随机二进制数。然后,当启动信号设置为1时,生成随机num_bin。为什么在我的代码中没有生成它?我的意思是,它生成0000000000000,什么时候应该生成一个13位的数字。有什么不对劲?多谢各位 注意:num_bin input是我必须在另一个进程中给出的数字 . . . reset <= '1', '0' after 75 ns; inicio <='0', '1' after 100 ns; process variable

我需要在测试台上生成13位的随机二进制数。然后,当启动信号设置为1时,生成随机num_bin。为什么在我的代码中没有生成它?我的意思是,它生成0000000000000,什么时候应该生成一个13位的数字。有什么不对劲?多谢各位

注意:num_bin input是我必须在另一个进程中给出的数字

  .
  .
  .
 reset <= '1', '0' after 75 ns;
 inicio <='0', '1' after 100 ns;

 process
 variable seed1 :integer ;
 variable seed2 :integer ;
 variable re1 : integer;
 variable re2 : real ;
 begin  

    if inicio = '1' then
    uniform (seed1,seed2,re2);
    re1 := integer (re2 * real(2**13 -1));  
   num_bin <= std_logic_vector ( to_unsigned (re1,13));
    end if;
 wait;
 end process;
。
.
.

重置删除进程中的条件,将seed1、seed2更改为正数,并让进程生成多个num_bin值:

library ieee;
use ieee.std_logic_1164.all;
use ieee.math_real.all;
use ieee.numeric_std.all;

entity uni is
end entity;

architecture foo of uni is
    signal num_bin: std_logic_vector (12 downto 0);
begin
    
NOLABEL:
    process
    variable seed1 :positive ;
    variable seed2 :positive ;
    variable re1 : integer;
    variable re2 : real ;
    begin  

       -- if inicio = '1' then
       uniform (seed1,seed2,re2);
       re1 := integer (re2 * real(2**13 -1));  
      num_bin <= std_logic_vector ( to_unsigned (re1,13));
       -- end if;
    wait for 10 ns;
    if Now > 50 ns then
        wait;
    end if;
    end process;
    
MONITOR:
    process (num_bin)
    begin
        report "uniform = " & to_string(num_bin) severity NOTE;
    end process;
end architecture;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.math_real.all;
使用ieee.numeric_std.all;
实体uni是
终端实体;
uniis的架构foo
信号数量:标准逻辑向量(12到0);
开始
诺拉贝尔:
过程
可变种子1:阳性;
可变种子2:阳性;
变量re1:整数;
变量re2:实数;
开始
--如果inicio='1',则
均匀(种子1、种子2、re2);
re1:=整数(re2*实(2**13-1));
那就50纳秒吧
等待
如果结束;
结束过程;
监视器:
进程(num_bin)
开始
报告“uniform=”&to_字符串(num_bin)严重性注释;
结束过程;
终端架构;
我们得到:

$GHDL-r uni
统一vhdl:44:9:@0ms:(报告注释):统一=uuuu
统一vhdl:44:9:@0ms:(报告注释):统一=1111
统一vhdl:44:9:@10ns:(报告注释):统一=111110001110
统一vhdl:44:9:@20ns:(报告注释):统一=1010010111000
统一vhdl:44:9:@30ns:(报告注释):统一=0101010101000
统一vhdl:44:9:@40ns:(报告注释):统一=0000100111
统一vhdl:44:9:@50ns:(报告注释):统一=0010101101

所有“1”的第一个非初始值可能是类型为正数的seed1和seed2的初始值的结果

如果您只得到所有“0”,是否正在将num_bin初始化为“0”

将条件计算添加回并初始化num_bin:

architecture fum of uni is
    signal num_bin: std_logic_vector (12 downto 0) := (others => '0');
    signal inicio: std_logic;
begin
    inicio <='0', '1' after 100 ns;
NOLABEL:
    process
    variable seed1 :positive ;
    variable seed2 :positive ;
    variable re1 : integer;
    variable re2 : real ;
    begin  
        if inicio = '1' then
            uniform (seed1,seed2,re2);
            re1 := integer (re2 * real(2**13 -1));  
            num_bin <= std_logic_vector ( to_unsigned (re1,13));
        end if;
        wait;
    end process;
    
MONITOR:
    process (num_bin)
    begin
        report "uniform = " & to_string(num_bin) severity NOTE;
    end process;
end architecture;
uni的架构fum是 信号数量:标准逻辑向量(12到0):=(其他=>'0'); 信号输入:标准逻辑; 开始
如果您想在VHDL中生成随机数,请查看开源OSVVM库

至少
uniform
要求用1中的值初始化
seed1
seed2
~2**31,但
整数的初始值为-2**31。因此,要么将两个种子值初始化为例如1,要么将它们声明为
正值
,以自动将初始值设置为1。我已经更改了,并且保持不变。我已经隐藏了一个不依赖于开始的值,它可以工作,但是如果我开始依赖于值1,它将不再工作。那应该是什么?同步错误?