6

私は次のコードを持っています(それは押されたボタンの数をエンコードします):

with buttons select
  tmp <= "000" when x"1",
         "001" when x"2",
         "010" when x"4",  
         "011" when x"8",
         "100" when others;
code <= input(1 downto 0);
error <= input(2);

信号を使わずに書き直そうとしていtmpます。出来ますか?以下は機能しません。

with buttons select
  error & code <= "000" when x"1",
                  "001" when x"2",
                  "010" when x"4",  
                  "011" when x"8",
                  "100" when others;
4

2 に答える 2

5

selectの代わりに、次のケースを使用できます。

my_process_name : process(buttons)
begin
  case buttons is
    when x"1" =>
      error <= '0';
      code  <= "00";
    when x"2" =>
      error <= '0';
      code  <= "01";
    when x"4" =>
      error <= '0';
      code  <= "10";
    when x"8" =>
      error <= '0';
      code  <= "11";
    when others =>
      error <= '1';
      code  <= "00";
  end case;
end process;
于 2013-03-09T20:08:57.283 に答える
0

または、これを2つの別々のwith/whenステートメントとして記述することもできます。

with buttons select
  error <= '0' when x"1",
           '0' when x"2",
           '0' when x"4",  
           '0' when x"8",
           '1' when others;
with buttons select
  code <= "00" when x"1",
          "01" when x"2",
          "10" when x"4",  
          "11" when x"8",
          "00" when others;

または代わりに:

error <= '0' when (buttons = X"1" or buttons = X"2" buttons = X"4" buttons = X"8") else '1'; 
code <= "00" when buttons = X"1" else "01" when buttons = X"2" else "10" when buttons = X"4" else "11" when buttons = X"8" else "00"; 

VHDLは、コンパイルされた言語、または合成された言語です。合成ツールが関連する論理構造を作成する限り、どの形式でも問題ありません。残りは、コードを理解して維持できるようにするための構文です。

于 2018-05-15T16:30:20.120 に答える