Challenge - 5 Problems
Latch Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output behavior of this VHDL process?
Consider the following VHDL process. What will be the inferred hardware behavior when this code is synthesized?
VHDL
process(clk) begin if rising_edge(clk) then if enable = '1' then q <= d; end if; end if; end process;
Attempts:
2 left
💡 Hint
Think about whether q is assigned in all clock cycles.
✗ Incorrect
Since q is assigned only inside the rising_edge(clk) and only when enable = '1', but q retains its previous value otherwise, this is a flip-flop with enable control. No latch is inferred because the assignment happens only on clock edges.
❓ Predict Output
intermediateWhat error does this VHDL code cause during synthesis?
Analyze this VHDL process and determine what kind of hardware or synthesis issue it will cause.
VHDL
process(a, b) begin if a = '1' then y <= '1'; end if; end process;
Attempts:
2 left
💡 Hint
Check if y is assigned in all possible conditions.
✗ Incorrect
Because y is assigned only when a = '1' and not assigned otherwise, the synthesizer infers a latch to hold the previous value of y when a = '0'.
🔧 Debug
advancedIdentify the cause of unintended latch inference in this code
This VHDL process unintentionally infers a latch. Which line or condition causes this?
VHDL
process(sel, in1, in2) begin if sel = '0' then outp <= in1; elsif sel = '1' then outp <= in2; end if; end process;
Attempts:
2 left
💡 Hint
Think about what happens if sel has an unexpected value.
✗ Incorrect
If sel is neither '0' nor '1', outp is not assigned any new value, so the synthesizer infers a latch to hold the previous value. Adding an else clause assigning outp fixes this.
📝 Syntax
advancedWhich option correctly avoids unintended latch inference?
Choose the VHDL process code that avoids unintended latch inference by ensuring all outputs are assigned in all conditions.
Attempts:
2 left
💡 Hint
Make sure y is assigned in every possible condition.
✗ Incorrect
Option B assigns y in both if and else branches, so no latch is inferred. Other options miss assignments in some conditions, causing latch inference.
🚀 Application
expertHow many latches are inferred by this VHDL code?
Analyze the following VHDL process and determine how many latches will be inferred during synthesis.
VHDL
process(sel, a, b, c) begin if sel = "00" then outp <= a; elsif sel = "01" then outp <= b; elsif sel = "10" then outp <= c; end if; end process;
Attempts:
2 left
💡 Hint
Check if outp is assigned for all possible sel values.
✗ Incorrect
Since sel can be "11" and outp is not assigned in that case, a latch is inferred to hold the previous value of outp.
