FPGA Center



CASE

It is used to select alternative processes according to possible values of a variable.

case (selective expression) is
      when  selection  =>
                 expressions;
      ..........................
      when others =>
                 expressions;
end case;


NOTE:


EXAMPLE 1:

P1:process
     variable x: Integer range 1 to 3;
     variable y: BIT_VECTOR (0 to 1);
     begin
          C1: case x is
                       when 1 => Out_1 <= 0;
                       when 2 => Out_1 <= 1;
                       when 3 => Out_1 <= 2;
                 end case C1;
         C2: case y is
                     when "00" => Out_2 <= 0;
                     when "01" => Out_2 <= 1;
                     when "10" => Out_2 <= 2;
                     when "11" => Out_2 <= 3;
                end case C2;
     end process;

EXAMPLE 2:


P2:process
      type Codes_Of_Operation is (ADD,SUB,MULT,DIV);
      variable Code_Variable: Codes_Of_Operation;
      begin
           C3: case Code_Variable is
                          when ADD | SUB => Operation := 0;
                          when MULT | DIV => Operation := 1;
                   end case C3;
      end process;

EXAMPLE 3:


P5:process
      variable Code_of_Operation : INTEGER range 0 to 2;
      constant Variable_1 : INTEGER := 0;
      begin
          C6: case Code_of_Operation is
                         when Variable_1 | Variable_1 + 1 => Operation := 0;
                         when Variable_1 + 2 =>   Operation := 1;
                  end case C6;
      end process;

                                                                                                           

    

                                                                                                                                    

 

                                                                                                                                                                                                                                                                   

Home | Fpga | VHDL | VHDL Dictionary | Digital Design | Simulation | PCB | Examples | Contact Us
Copyright © 2010 - 2013 FPGAcenter. All Rights Reserved.