Turn D flip-flops into an enabled T flip-flop and a JK flip-flop with a clear, using logic in front of D.
Hardware context: An old counter drawn with T and JK flip-flops, ported to a cell library that has only D flip-flops. Build an enabled T flip-flop and a JK flip-flop with an asynchronous clear from D flip-flops.
A cell library has only D flip-flops, but an old counter design was drawn with a T flip-flop and a JK flip-flop. To port it, each must be rebuilt as a D flip-flop with the right logic in front of its D input.
This is an Implement problem. Complete tjk. The starter clocks t and j straight into D, which is wrong. The T flip-flop also has an enable: it acts only while en = 1. A low pulse on clr_n clears both at once, without a clock edge.
The check makes eight rising edges per case, with some clear pulses between them, and compares qt and qjk with a model. The design must synthesize with no latches.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
script | 40 | input of each check |
Full specification
module tjk (
input logic clk,
input logic clr_n, // asynchronous clear, active low: both flip-flops to 0 at once
input logic en, // the T flip-flop acts only while en = 1
input logic t, // T flip-flop: toggle when 1, hold when 0
input logic j, k, // JK flip-flop: 10 set, 01 reset, 11 toggle, 00 hold
output logic qt,
output logic qjk
);
...
endmodule
| Flip-flop | Inputs at the edge | Next state Q+ |
|---|---|---|
| T | en = 0, or t = 0 | Q (hold) |
| T | en = 1 and t = 1 | Q' (toggle) |
| JK | j k = 00 | Q (hold) |
| JK | j k = 01 | 0 (reset) |
| JK | j k = 10 | 1 (set) |
| JK | j k = 11 | Q' (toggle) |
clr_n = 0 clears both flip-flops at once, between edges. Each case starts with a clear. After a clear pulse the result also records both outputs, which must read 0.
Examples
Example 1
T: Toggle, Hold, Toggle- Input
clear, en1 t1 jk00; en1 t0 jk00; en1 t1 jk00; en1 t1 jk00; en1 t0 jk00; en1 t1 jk00; en0 t1 jk00; en0 t1 jk00
- Output
qt_edge0 = yes, qjk_edge0 = no, qt_edge1 = yes, qjk_edge1 = no, qt_edge2 = no, qjk_edge2 = no, qt_edge3 = yes, qjk_edge3 = no, qt_edge4 = yes, qjk_edge4 = no, qt_edge5 = no, qjk_edge5 = no, qt_edge6 = no, qjk_edge6 = no, qt_edge7 = no, qjk_edge7 = no
After the clear, each edge with en = 1 and t = 1 inverts qt; t = 0 holds it, and so does en = 0. j and k stay 0, so qjk holds 0.
Example 2
JK: Set, Hold, Reset, Hold- Input
clear, en0 t0 jk10; en0 t0 jk00; en0 t0 jk01; en0 t0 jk00; en0 t0 jk10; en0 t0 jk10; en0 t0 jk01; en0 t0 jk00
- Output
qt_edge0 = no, qjk_edge0 = yes, qt_edge1 = no, qjk_edge1 = yes, qt_edge2 = no, qjk_edge2 = no, qt_edge3 = no, qjk_edge3 = no, qt_edge4 = no, qjk_edge4 = yes, qt_edge5 = no, qjk_edge5 = yes, qt_edge6 = no, qjk_edge6 = no, qt_edge7 = no, qjk_edge7 = no
jk = 10 sets qjk, 00 holds it, 01 resets it. A second 10 while qjk is already 1 keeps it at 1.
Example 3
JK: Toggle Four Times- Input
clear, en0 t0 jk11; en0 t0 jk11; en0 t0 jk11; en0 t0 jk11; en0 t0 jk00; en0 t0 jk11; en0 t0 jk00; en0 t0 jk00
- Output
qt_edge0 = no, qjk_edge0 = yes, qt_edge1 = no, qjk_edge1 = no, qt_edge2 = no, qjk_edge2 = yes, qt_edge3 = no, qjk_edge3 = no, qt_edge4 = no, qjk_edge4 = no, qt_edge5 = no, qjk_edge5 = yes, qt_edge6 = no, qjk_edge6 = yes, qt_edge7 = no, qjk_edge7 = yes
With jk = 11 every edge inverts qjk: 1, 0, 1, 0. Then 00 holds, and one more 11 toggles to 1.
Constraints and Contract
- All inputs are known 0/1 values and change only between edges.
- Keep the module name and the ports.
Hints
Hint 1
A D flip-flop stores D, so D must be the next state you want. Write Q+ for each flip-flop as an equation in its inputs and its own Q.
Hint 2
For T: hold unless both en and t are 1, and invert then. One AND and one XOR do exactly that.
Hint 3
For JK: Q+ = JQ' + K'Q. For the clear, put negedge clr_n in the sensitivity list and test it first.
What the grader checks: Four directed and twelve seeded scripts of eight rising edges, some with clear pulses between edges. After each edge and each clear, qt and qjk are compared with a JavaScript model of the characteristic equations. Synthesis must report no latches.
The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.
16 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone