2017-12-19 7 views
0

VHDLに乱数シーケンスジェネレータを書き込めません。 これを行うために線形方程式を使用しようとしましたが、ザイリンクスコンパイラは構文について不平を言っています。VHDL-線形方程式を使用してシードで擬似乱数を生成する?

このコードではクロック入力が使用され、ボードにはシードを入力するためのスイッチが7つあります。そこから、すべての代数です。それで、私は望みました。

私が持っているコードは以下の通りです:

entity RandNumSeqGen is 
    Port (clk : in STD_LOGIC; 
      switches: in STD_LOGIC_VECTOR (6 downto 0); 
      num : out STD_LOGIC_VECTOR (0 to 3)); 
end RandNumSeqGen; 

architecture Behavioral of RandNumSeqGen is 
constant M : integer := 278200; 
constant A : integer := 6521; 
constant B : integer := 88977; 
variable rand_f: real :=0.0; 
variable rand_d: integer :=0; 
variable seed: integer :=0; 
seed <= to_integer(signed(switches)); 

begin 
if (clk'event and clk='1') then 
    Seed := (seed*A+B) mod M; 
    rand_f:=seed/real(M); 
    rand_f:=rand_f*1000; 
    rand_d:=integer(rand_f) mod 12; 
    num<= rand_d; 
end if; 


end Behavioral; 

コードは、理想的には0と11の間に新たな乱数を作り続けるとnum個の出力にそれを記述します。

エラーレポートには、言い訳があります。

多分、変数の宣言に問題がありますか? 修正が必要なことがわかっている場合は、教えてください。私はより良くすることを学びたい。

Line 47: Syntax error near "seed". 
Line 50: Syntax error near "then". 
Line 51: Syntax error near "mod". 
Line 52: Syntax error near ":=". 
Line 53: Syntax error near ":=". 
Line 54: Syntax error near "mod". 
Line 56: Syntax error near "if". 
ERROR:ProjectMgmt - 7 error(s) found while parsing design hierarchy. 

ご不便をおかけして申し訳ございませんが、私はVHDLの数値変数を使い始めました。今まで

+2

はどこライン47 26行の例である...私は –

+1

はい、VHDLには変数がありますが、使用する信号は信号です。ですから、教科書やオンラインメディアを参照し、VHDLと信号についてお読みください。タイプrealは合成不可能です。 – Paebbels

+0

このコードでは多くの構文エラーがあります。あなたはVHDLチュートリアルなどを探し始めるべきです。 VHDLはC、JavaなどのCPU言語ではありません。 – JHBonarius

答えて

0

はあなたのコードは、おそらく

library ieee; 
use ieee.std_logic_1164.all; 

entity RandNumSeqGen is 
    Port (
     clk : in STD_LOGIC; 
     switches: in STD_LOGIC_VECTOR (6 downto 0); 
     num : out STD_LOGIC_VECTOR (0 to 3) 
    ); 
end entity; 

architecture Behavioral of RandNumSeqGen is 
    use ieee.numeric_std.all; 
    constant M : integer := 278200; 
    constant A : integer := 6521; 
    constant B : integer := 88977; 
begin 
    gen_rand_out: process(clk) 
     variable rand_f: real := 0.0; 
     variable rand_d: integer := 0; 
     variable seed: integer := 0; 
    begin 
     if rising_edge(clk) then 
      -- seed := to_integer(signed(switches)); -- I don't get what you want to do here 
      seed := (seed*A+B) mod M; 
      rand_f := real(seed)/real(M); 
      rand_f := rand_f*1000.0; 
      rand_d := integer(rand_f) mod 12; 
      num <= std_logic_vector(to_unsigned(rand_d, num'length)); 
     end if; 
    end process; 
end architecture; 

をする必要がありますCとPython

を使用しました。しかし、もちろん、この意志は合成ではありませんか?また、別のVHDLコンパイラを試してみることもできます。構文エラーが何であるかを教えてくれます。たとえば、「信号への変数代入を使用できません」、「整数と実数の間の積分演算子がオーバーロードされていません」、「プロセス文の外部で使用できない場合」などがあります。
関連する問題