0

4つの押しボタンを入力として使用し、3つの7セグメントLEDディスプレイを出力として使用したいと思います。2つのプッシュボタンは、16のRAMロケーションを上下に移動する必要があります。他の2つは、現在表示されているメモリ位置の内容をインクリメントおよびデクリメントする必要があります。私は次の2つのエンティティを持っています:

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

entity DE2_TOP is

  port (
    KEY : in std_logic_vector(3 downto 0);         -- Push button
    CLOCK_50: in std_logic;
    );

end DE2_TOP;

architecture datapath of DE2_TOP is

begin  
  U1: entity work.lab1 port map (
    key => key,
    clock => clock_50,        
  );

end datapath;

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

entity raminfr is                     -STANDARD RAM INFERENCE
    port (
        clock: in std_logic;
        we : in std_logic;
        a : in unsigned(3 downto 0);
        di : in unsigned(7 downto 0);
        do : out unsigned(7 downto 0)
    );
end raminfr;

architecture rtl of raminfr is

type ram_type is array (0 to 15) of unsigned(7 downto 0);
signal RAM : ram_type;
signal read_a : unsigned(3 downto 0);
begin
process (clock)
begin
    if rising_edge(clock) then
        if we = '1' then
            RAM(to_integer(a)) <= di;
        end if;
        read_a <= a;
    end if;
end process;
do <= RAM(to_integer(read_a));
end rtl;

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

entity lab1 is
    port(
        clock : in std_logic;
        key : in std_logic_vector(3 downto 0); 
        );
end lab1;

architecture up_and_down of lab1 is
    signal value_in_ram : unsigned(7 downto 0);
    signal we : std_logic;
    signal value_counter    : unsigned(7 downto 0) ;
    signal register_counter : unsigned(3 downto 0);
        begin
    U1: entity work.raminfr port map (
        a   => register_counter,
        di  => value_counter,
        do  => value_in_ram,
        clock => clock,
        we  => we
    );

    process(clock)
        begin
            if rising_edge(clock) then
                if (key(3)='0' and key(2)='0' and key(1)='1' and key(0)='0') then
                    value_counter <= value_counter + "1";   
                elsif (key(3)='0' and key(2)='0' and key(1)='0' and key(0)='1') then  
                    value_counter <= value_counter - "1";   
                elsif (key(3)='1' and key(2)='0' and key(1)='0' and key(0)='0') then
                    register_counter<= register_counter + "1";
                    value_counter <= value_in_ram;
                elsif (key(3)='0' and key(2)='1' and key(1)='0' and key(0)='0') then
                    register_counter<= register_counter - "1";
                    value_counter <= value_in_ram;
                end if;
            end if;
    end process;
end architecture up_and_down;

また、次のテストベンチがあり、KEYを介して押されているボタンをシミュレートしようとしています。

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


entity DE2_TOP_TEST is
end;

architecture BENCH of DE2_TOP_TEST is

    signal KEY :  std_logic_vector(3 downto 0);
    signal CLOCK_50 :  std_logic := '0';
    signal hex4, hex5, hex6 :  std_logic_vector(6 downto 0);           
begin
    clock_50 <= not clock_50 after 50 ns;
    process
        begin
            KEY<="0010";
                    wait for 1 us;
        KEY<="0000";
    end process;

uut:work.DE2_TOP port map (                                                         
    KEY=>key,
    CLOCK_50=>clock_50, 
    hex4=>hex4,
hex5=>hex5,
hex6=>hex6                                 
);
end BENCH;

私のテストベンチのセットアップは次のようになります。

ここに画像の説明を入力してください

シミュレートするために、上記の3つのファイルすべてをコンパイルしてから、DE2_TOP_TESTをシミュレートしますが、以下のように「KEY」がまだ定義されていないという結果になります(ただし、CLOCK_50は設定したデフォルト値を取得します)。

ここに画像の説明を入力してください

誰もがこれを引き起こしているのを知っていますか?

4

1 に答える 1

3

(1)テストするために入力しているエンティティに未接続のポートがあります。テスト結果は、これらの入力(具体的には、駆動されていないclk)に対して期待どおりです。

(2)clkを接続したら、それを駆動する必要があります。

signal clk : std_logic := '0';

clk <= not clk after 50 ns;

10MHzのクロックを与える必要があります。シミュレータでこれを確認してください

(3)特定の値のシーケンスで「KEY」を駆動します

subtype keys is std_logic_vector(3 downto 0);
constant count_up : keys := "0001";
constant count_dn : keys := "0010";
constant idle     : keys := "0000"; 
-- etc

    process
    begin
        KEY <= count_up;
        wait for 1 us;
        KEY <= idle;
        wait for ...
-- etc
    end process;

(4)出力をテストベンチに戻し、値を確認できるようにします。それらをディスプレイに接続する場合は、とにかくトップレベル(デザイン)エンティティのポートとしてそれらを引き出す必要があります!

次に(後で、計画が開始されたら)テストベンチプロセスでそれらをテストできます...

    wait for 100 ns;
    -- after the last press, we should have "07" on the display
    assert digit(1) = "0111111" report "Left digit has wrong value" severity ERROR;
    assert digit(0) = "0000111" report "Left digit has wrong value" severity ERROR;

このようなセルフチェックテストベンチは、波形を見つめることでデバッグを節約します。テストが失敗した場合にのみ波形が必要です...

于 2013-01-27T13:32:22.787 に答える