JK Flip Flop Synthesis Verification
Legacy schematics and older digital design textbooks heavily feature JK flip-flops due to their versatility in building counters and state machines. However, modern standard cell libraries typically only provide D flip-flops. Synthesis tools like Yosys must map JK behavior into a standard D flip-flop preceded by multiplexers and combinational logic. A precise RTL implementation ensures the synthesizer can optimize this logic accurately into standard library cells.
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": [
{ "name": "clk", "wave": "p......" },
{ "name": "rst_n", "wave": "01....." },
{ "name": "j", "wave": "010011." },
{ "name": "k", "wave": "000111." },
{},
{ "name": "q", "wave": "0.1.010" }
], "head": { "text": "Cycle-by-cycle evaluation of JK flip-flop behavior." } }| 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 a real 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.