2017-06-28 1 views
0

16ビットのランダムシーケンスを生成しようとしています。 問題は、出力が未定義状態になっていることです。私はこれがxorステートメントでの並列処理によるものだと感じています。だから私は遅れを入れましたが、それはまだ動作しません。あなたのLFSRにいくつかの小さな構造的な変更を加える16ビットLFSRで擬似ランダムシーケンスを作成する方法

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 

entity random_data_generator is 
    port (
    por    : in STD_LOGIC; 
    sys_clk   : in STD_LOGIC; 
    random_flag  : in STD_LOGIC; 
    random_data  : out STD_LOGIC_vector (15 downto 0) 
); 
end random_data_generator; 

architecture Behavioral of random_data_generator is 
    signal q   : std_logic_vector(15 downto 0); 
    signal n1,n2,n3 : std_logic; 


begin 
    process(sys_clk) 
    begin 
    if(por='0') then 
    q<= "1001101001101010"; 
    elsif(falling_edge(sys_clk)) then 
     if(random_flag='1') then 
     n1<= q(15) xor q(13); 
     n2<= n1 xor q(11) after 10 ns; 
     n3<= n2 xor q(10) after 10 ns; 
     q<= q(14 downto 0) & n3 after 10 ns; 
    end if; 
    end if; 
    end process; 
    random_data <= q; 
end Behavioral; 
+0

覚えておいてください:「乱数を生成する算術的方法を考慮する人は、もちろん、罪の状態です」。 - ジョン・フォン・ノイマン1951_。 PRNGは本当に乱数を生成しません。 – JHBonarius

+0

ザイリンクスアプリケーションノート[XAPP052](https://www.xilinx.com/support/documentation/application_notes/xapp052.pdf)は、ハードウェアリソースを最小限に抑えてPRNGを実装する方法を示しています。 PoC IPコア[PoC.arith.prng](https://github.com/VLSI-EDA/PoC/blob/master/src/arith/arith_prng.vhdl?ts=2)は、3〜168の設定可能なPRNGですビットは、XAPP052によって提供されるPRNG多項式を実装する値を出力します。 – Paebbels

答えて

4

library ieee; 
use ieee.std_logic_1164.all; 

entity random_data_generator is 
    port (
     por:    in std_logic; 
     sys_clk:   in std_logic; 
     random_flag:  in std_logic; 
     random_data:  out std_logic_vector (15 downto 0) 
    ); 
end entity random_data_generator; 

architecture behavioral of random_data_generator is 
    signal q:    std_logic_vector(15 downto 0); 
    signal n1, n2, n3: std_logic; 
begin 
    process (por, sys_clk) -- ADDED por to sensitivity list 
    begin 
     if por = '0' then 
      q <= "1001101001101010"; 
     elsif falling_edge(sys_clk) then 
      if random_flag = '1' then 
       -- REMOVED intermediary products as flip flops 
       q <= q(14 downto 0) & n3; -- REMOVED after 10 ns; 
      end if; 
     end if; 
    end process; 
    -- MOVED intermediary products to concurrent signal assignments: 
    n1 <= q(15) xor q(13); 
    n2 <= n1 xor q(11); -- REMOVED after 10 ns; 
    n3 <= n2 xor q(10); -- REMOVED after 10 ns; 

    random_data <= q; 
end architecture behavioral; 

これらの変更は、N1、N2を削除し、n3のフリップは、同時処理信号代入文にそれらの割り当てを促進することにより、フリップフロップ。 'U'を生成する根本的な問題は、これらのフリップフロップが初期化されていないことです。彼らはその割り当てがsys_clkの立ち下がり時にelsif条件付きのif文内にあったので、フリップフロップでした。

テストベンチの追加:起草とテストベンチをシミュレートする、両方の分析

library ieee; 
use ieee.std_logic_1164.all; 

entity rng_tb is 
end entity; 

architecture foo of rng_tb is 
    signal por:   std_logic; 
    signal sys_clk:  std_logic := '0'; 
    signal random_flag: std_logic; 
    signal random_data: std_logic_vector (15 downto 0); 
begin 
DUT: 
    entity work.random_data_generator 
     port map (
      por => por, 
      sys_clk => sys_clk, 
      random_flag => random_flag, 
      random_data => random_data 
     ); 
CLOCK: 
    process 
    begin 
     wait for 5 ns; 
     sys_clk <= not sys_clk; 
     if now > 2800 ns then 
      wait; 
     end if; 
    end process; 
STIMULI: 
    process 
    begin 
     por <= '1'; 
     random_flag <= '0'; 
     wait until falling_edge(sys_clk); 
     por <= '0'; 
     wait until falling_edge(sys_clk); 
     wait for 1 ns; 
     por <= '1'; 
     wait until falling_edge(sys_clk); 
     random_flag <= '1'; 
     wait; 
    end process; 
end architecture; 

する与える:

rng_tb.png

は、16ビットを使用して16よりも長い長さを有する擬似ランダムシーケンスを示しますリニアフィードバックシフトレジスタ(LFSR)。

関連する問題