0
0
Verilogprogramming~20 mins

D flip-flop with clock edge in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
D Flip-Flop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of D flip-flop on rising clock edge

What is the output q after the rising edge of the clock in this D flip-flop module?

Verilog
module dff(input wire clk, input wire d, output reg q);
  always @(posedge clk) begin
    q <= d;
  end
endmodule

// Initial state: q = 0
// Inputs: clk rising edge, d = 1
// What is q after the clock edge?
Aq = 1
Bq = 0
Cq toggles
Dq holds previous value
Attempts:
2 left
💡 Hint

Remember, on the rising edge of the clock, the flip-flop captures the value of d.

Predict Output
intermediate
2:00remaining
Behavior of D flip-flop with asynchronous reset

Given this D flip-flop with asynchronous reset, what is the output q after reset is asserted low?

Verilog
module dff_async_reset(input wire clk, input wire reset, input wire d, output reg q);
  always @(posedge clk or negedge reset) begin
    if (!reset)
      q <= 0;
    else
      q <= d;
  end
endmodule

// Initial q unknown
// reset = 0 (asserted), d = 1
// What is q?
Aq toggles
Bq = 0
Cq holds previous value
Dq = 1
Attempts:
2 left
💡 Hint

Asynchronous reset forces q to 0 immediately when reset is low.

🔧 Debug
advanced
2:00remaining
Identify the error in this D flip-flop code

What error will this D flip-flop code cause when synthesized?

Verilog
module dff_error(input wire clk, input wire d, output reg q);
  always @(clk) begin
    if (clk == 1)
      q <= d;
  end
endmodule
AIt causes a syntax error due to missing posedge
BIt causes a runtime error
CIt synthesizes correctly as a flip-flop
DIt creates a latch instead of a flip-flop
Attempts:
2 left
💡 Hint

Check the sensitivity list and how the clock is used.

📝 Syntax
advanced
2:00remaining
Syntax error in D flip-flop declaration

Which option contains a syntax error in this D flip-flop module?

Verilog
module dff_syntax(input wire clk, input wire d, output reg q);
  always @(posedge clk) begin
    q <= d;
  end
endmodule
Amodule dff(input clk, input d, output reg q) always @(posedge clk) q <= d; endmodule
Bmodule dff(input wire clk, input wire d, output reg q); always @(posedge clk) q <= d; endmodule
Cmodule dff(input wire clk, input wire d, output reg q); always @(posedge clk) begin q <= d; end endmodule
Deludomdne dne ;d =< q nigeb )klc egdesop(@ syawla ;)q ger tuptuo ,d eriw tupni ,klc eriw tupni(ffd eludom
Attempts:
2 left
💡 Hint

Look for missing semicolons and missing begin/end blocks.

🚀 Application
expert
3:00remaining
Number of clock cycles for output change in D flip-flop chain

Consider a chain of three D flip-flops connected in series, each clocked by the same clock signal. If the input d to the first flip-flop changes at clock cycle 0, after how many clock cycles will the output of the third flip-flop reflect this change?

A1 clock cycle
B2 clock cycles
C3 clock cycles
D4 clock cycles
Attempts:
2 left
💡 Hint

Each flip-flop updates its output on the rising edge of the clock, passing the value to the next flip-flop on the next clock cycle.