JK Flip-Flop
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:
qbecomes 0 immediately whenrst_nis 0 - Priority rules: Asynchronous reset takes highest priority;
jandkinputs are only evaluated on the positive clock edge whenrst_nis 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
qmust be registered on the positive edge ofclk. - Reset
rst_nmust be asynchronous and active-low. - When
rst_nis 0,qmust immediately become 0 regardless of the clock. - Both
jandkbeing 1 must result inqinverting its previous state.
Topics
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