2017-10-06 7 views
0

VHDLを使用してSRフリップフロップを実装したかったのです。フリップフロップとテストベンチのコードを書きました。しかし、テストベンチは正しくコンパイルされず、わからないエラーが発生します。私はghdlを使ってコンパイルしています。助けてください。SR FliflopのVHDLテストベンチ

これはフリップフロップのコードです。

library ieee; 
use ieee.std_logic_1164.all; 

entity sr_flipflop is 
    port 
    (
     s,r,clock: in std_logic; 
     q,qbar: inout std_logic 
    ); 
end sr_flipflop; 

architecture arc of sr_flipflop is 
    signal x,y: std_logic; 
begin 
    process (clock,s,r) begin 
     x<=r and clock; 
     y<=s and clock; 
     q<=qbar nor x after 10 ns; 
     qbar<=q nor y after 10 ns; 
    end process; 
    process (x,y) begin 
     q<=qbar nor x after 5 ns; 
     qbar<=q nor y after 5 ns; 
    end process; 
end architecture arc; 

これはテストベンチのコードです。

library ieee; 
use ieee.std_logic_1164.all; 

entity sr_flipflop_tb is 
end entity sr_flipflop_tb; 

architecture arc of sr_flipflop is 
    component sr_flipflop is 
     port 
     (
      s,r,clock: in std_logic; 
      q,qbar: inout std_logic 
     ); 
    end component sr_flipflop; 

    signal clock:std_logic:='0'; 
    signal s,r:std_logic; 
    signal q:std_logic:='0'; 
    signal qbar:std_logic:='1'; 
    constant half_period:time:=30 ns; 

begin 
    port_map:sr_flipflop port map(clock=>clock,s=>s,r=>r,q=>q,qbar=>qbar); 

    process begin 
     clock <= not clock after half_period; 
    end process; 
    process begin 
     s<='0'; 
     r<='0'; 

     s<='0' after 40 ns; 
     r<='1' after 40 ns; 

     s<='1' after 80 ns; 
     r<='0' after 80 ns; 

     s<='1' after 120 ns; 
     r<='1' after 120 ns; 
    end process; 

end architecture arc; 

私は次のエラーを取得する最初のファイルには、エラーなしでコンパイルが、私はCMDで次のコマンドを与えるとき、

ghdl -a sr_flipflop_tb.vhd 

sr_flipflop_tb.vhd:16:15: identifier 'clock' already used for a declaration 
sr_flipflop.vhd:7:20: previous declaration: port "clock" 
sr_flipflop_tb.vhd:17:15: identifier 's' already used for a declaration 
sr_flipflop.vhd:7:16: previous declaration: port "s" 
sr_flipflop_tb.vhd:17:17: identifier 'r' already used for a declaration 
sr_flipflop.vhd:7:18: previous declaration: port "r" 
sr_flipflop_tb.vhd:18:15: identifier 'q' already used for a declaration 
sr_flipflop.vhd:8:16: previous declaration: port "q" 
sr_flipflop_tb.vhd:19:15: identifier 'qbar' already used for a declaration 
sr_flipflop.vhd:8:18: previous declaration: port "qbar" 
sr_flipflop_tb.vhd:26:16: port "clock" can't be assigned 
sr_flipflop_tb.vhd:29:16: port "s" can't be assigned 
sr_flipflop_tb.vhd:30:16: port "r" can't be assigned 
sr_flipflop_tb.vhd:32:16: port "s" can't be assigned 
sr_flipflop_tb.vhd:33:16: port "r" can't be assigned 
sr_flipflop_tb.vhd:35:16: port "s" can't be assigned 
sr_flipflop_tb.vhd:36:16: port "r" can't be assigned 
sr_flipflop_tb.vhd:38:16: port "s" can't be assigned 
sr_flipflop_tb.vhd:39:16: port "r" can't be assigned 

いくつかの光を当てるしてください。ありがとう。あなたのテストベンチで

答えて

3

7行目は、これはコピー&ペースト誤りであるように思わ

architecture arc of sr_flipflop is 

あり、それはこれがこれらのエラーメッセージを起こす必要がある

architecture arc of sr_flipflop_tb is 

でなければなりません。

あなた自身のコード自体は、理想的ではありません。 ModelSimでは、あなたのテストベンチはまったく動かないでしょう(私はGHDLについて知らない)。おそらくthis tutorialをチェックしてください。わずかに年代がついていますが、機能します。

+0

VHDL-2008を使用して起動し、あなたは私のコードが理想的ではありませんどの局面では詳しく説明していただけますか?私は数日前にVHDLを使い始めましたので、ちょっとした助けに本当に感謝しています。 –

+0

"not ideal"はかなり控えめです;) – JHBonarius

0

この

entity sr_flipflop_tb is 
end entity sr_flipflop_tb; 

architecture arc of sr_flipflop is 

はあなたがqq_barを駆動する二つの方法があり、この

entity sr_flipflop_tb is 
end entity sr_flipflop_tb; 

architecture arc of sr_flipflop_tb is 
        ^^^^^^^^^^^^^^ 
1

ないあなたの質問への答えしかし

process (clock,s,r) begin 
    x<=r and clock; 
    y<=s and clock; 
    q<=qbar nor x after 10 ns; 
    qbar<=q nor y after 10 ns; 
end process; 
process (x,y) begin 
    q<=qbar nor x after 5 ns; 
    qbar<=q nor y after 5 ns; 
end process; 

でなければなりません。これは意図したとおりに動作しません。複数のドライバのため、信号は'X'に解決されます。


次の問題は機密性リストです。

process (x,y) begin 
    q<=qbar nor x after 5 ns; 
    qbar<=q nor y after 5 ns; 
end process; 

qq_bar感度リストにありません。したがって、q_bar、resp。がある場合、qq_barは更新されません。 qが更新されました。


次の問題は信号の更新です。

信号は次のデルタサイクルまで更新されません。デルタサイクルは、プロセスが終了した後に発生します。だから、:xは次のデルタサイクルまで更新されませんよう

process (clock,s,r) begin 
    x<=r and clock; 
    q<=qbar nor x after 10 ns; 
end process; 

によるrまたはclockの変化にxの変化は、この次の行にqに適用されることはありません。


最後に、inoutポートタイプを使用しないでください。

出力ポートに内部アクセスする場合は、VHDL-2008を使用してコンパイルするか、中間信号を使用します。

architecture ... of ... 
    signal q_int : std_logic; 
begin 
    [... assign and use q_int] 
    q <= q_int; 
end architecture; 

しかし好ましく

関連する問題