Challenge - 5 Problems
Setup and Hold Time Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateSetup time violation detection in flip-flop timing
Consider a D flip-flop with a clock period of 10ns, setup time of 2ns, and data arrival at 9ns after the clock edge. What will be the output Q after the clock edge?
Verilog
module test; reg clk, d; wire q; reg [3:0] time; initial begin clk = 0; d = 0; time = 0; forever #5 clk = ~clk; // 10ns clock period end always @(posedge clk) begin $display($time, ": Clock edge detected, Q = %b", q); end always @(time) begin if (time == 9) d = 1; // data changes at 9ns end always #1 time = time + 1; dff my_dff(.clk(clk), .d(d), .q(q)); initial #30 $finish; endmodule module dff(input clk, input d, output reg q); always @(posedge clk) begin q <= d; end endmodule
Attempts:
2 left
💡 Hint
Setup time means data must be stable before the clock edge by a certain time.
✗ Incorrect
Since data changes at 9ns and clock edge is at 10ns, data is only stable 1ns before clock edge, less than the 2ns setup time. This causes a setup time violation, so Q does not update to new data.
❓ Predict Output
intermediateHold time violation effect on flip-flop output
A D flip-flop has a hold time of 1ns. If data changes exactly at the clock edge, what is the expected behavior of the output Q?
Verilog
module test;
reg clk, d;
wire q;
initial begin
clk = 0;
d = 0;
#5 d = 1; // data changes at 5ns
#5 $finish;
end
always #5 clk = ~clk; // 10ns clock period
dff my_dff(.clk(clk), .d(d), .q(q));
always @(posedge clk) begin
$display($time, ": Clock edge, Q = %b", q);
end
endmodule
module dff(input clk, input d, output reg q);
always @(posedge clk) begin
q <= d;
end
endmoduleAttempts:
2 left
💡 Hint
Hold time means data must remain stable after the clock edge for a certain time.
✗ Incorrect
Data changes exactly at clock edge, violating the 1ns hold time requirement. This can cause metastability or unpredictable output.
🧠 Conceptual
advancedUnderstanding setup and hold time constraints
Which statement correctly describes the relationship between setup time and hold time in synchronous circuits?
Attempts:
2 left
💡 Hint
Think about when data must be stable relative to the clock edge.
✗ Incorrect
Setup time requires data to be stable before the clock edge; hold time requires data to remain stable after the clock edge to ensure correct sampling.
📝 Syntax
advancedIdentify the timing constraint violation in Verilog code
Given the following Verilog snippet, which timing violation is most likely to occur?
Verilog
module dff(input clk, input d, output reg q); always @(posedge clk) begin q <= d; end endmodule module test; reg clk = 0; reg d = 0; wire q; dff ff(.clk(clk), .d(d), .q(q)); always #5 clk = ~clk; // 10ns clock initial begin d = 1; // data changes at time 0 #9 d = 0; // data changes 9ns after clock edge #10 $finish; end always @(posedge clk) $display($time, ": Q = %b", q); endmodule
Attempts:
2 left
💡 Hint
Check when data changes relative to clock edges.
✗ Incorrect
Data changes 9ns after clock edge, but clock period is 10ns, so next clock edge is at 10ns. Data changes only 1ns before next clock edge, violating setup time for next cycle. But for current cycle, data changes 9ns after clock edge, which is less than hold time of 1ns, so hold time violation is more likely.
🚀 Application
expertCalculate maximum clock frequency considering setup and hold times
A synchronous system has a flip-flop with setup time = 2ns, hold time = 1ns, and combinational logic delay = 5ns. What is the maximum clock frequency that avoids setup and hold time violations?
Attempts:
2 left
💡 Hint
Maximum clock frequency = 1 / (setup time + logic delay). Hold time is usually smaller and affects minimum delay, but setup time + logic delay limits max frequency.
✗ Incorrect
Maximum clock period = setup time + logic delay = 2ns + 5ns = 7ns. Frequency = 1 / 7ns = approx 142.857 MHz. But hold time requires minimum delay after clock edge, so minimum clock period must be larger than hold time. The limiting factor is setup time + logic delay, so max frequency is about 142.857 MHz. However, to be safe and considering hold time constraints, the practical max frequency is lower. Given options, 83.33 MHz corresponds to 12ns period, which safely covers timing constraints.
