Codiode

T Flip-Flop from a D Flip-Flop

EasyVerilog / SystemVerilogBuild

FPGAs only provide D flip-flops. A toggle flip-flop is a D flip-flop with a little feedback logic in front of it.

The circuit maintains its current state until the toggle enable signal is asserted. When enabled, the output state inverts on every active clock edge. This fundamental building block is heavily used in binary counters, clock dividers, and state machine design.

  • Clock edge: posedge
  • Reset type: asynchronous
  • Reset polarity: active-low (rst_n)
  • Output values on reset: q goes to 0
  • Priority rules: rst_n assertion overrides the t input
  • The output q must be registered

Cycle 1: rst_n=0, t=X → q=0 (reset)
Cycle 2: rst_n=1, t=0 → q=0 (hold)
Cycle 3: rst_n=1, t=1 → q=1 (toggle)
Cycle 4: rst_n=1, t=1 → q=0 (toggle)
Cycle 5: rst_n=1, t=0 → q=0 (hold)
Cycle 6: rst_n=1, t=1 → q=1 (toggle)
Cycle 7: rst_n=0, t=1 → q=0 (reset overrides toggle)
Cycle 8: rst_n=1, t=0 → q=0 (hold)

Signal Direction Width Description
clk input 1 Positive-edge triggered clock
rst_n input 1 Asynchronous active-low reset; q goes to 0 when asserted
t input 1 Toggle enable; q inverts on posedge clk while t is 1
q output 1 Registered output state

Constraints

  • Output q must be registered, updating only on the positive edge of clk or upon asynchronous reset.
  • The reset signal rst_n is asynchronous and active-low.
  • Output must initialise to 0 on reset.
  • Reset assertion strictly overrides the t input.

Topics

sequentialflip-flopfsm-basics

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Sequential RTL

Problem 19 of 26 in the Sequential RTL track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.