Know this topic? Give it a go. The lesson is here if you need it.
A conditional assignment chooses which value drives an output. It describes selection hardware that responds to its inputs, not a stored decision. This builds on concurrent assignments.
A fan must follow this temperature contract:
| Temperature in degrees Celsius | Speed code |
|---|---|
| Below 18 | 00, off |
| 18 through 24 | 01, slow |
| 25 through 34 | 10, medium |
| 35 or higher | 11, fast |
A candidate checks temperature >= 18 first and immediately selects slow when true.
Only otherwise does it check the higher thresholds.
Question 1 of 1
A simple sensor selector illustrates the syntax:
shown_o <= main_i when ok_i = '1' else backup_i;
Read when ... else as the condition selecting the preceding value or the following alternative.
This remains one concurrent assignment and one output driver.
Both inputs can exist at the same time. The selector is a multiplexer, often shortened to mux. No clock is needed for this combinational decision.
At 40 degrees, all three threshold conditions are true. The required highest speed must take priority.
speed_o <= "11" when temp_i >= 35 else
"10" when temp_i >= 25 else
"01" when temp_i >= 18 else
"00";
The first true condition supplies the result. Later conditions handle only inputs not already selected. Synthesis may optimize the logic; the required priority must remain the same.
The final fallback covers temperatures below every threshold.
Keep the unconditional final alternative. An incomplete combinational assignment can retain its previous output and infer storage.
Suppose a maintenance input must force the fan off even at 40 degrees. Would you check it before or after the temperature choices? The override must win over every matching threshold. This is a changed-spec design question, not an extra input in the shipped example.
The shared-pin recipe chooses between driving a value and releasing the pin:
line_io <= value_i when enable_i = '1' else 'Z';
Here Z means the driver releases the shared connection.
Real tri-state support depends on where that connection exists in the target device.
A comparison can also drive a flag:
over_o <= '1' when total_o > LIMIT else '0';
The conditional form converts the comparison's Boolean result into a logic value.
Open Fan Speed Selector in the example panel on the right.
Its fan_speed source implements the required threshold order.
Before reading each output, predict the codes at 24, 25, 34, and 35 degrees.
The waveform changes speed exactly at 25 and 35.
At 40, speed_o remains 11, despite all three comparisons being true.
Cooling back through 30, 20, and 10 gives medium, slow, then off. There is no memory of the previous higher speed.