EmbDev.net

Forum: FPGA, VHDL & Verilog Case Statement outside Process Block


Author: Rejoy Mathews (Company: Lab Instructor) (rejoymathews32)
Posted on:

Rate this post
0 useful
not useful
case sel is
when '0' => o <= i(0);
when '1' => o <= i(1);
when others => o <= 'U';
end case;

The above case statement when put outside a process block gives a syntax 
error and I am forced to put the case statement inside a process block 
although I do not feel the need to do the same.

Can anyone explain what is the restriction that VHDL is imposing because 
of which I am forced to define the case statement within the process 
block.

Thanks in advance.

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
1 useful
not useful
Rejoy M. wrote:
> Can anyone explain what is the restriction that VHDL is imposing because
> of which I am forced to define the case statement within the process
> block.
There are different syntax elements to do such things outside an 
process. Read about "concurrent assignments" (=without process) vs. 
"sequential statements" (=inside a process).

sequential coding:
process (i) begin
  case sel is
    when '0' => o <= i(0);
    when '1' => o <= i(1);
    when others => o <= 'U';
  end case;
end process;

concurrent coding:
o <= i(0) when sel='0' else
     i(1) when sel='1' else
     'U';

Author: Markus F. (mfro)
Posted on:

Rate this post
1 useful
not useful
Rejoy M. wrote:
> Can anyone explain what is the restriction that VHDL is imposing because
> of which I am forced to define the case statement within the process
> block.

The (rather unsatisfying but correct) answer is probably: because that's 
the way it is. You might as well ask why there is no concurrent "if" 
statement. I would assume language designers did it this way to make it 
clear to the coder that there are significant differences between 
sequential and concurrent and allowed only one-liners for the latter.

Maybe the "selected concurrent signal assignment" is what you are 
looking for. Although kind of backwards, it's basically the same thing:
with selector select
    target <= value1 when choice1,
    target <= value2 when choice2,
    target <= default_value when others;

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig