Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 37 ยท Concurrent and Sequential Code

Concurrent Signal Assignments

Describe combinational logic in VHDL with concurrent assignments: simple, conditional when/else and selected with/select assignments, multiplexers, decoders and priority logic.

Statements that sit directly in the architecture body, outside any process, are concurrent. They all run in parallel and re-evaluate whenever one of their inputs changes. Three forms of concurrent signal assignment cover most combinational logic: the simple assignment, the conditional assignment (when ... else) and the selected assignment (with ... select).

Simple assignment

VHDL
y     <= a and b;
carry <= (a and b) or (cin and (a xor b));
sum   <= a xor b xor cin;

An optional after clause adds a delay in simulation (y <= a and b after 2 ns;), which is ignored by synthesis and used only in models.

Conditional assignment: when ... else

VHDL
y <= a when sel = '0' else
     b;

The conditions are tested in order, so earlier ones have priority. With three or more branches this describes a priority chain:

VHDL
grant <= "001" when req(0) = '1' else
         "010" when req(1) = '1' else
         "100" when req(2) = '1' else
         "000";

Here req(0) wins over req(1), and req(1) over req(2). The final else is required: without it the signal would have to remember its old value, which would infer a latch (a memory element you did not want). In concurrent code, a signal must always be assigned in every case.

Selected assignment: with ... select

When one expression chooses among many fixed values, with ... select is clearer and has no priority:

VHDL
with sel select
  y <= a when "00",
       b when "01",
       c when "10",
       d when others;

Every possible value of sel must be covered; others is the safety net and is mandatory when the cases do not list every value (and for std_logic they never do: 'U', 'X' and so on also exist). VHDL-2008 offers with sel select? for matching with don't-cares, and allows when/else and case forms to appear in more places.

Multiplexers and decoders

A 4-to-1 multiplexer with with ... select is shown above. A 2-to-4 decoder (one-hot output) is similarly short:

VHDL
with addr select
  cs <= "0001" when "00",
        "0010" when "01",
        "0100" when "10",
        "1000" when others;

Compare the three forms:

Form Reads like Priority? Typical use
Simple <= an equation โ€“ Gates, arithmetic
when ... else if / elsif / else Yes Priority encoders, defaults
with ... select case No Multiplexers, decoders, look-up tables

Stand-ins in C

The first stand-in models a 4-to-1 multiplexer and a priority arbiter, the two shapes you will build most often. Note how the priority chain returns on the first match while the selected form indexes by value.

C Stand-in (C): mux (select) and priority (when/else)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

A seven-segment decoder

A seven-segment display is a classic use of with ... select: a 4-bit digit goes in and seven segment lines come out. In VHDL it is a table:

VHDL
with digit select
  seg <= "1111110" when x"0",   -- segments a b c d e f g
         "0110000" when x"1",
         "1101101" when x"2",
         "1111001" when x"3",
         "0110011" when x"4",
         "1011011" when x"5",
         "1011111" when x"6",
         "1110000" when x"7",
         "1111111" when x"8",
         "1111011" when x"9",
         "0000000" when others;

The C stand-in prints the digits on a text display, using the same table, so you can see the decoded pattern.

C Stand-in (C): seven-segment decoder

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Avoiding accidental latches

In concurrent code, when ... else without a final else is an error. In a process (next lesson) a missing branch compiles and creates a latch. The rule for combinational logic is the same everywhere: every path must assign every output.

Seeing latches in a synthesis report for logic you meant to be combinational is a warning sign. Check for missing else branches and case choices.

Use with ... select for table-like selection and when ... else only when priority matters or the conditions are not simple comparisons of one expression. Simulators and synthesizers produce the same hardware for equivalent code, so choose for readability.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What kind of logic does y <= a when sel = '0' else b; describe?

    The output follows a or b depending on sel, which is a multiplexer.
  2. 2. In with s select y <= a when "00", b when "01"; what is missing?

    Every value of the selector must be covered; others handles the rest, including non-0/1 std_logic values.
  3. 3. Which concurrent form implies priority between conditions?

    Conditions in when/else are tested in order, so earlier conditions take priority.
  4. 4. Why must a concurrent when ... else end with a plain else value?

    A signal must be driven in all cases, otherwise memory would be implied; the compiler rejects it in concurrent code.

Summary

  • Concurrent statements live in the architecture body and run in parallel.
  • Use simple assignments for equations, when ... else for priority, with ... select for table-like selection.
  • Always cover every case; others and a final else prevent latches and compile errors.
  • Equivalent descriptions synthesize to the same hardware; pick the clearest one.

Next: Processes and Sensitivity Lists