module jk_ff_enable (
input CLK,
input EN,
input J,
input K,
output reg Q
);
always @(posedge CLK) begin
if (EN) begin
case ({J, K})
2'b00: Q <= Q; // hold
2'b01: Q <= 1'b0; // reset
2'b10: Q <= 1'b1; // set
default: Q <= ~Q; // toggle
endcase
end
end
endmodule
💡Remember
EN masks the JK function; when low, the state is retained regardless of J/K.- Synthesizers usually implement JK as logic feeding a D flip-flop; writing it directly with a clocked
case is clear and portable. - Nonblocking assignments (
<=) ensure the toggle uses the pre-edge value of Q and avoid races across sequential paths.