Codiode

JK Flip-Flop

MediumVerilog / SystemVerilogBuild

Textbooks still use JK flip-flops; standard cell libraries don't have them. Synthesis builds one from a D flip-flop and the next-state logic you describe.

A JK flip-flop updates its output state based on the values of the j and k inputs. When both inputs are low, the output holds its current value. When j is high and k is low, the output sets to 1. When k is high and j is low, the output clears to 0. When both inputs are high, the output toggles its state, inverting the previous value.

  • Clock edge: posedge clk
  • Reset type: asynchronous
  • Reset polarity: active-low (rst_n)
  • Output values on reset: q becomes 0 immediately when rst_n is 0
  • Priority rules: Asynchronous reset takes highest priority; j and k inputs are only evaluated on the positive clock edge when rst_n is 1.

Cycle 1: rst_n=0 -> q=0
Cycle 2: rst_n=1, j=1, k=0 -> q=1 (Set)
Cycle 3: rst_n=1, j=0, k=0 -> q=1 (Hold)
Cycle 4: rst_n=1, j=0, k=1 -> q=0 (Reset)
Cycle 5: rst_n=1, j=1, k=1 -> q=1 (Toggle)
Cycle 6: rst_n=1, j=1, k=1 -> q=0 (Toggle)

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
j input 1 Set/Toggle input; evaluated on posedge clk
k input 1 Reset/Toggle input; evaluated on posedge clk
q output 1 Registered output state; resets to 0

Constraints

  • Output q must be registered on the positive edge of clk.
  • Reset rst_n must be asynchronous and active-low.
  • When rst_n is 0, q must immediately become 0 regardless of the clock.
  • Both j and k being 1 must result in q inverting its previous state.

Topics

SequentialFlip-FlopState Logic

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 20 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.