Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VHDL Case/When: multiple cases, single clause

Tags:

case

vhdl

Inside a process I have something like this:

CASE res IS
  WHEN "00" => Y <= A;
  WHEN "01" => Y <= A;
  WHEN "10" => Y <= B;
  WHEN "11" => Y <= C;
  WHEN OTHERS => Y <= 'X';
END CASE;

Note that case "00" and "01" get the same value. Is there a correct syntax for something like

WHEN "00", "01" => ?

Extra note: There's far more to this than Y being changed, I just used that for simplicity. So the case/when is necessary.

like image 973
Jay Wick Avatar asked Sep 14 '10 08:09

Jay Wick


2 Answers

You can separate multiple choices with the "pipe" or bar symbol. The proper syntax for your example is:

CASE res IS
  WHEN "00" | "01" => Y <= A;
  WHEN "10" => Y <= B;
  WHEN "11" => Y <= C;
  WHEN OTHERS => Y <= 'X';
END CASE;
like image 174
Charles Steinkuehler Avatar answered Oct 24 '22 01:10

Charles Steinkuehler


You can also give a range of choices for a case:

USE IEEE.STD_LOGIC_ARITH.ALL;

CASE CONV_INTEGER(res) IS
  WHEN 0 to 1 => Y <= A;
  WHEN 2 => Y <= B;
  WHEN 3 => Y <= C;
  WHEN OTHERS => Y <= 'X';
END CASE;
like image 32
VahidG Avatar answered Oct 24 '22 00:10

VahidG