Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VHDL: with-select for multiple values

Tags:

select

vhdl

I have the following code (it encodes a number of a pressed button):

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);

I am trying to rewrite it without using tmp signal. Is it possible? The following doesn't work:

with buttons select
  error & code <= "000" when x"1",
                  "001" when x"2",
                  "010" when x"4",  
                  "011" when x"8",
                  "100" when others;
like image 545
rburny Avatar asked Mar 09 '13 18:03

rburny


People also ask

When else vs with select?

One important difference between the “with/select” and “when/else” assignment can be seen by comparing the conceptual implementation of these two statements. The "when/else" statement has a priority network; however, the “with/select” assignment avoids this chain structure and has a balanced structure.

What is signal assignment statement in VHDL?

The signal assignment statement is typically considered a concurrent statement rather than a sequential statement. It can be used as a sequential statement but has the side effect of obeying the general rules for when the target actually gets updated.


1 Answers

Instead of with select, you could use case:

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;
like image 63
TOTA Avatar answered Sep 27 '22 19:09

TOTA