2

VHDLでカウンターを作成しようとしています。最終的な目標は、「do_count」をボタンにフックすることです。合計はBCDに変換され、7セグメントディスプレイに表示されます。ボタンを押して、数字が増えるのを見てください。

ModelSimを使用していますが、内部の「counter_value」が1ずつ正しくインクリメントされていることがわかります。ただし、2つのテスト「do_count」で出力信号「total」が「000X」、次に「00X0」になります。X'd信号を受信するのはなぜですか?

「output<=current_value」をプロセス内、プロセス外、「if」内などに移動しました。それでも「000X」です。

プロセス内で変数「tmp」を使用してみました。

count_up : process(clk) is
   variable tmp : unsigned (15 downto 0 );
begin
   tmp := current_value;
   -- snip
   if do_count='1' then
      current_value <= tmp + to_unsigned(1,16);
   end if;

それでも私は「000X」を手に入れます。

完全なコード:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;

entity d_counter is
    port ( rst : in std_logic;
           clk : in std_logic;
           do_count : in std_logic;
           total : out unsigned (15 downto 0)
        );
  end entity d_counter;

architecture counter_arch of d_counter is
  signal current_value : unsigned (15 downto 0) := (others=>'0');
begin
  count_up : process(clk) is
  begin
    if rst='1' then
      current_value <= (others=>'0');
      total <= (others=>'0');
    elsif rising_edge(clk) then
      if do_count='1' then
        current_value <= current_value + to_unsigned(1,16);
      end if;
    end if;
  end process count_up;
  total <= current_value;
end architecture counter_arch;

テストベンチ:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;

entity test_counter is 
  begin
  end entity test_counter;

architecture run_test_counter of test_counter is

  signal t_rst : std_logic := '1';
  signal t_clk : std_logic := '0';
  signal t_do_count : std_logic;
  signal t_total : unsigned( 15 downto 0 );

  component d_counter is
    port ( rst : in std_logic;
           clk : in std_logic;
           do_count : in std_logic;
           total : out unsigned( 15 downto 0 )
        );
  end component d_counter;

begin
  uut : d_counter
    port map( rst => t_rst,
      clk => t_clk,
      do_count => t_do_count,
      total => t_total );

    clock : process is 
    begin

        t_clk <= '0'; wait for 10 ns;
        t_clk <= '1'; wait for 10 ns;
    end process clock;

    stimulus : process is
    begin
      t_rst <= '1';
      t_do_count <= '0';
      t_total <= (others =>'0');
      wait for 15 ns;

      t_rst <= '0';
      wait for 10 ns;

      t_do_count <= '1';
      wait for 10 ns;

      t_do_count <= '0';
      wait for 10 ns;

      t_do_count <= '1';
      wait for 10 ns;

      t_do_count <= '0';
      wait for 10 ns;

      wait;

    end process stimulus;
end architecture run_test_counter;

2012年10月3日更新。両方の答えが役に立ちました。プロセス内で「total<=current_value」を移動し(@simonから)、余分な「t_total <=(others => '0');」を削除します。(@ peter-bennettから)私のテストベンチで必要でした。Xを取り除くために両方をしなければなりませんでした。

4

2 に答える 2

3

あなたのコードは「合計」でマルチドライブを記述します。プロセスcount_upで割り当てを削除する必要があります。

count_up : process(clk) is
  begin
    if rst='1' then
      current_value <= (others=>'0');
      total <= (others=>'0');  --> Remove it
    elsif rising_edge(clk) then
      if do_count='1' then
        current_value <= current_value + to_unsigned(1,16);
      end if;
     end if;
  end process count_up;

  total <= current_value; -- Keep it
于 2012-10-03T06:47:18.180 に答える
3

あなたの間違いはあなたのテストベンチにあるようです。信号はカウンターコンポーネントt_totalの出力にマッピングされますが、割り当てを使用して書き込みを行っています。これを削除すれば、問題はなくなると思います。totalt_total <= (others => '0')

  uut : d_counter
    port map( rst => t_rst,
      clk => t_clk,
      do_count => t_do_count,
      total => t_total );

    clock : process is 
    begin

        t_clk <= '0'; wait for 10 ns;
        t_clk <= '1'; wait for 10 ns;
    end process clock;

    stimulus : process is
    begin
      t_rst <= '1';
      t_do_count <= '0';
      t_total <= (others =>'0'); <-- Do not assign to t_total (its an output)
于 2012-10-03T08:53:13.833 に答える