1

コードは次のとおりです。

entity main is
port(input:in unsigned(99 downto 0);
clk:in std_logic;
output:out unsigned(99 downto 0)
);
end main;

architecture Behavioral of main is

begin

process(clk)

variable x:unsigned(99 downto 0):=X"27c8a94a6fb72a00000000000";
begin
if(clk'event and clk='1') then

x:=(x*input);// this line is a problem!!

output<=x;
x:=X"27c8a94a6fb72a00000000000";// i have to rest x manually :S

end if;
end process;
end Behavioral;

最初の問題は、xは変数であり、プロセスが実行されるたびにリセットする必要がありますが、リセットせず、その値を保存することです。シミュレーションで段階的に見てきました。2番目の問題は、入力がこのエンティティに固定されており、各clkプロセスによって変更されないにもかかわらず、x * input(正解)または0(不正解)のいずれかです。クロックを少し減らすと、正解(入力x)で停止する可能性があります私の問題は、入力とxが固定されている場合、入力xが固定されない理由です。2つ目は、プロセスが再度呼び出されたときにxがリセットされない理由です(感度リストから) )。テストコードは次のとおりです。


LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
use IEEE.numeric_std.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;

ENTITY test IS
END test;

ARCHITECTURE behavior OF test IS 

    -- Component Declaration for the Unit Under Test (UUT)

    COMPONENT main
    PORT(
         input : IN  unsigned(99 downto 0);
         clk : IN  std_logic;
         output : OUT  unsigned(99 downto 0)
        );
    END COMPONENT;


   --Inputs
   signal input : unsigned(99 downto 0) := (others => '0');
   signal clk : std_logic := '0';

    --Outputs
   signal output : unsigned(99 downto 0);

   -- Clock period definitions
   constant clk_period : time := 10 ns;

BEGIN

    -- Instantiate the Unit Under Test (UUT)
   uut: main PORT MAP (
          input => input,
          clk => clk,
          output => output
        );

   -- Clock process definitions
   clk_process :process
   begin
        clk <= '0';
        wait for clk_period/2;
        clk <= '1';
        wait for clk_period/2;
   end process;


   -- Stimulus process
   stim_proc: process
   begin        
      -- hold reset state for 100 ns.
      wait for 100 ns;  
input<=X"000000000000000000000000F";
--input<="000000000001";
      wait for clk_period*10;

      -- insert stimulus here 

      wait;
   end process;

END;

///

テストの開始時に、入力値を挿入せずにプロセスが数回実行されることに注意してください。この場合、結果は気にしません。入力が挿入されると、この問題が発生することを話します。

4

2 に答える 2

1

最初に理解することは、プロセスを呼び出さないことです。

プロセスは1回だけ開始されるため、変数は1回だけ初期化されます。

実行が完了してスリープします。次のクロックイベントが起動し、各クロックサイクルの最初から完了まで実行されます。

プロセスを、イベントループを備えたCメインプログラムのようなものと考えると役立つ場合があります。イベントが発生するまでスリープし、宣言した変数はグローバル変数(または「静的」変数-最後の値を保持します)です。

C関数またはプロシージャ(、ボイド関数)の効果が必要な場合は、VHDL関数またはプロシージャを記述します。これらのローカル変数は、プロセス内で呼び出すたびに再初期化されます。

したがって、1クロックサイクルx * input後、数クロックサイクル後、最下位100ビットがx * input * input * input ... * input表示されます。乗算ワードの増加により、最終的にはすべて0になります。

新しい入力ごとにXの初期値を掛けるだけの場合は、Xを定数として宣言し、次のように記述したほうがよいでしょう。

process(clk)
constant x:unsigned(99 downto 0):=X"27c8a94a6fb72a00000000000";
begin
   if rising_edge(clk) then
      output <= x * input;
   end if;
end process;
于 2013-03-14T16:11:40.450 に答える
0

問題は、長さ100の2つの符号なし値を乗算することです。これにより、長さ200の結果になります(numeric_stdパッケージを参照してください)。次のように問題を解決できます。

entity main is
port(
input:in unsigned(99 downto 0);
clk:in std_logic;
output:out unsigned(199 downto 0)
);
end main;

architecture Behavioral of main is

begin
process(clk) 
    variable x:unsigned(99 downto 0); 
    variable x_res:unsigned(199 downto 0); 
begin 
    if(clk'event and clk='1') then 
        x:=(input); 
        x_res:=(x*x); 
        output<=x_res; 
    end if; 
end process; 
end Behavioral;
于 2013-03-15T08:26:32.153 に答える