Week 2 · Day 7 · 7 hours

Verilog RTL I – Combinational

Combinational, arithmetic, sequential, counters, timers

Daily plan

What you will learn and practise

Complete the stages in order and retain the requested evidence.

Theory · 2h

always blocks and blocking assignment
if/else, case/casez/casex
Complete assignments and latch avoidance
Combinational coding guidelines

Guided lab · 2h

1. 2:1 MUX with assign
2. 2:1 MUX with if
3. 2:1 MUX with case
4. 4:1/8:1 MUX
5. Decoder/DEMUX

Independent lab · 2h

6. Encoder/priority encoder
7. Binary↔one-hot
8. Min/max selector
9. Leading-one/zero detector
10. Population counter
11. Parameterized MUX

Debug and assignment · 1h

Debug missing default, incomplete assignment, bad slicing
Explain why each faulty block infers wrong hardware

Expected deliverable

Combinational RTL library

Practical work

Implement complete combinational RTL with assign, if/else and case while preventing unintended latches.

Setup
  1. Create project_workspace/week2_verilog_rtl1/day7.
  2. Reuse the Day 6 simulation flow.
  3. Enable compiler/lint warnings and retain the log.
Execution steps
  1. Implement 2:1 MUX using assign, if/else and case.
  2. Implement 4:1 and 8:1 MUX blocks.
  3. Implement decoder and demultiplexer.
  4. Implement encoder and priority encoder.
  5. Implement binary-to-one-hot and one-hot-to-binary conversion.
  6. Implement min/max selector, leading-one/zero detector and population counter.
  7. Create a parameterized MUX and verify representative select/input combinations.
Written assignment
  1. Compare continuous assignment with a combinational always block.
  2. Why are blocking assignments normally used in combinational procedural RTL?
  3. Explain how an incomplete if/case assignment can infer a latch.
  4. State the purpose of a default case and when it is required for clear intent.
  5. Explain priority behavior in a priority encoder and how it differs from an ordinary encoder.
Debug challenge

Correct missing defaults, incomplete output assignments and bad vector slicing in faulty combinational blocks; state what hardware the faulty version could infer.

Evidence to retain
  • combinational RTL library
  • testbench/results
  • warning-clean compile log
  • debug-before/after notes
  • written answers
Completion criteria
  • No unintended latch behavior
  • Outputs are assigned for all intended input conditions
  • Parameterized MUX verifies correctly
  • Debug explanation connects source defect to hardware behavior
Executable lab

Build, run and retain evidence

project_workspace/week2_verilog_rtl1/day7_combinational/

Required files
  • rtl/mux2_assign.v
  • rtl/mux2_if.v
  • rtl/mux2_case.v
  • rtl/mux_n.v
  • rtl/decoder.v
  • rtl/demux.v
  • rtl/priority_encoder.v
  • rtl/onehot.v
  • rtl/popcount.v
  • tb/tb_day7.v
Mandatory tests
  • Every MUX select value
  • Decoder/DEMUX legal selections
  • Priority encoder multiple-active-input cases
  • Binary/one-hot conversion cases
  • Population count 0, all-ones and mixed patterns
  • Parameterized MUX at two configurations
Compile
iverilog -g2012 -Wall -o sim/day7.vvp rtl/*.v tb/tb_day7.v
Run
vvp sim/day7.vvp | tee logs/day7.log
Waveform
gtkwave sim/day7.vcd
PASS criteria
  • All combinational checks PASS
  • No unintended latch behavior in reviewed RTL
  • No compile errors
  • Log and VCD retained
Knowledge check

Review before completing Day 7

  1. MCQ

    What coding defect commonly causes unintended latch inference?

    Review answer

    An output is not assigned on every combinational path.

  2. Code reading

    In an always @(*) MUX, why are blocking assignments normally used?

    Review answer

    They model ordered combinational calculation without clocked-state semantics.

  3. Debug

    A case statement assigns y in three branches but not the fourth and has no default. What is the risk?

    Review answer

    y may retain its old value, implying a latch.

  4. Short answer

    Differentiate an ordinary encoder from a priority encoder.

    Review answer

    A priority encoder defines which asserted input wins when multiple inputs are active.

Skills and assessment traceability

Combinational RTL

  • always combinational
  • if/case
  • complete assignment
  • MUX/decoder/encoder
  • latch avoidance

Assessment: Q2