Consider this Verilog testbench snippet that models a simple flip-flop with a clock and asynchronous reset. What will be the value of q after 25 time units?
module dff(input clk, input rst_n, input d, output reg q); always @(posedge clk or negedge rst_n) begin if (!rst_n) q <= 0; else q <= d; end endmodule module test; reg clk = 0; reg rst_n = 0; reg d = 0; wire q; dff uut(clk, rst_n, d, q); always #5 clk = ~clk; initial begin #10 rst_n = 1; d = 1; #10 d = 0; #10 $display("q = %b", q); $finish; end endmodule
Think about when the flip-flop samples the input d relative to the clock edges and reset.
The flip-flop resets q to 0 initially. Clock posedges occur at 5, 15, 25, etc. After 10 time units, reset is released and d is set to 1. At 15 units, q captures d=1. At 20 units, d=0. At 25 units (posedge clk), q captures d=0, so q = 0 after 25 time units.
Which of the following best explains the importance of setup time in digital design?
Think about what happens if data changes exactly at the clock edge.
Setup time is the minimum time before the clock edge that data must be stable to be reliably captured by flip-flops. Violating setup time can cause metastability and incorrect outputs.
This Verilog code models a simple counter. However, it sometimes produces incorrect counts. What timing-related problem is most likely causing this?
module counter(input clk, input rst_n, output reg [3:0] count); always @(posedge clk or negedge rst_n) begin if (!rst_n) count <= 0; else count <= count + 1; end endmodule
Consider the effect of asynchronous reset on timing and metastability.
Asynchronous reset can cause metastability if deasserted close to the clock edge. This can cause unpredictable counter values. Proper synchronization or synchronous reset avoids this.
Select the code snippet that implements a synchronous reset for a flip-flop.
Synchronous reset happens only on the clock edge.
Option B triggers only on the clock's positive edge and resets q if rst_n is low, making reset synchronous. Others use asynchronous reset or incorrect sensitivity lists.
A digital circuit has a combinational logic delay of 8 ns and a flip-flop setup time of 2 ns. The clock-to-Q delay of the flip-flop is 3 ns. What is the maximum clock frequency the circuit can safely run at?
Use the formula: Clock period ≥ Clock-to-Q delay + Combinational delay + Setup time.
The minimum clock period = 3 ns + 8 ns + 2 ns = 13 ns. Maximum frequency ≈ 76.9 MHz. Among the options, 71.4 MHz (period ≈14 ns) is the highest frequency that safely satisfies the timing constraint (period ≥ 13 ns).
