Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

when use 'else' and when use ; ?

Hi.. I am starter in VHDl.

I have some questions...

What is difference between else and ;?

first code use else but when i use ';' instead of 'else' it doesn't work.

Do you know why?

and second question is

first code is about 'priority encoder' (priority means that when input comes, the highest input come out to the output. for example .. when inputs are 6 and 5.. the output is only "110" ,not "111"(<= 110 or 101)

I learned that the VHDL process the code in parallel unless we don't use 'process statement '

But I don't use 'process statement' in first code, but I think the first code look like being processed in sequential. The reason why I think is when i test the code in Model_sim, I gave input i(6) and i(5) the same clock. and the output is only110, not 111. I think this means the code was processed in sequential even though i don't use 'process statement'

what's happening?

(1)

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY encoder is

PORT(

i :IN std_logic_vector(7 downto 0);

a : OUT std_logic_vector(2 downto 0));

END encoder;

ARCHITECTURE arc of encoder is

BEGIN

a<= "111" when i(7) ='1' else

"110" when i(6) = '1' else

"101" when i(5) = '1' else

"100" when i(4) = '1' else

"011" when i(3)= '1' else

"010" when i(2)= '1'else

"001" when i(1)= '1' else

"000" when i(0)= '1' else

"000";

END ARC;

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    if you put this ; at end it implies end of statement and then you have to repeat that for each value which means drive the signal (a) with different values (multiple drivers) but compiler needs to understand one value to drive (a). If you have multiple drivers then you must have logic to make the compiler understand how to apply each case (priority).

    Priority can be either in a process(if else) or outside process e.g. when else as you have done.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Your assignment to a is done outside a process, so imagine that it happens (nearly) instantly. (instead of conditionally).

    The assignment to a is using more of a priority list to determine your output. If i(7) = '1', it doesn't matter what 6-0 are, your output will be "111". If i(7)=0, then i(6) is examined next. If you re-wrote your statement as:

    a<="000" when i(0) = '1' else

    "001" when i(1) = '1' else

    ..

    "111" when i(7) = '1' else

    "000";

    then i(0) = '1' would take priority over all others.