HDL & Digital Design Flow
Level 4 — Application (novel problems, no hints) Time limit: 60 minutes Total marks: 60
Question 1 — RTL Design & Blocking vs Non-blocking (14 marks)
A junior engineer writes the following Verilog intending to build a 3-stage shift register that shifts input din toward q_out on each rising clock edge:
module shifter (input clk, input din, output reg q_out);
reg a, b;
always @(posedge clk) begin
a = din;
b = a;
q_out = b;
end
endmodule(a) Explain precisely what hardware this code synthesises to, and why it does not produce a 3-stage shift register. (5)
(b) Rewrite the always block so it correctly implements a 3-stage shift register. State which assignment operator you use and justify the choice. (5)
(c) After your fix, if din follows the sequence 1,0,1,1,0 on five successive rising edges (all registers initially 0), give the value of q_out after each edge. (4)
Question 2 — Combinational Logic in HDL (12 marks)
You must describe a 4-to-1 multiplexer with a 2-bit select sel, four 1-bit data inputs d0..d3, and output y, using an always @(*) block and a case statement.
(a) Write synthesisable Verilog for this module. (6)
(b) A colleague omits the default case and only lists sel = 2'b00, 2'b01, 2'b10. Explain what unintended hardware this creates and why it is a bug even though sel is only 2 bits wide. (4)
(c) Rewrite the body as a single continuous-assignment (assign) statement using the conditional (?:) operator. (2)
Question 3 — Static Timing & Critical Path (16 marks)
A synchronous circuit has two flip-flops FF1 → (combinational logic) → FF2, both clocked by the same clock. The following parameters apply:
- Clock-to-Q delay () = 0.4 ns
- Combinational logic delay () = 3.1 ns
- Setup time () = 0.3 ns
- Hold time () = 0.2 ns
- Clock skew (arrives at FF2 later than FF1) = 0.25 ns
(a) Write the setup-timing inequality for this path and compute the minimum clock period and the corresponding maximum frequency. (6)
(b) State the hold-timing inequality for the fastest path. Using a minimum contamination delay through logic of 0.5 ns, determine whether the hold constraint is satisfied. Show the slack. (5)
(c) The design must run at 350 MHz. The current critical path fails. You may pipeline the combinational logic by splitting it into two balanced stages. Assuming the split is perfectly balanced and adds one FF with the same and , compute the new (ignore skew here) and confirm whether 350 MHz is now met. (5)
Question 4 — Testbench & Simulation (10 marks)
You are given a DUT with the interface:
module adder4 (input [3:0] a, input [3:0] b, output [4:0] sum);(a) Write a self-checking testbench that applies at least three test vectors, computes the expected result behaviourally, compares it to sum, and prints PASS/FAIL for each. Use $display and $finish. (7)
(b) Explain why a self-checking testbench is preferable to visually inspecting a waveform for a design that will later be regression-tested in CI. (3)
Question 5 — FPGA vs ASIC Flow & Synthesis (8 marks)
(a) A team prototypes an algorithm on an FPGA, then targets an ASIC for volume production. Give three concrete ways the design flow or the RTL itself may need to change when moving from FPGA to ASIC. (6)
(b) In one sentence each, define "synthesis" and "gate-level netlist". (2)
Answer keyMark scheme & solutions
Question 1 (14 marks)
(a) (5 marks)
The block uses blocking (=) assignments executed sequentially within one edge event.
a = din;→aimmediately becomesdin.b = a;→bimmediately becomes the newa=din.q_out = b;→q_outimmediately becomesdin.
So on each edge all three variables collapse to the current din. (2)
Synthesis: the tool sees that a and b are read only after being written in the same block, so they are optimised away; only one flip-flop (for q_out) remains. (2) It is therefore a single-register delay, not a 3-stage shift register. (1)
(b) (5 marks)
always @(posedge clk) begin
a <= din;
b <= a;
q_out <= b;
endUse non-blocking (<=). (2) Non-blocking assignments schedule all RHS evaluations using old values, then update simultaneously at the end of the time step, correctly modelling parallel flip-flops that each capture the previous stage's value. (2) This yields three cascaded registers → 3-stage shift register. (1)
(c) (4 marks) Pipeline (a,b,q_out), initial 0,0,0. din sequence 1,0,1,1,0.
| Edge | din | a | b | q_out |
|---|---|---|---|---|
| 1 | 1 | 1 | 0 | 0 |
| 2 | 0 | 0 | 1 | 0 |
| 3 | 1 | 1 | 0 | 1 |
| 4 | 1 | 1 | 1 | 0 |
| 5 | 0 | 0 | 1 | 1 |
q_out sequence = 0, 0, 1, 0, 1. (4; deduct 1 per error)
Question 2 (12 marks)
(a) (6 marks)
module mux4 (input d0, d1, d2, d3, input [1:0] sel, output reg y);
always @(*) begin
case (sel)
2'b00: y = d0;
2'b01: y = d1;
2'b10: y = d2;
2'b11: y = d3;
default: y = 1'b0;
endcase
end
endmoduleMarks: correct interface/reg output (1), always@(*) (1), case syntax (1), four correct mappings (2), default/completeness (1).
(b) (4 marks)
With one branch missing, y is not assigned for sel = 2'b11. In an always @(*) block, an unassigned variable retains its previous value, so the synthesiser infers a latch on y. (2) Even though sel is only 2 bits, 2'b11 is a legal, reachable value; the incomplete case is still not fully specified, producing an unintended level-sensitive latch — a common source of timing/glitch bugs. (2)
(c) (2 marks)
assign y = sel[1] ? (sel[0] ? d3 : d2) : (sel[0] ? d1 : d0);Question 3 (16 marks)
(a) (6 marks) Setup inequality (skew adds to available time on launch side / here skew delays capture clock, relaxing setup): (4) (2)
(b) (5 marks) Hold inequality (capture clock later by skew → tougher): LHS ns; RHS ns. (3) Slack ns → hold constraint satisfied. (2)
(c) (5 marks) Split logic into two balanced halves: each stage logic ns. New per-stage requirement (ignore skew): (3) Required 350 MHz → period 2.857 ns > 2.25 ns. 350 MHz is now met (with 0.607 ns slack). (2)
Question 4 (10 marks)
(a) (7 marks)
module tb_adder4;
reg [3:0] a, b;
wire [4:0] sum;
integer errors = 0;
adder4 dut (.a(a), .b(b), .sum(sum));
task check;
input [3:0] ta, tb;
reg [4:0] exp;
begin
a = ta; b = tb; #1;
exp = ta + tb;
if (sum === exp)
$display("PASS: %0d + %0d = %0d", ta, tb, sum);
else begin
$display("FAIL: %0d + %0d got %0d exp %0d", ta, tb, sum, exp);
errors = errors + 1;
end
end
endtask
initial begin
check(4'd3, 4'd5);
check(4'd15, 4'd15);
check(4'd0, 4'd9);
$display("Total errors = %0d", errors);
$finish;
end
endmoduleMarks: instantiation (1), ≥3 vectors (1), behavioural expected value (2), comparison + PASS/FAIL (2), $finish (1).
(b) (3 marks) Self-checking testbenches produce a machine-readable PASS/FAIL verdict, so they can run unattended in CI with no human waveform inspection (1); they scale to thousands of vectors and catch regressions automatically (1); and they give an objective, reproducible reference model rather than error-prone visual judgement (1).
Question 5 (8 marks)
(a) (6 marks) — any three, 2 each:
- Clocking/reset: FPGA uses dedicated global clock buffers and often async/vendor-specific reset; ASIC needs a custom clock tree, and synchronous reset strategy chosen for area/timing.
- Memory/IP mapping: FPGA block-RAM/DSP primitives must be replaced by ASIC RAM compilers / standard-cell macros.
- Timing closure: ASIC needs full physical synthesis, place-and-route, and sign-off STA with parasitic extraction, whereas FPGA timing is bounded by fixed fabric.
- Design-for-test: ASIC requires scan-chain/BIST insertion not needed on FPGA.
- Power/area optimisation: ASIC allows and demands gate-level/library-specific optimisation, multi-Vt cells, etc.
(b) (2 marks)
- Synthesis: the process that translates RTL (behavioural HDL) into a network of logic gates/flip-flops from a target technology library. (1)
- Gate-level netlist: a structural description listing the actual library cells and their interconnections that implement the design. (1)
[
{"claim":"Q3a Tmin = tcq+tlogic+tsu-skew = 3.55 ns","code":"Tmin=0.4+3.1+0.3-0.25; result=abs(Tmin-3.55)<1e-9"},
{"claim":"Q3a fmax approx 281.7 MHz","code":"f=1/(3.55e-9); result=abs(f-281.69e6)<1e5"},
{"claim":"Q3b hold slack = 0.45 ns positive","code":"slack=(0.4+0.5)-(0.2+0.25); result=abs(slack-0.45)<1e-9 and slack>0"},
{"claim":"Q3c pipelined Tmin=2.25 ns meets 350MHz (2.857 ns period)","code":"Tmin=0.4+3.1/2+0.3; result=abs(Tmin-2.25)<1e-9 and Tmin<(1/350e6)*1e9"}
]