[systemverilog] first attempt
Viewer
- `timescale 1ns / 1ps
- // D-flip-flop using JK flip-flop
- module FlipFlopD(input logic D, clock, clear
- output logic q);
- always_ff @(negedge clock, posedge clear)
- if (clear)
- q <= 0;
- else
- case ({d, ~d})
- 2'b01: q <= 0;
- 2'b10: q <= 1;
- endcase
- endmodule
- c) (3 pt.) Write a test-bench for the D flip-flop that illustrates
- its behavior when input D takes values of 0 and 1, and for different
- current states of the flip-flop. The test-bench should use an initial
- pulse for the clear signal of the flip-flop to bring it into a
- well-defined state, as seen in class.
- module FlipFlopTest;
- logic d, clock, clear;
- logic q;
- FlipFlipD flip_flop(d, clock, clear, q);
- // 1) Initial pulse for 'clear'
- initial begin
- clear = 1;
- #5 clear = 0;
- end
- // 2) Clock signal
- initial begin
- clock = 1;
- forever #5 clock = ~clock;
- end
- // 3) Values for 'd'
- initial begin
- d = 0; // reset
- #10 d = 1; // set
- #10 $finish;
- end
- endmodule
Editor
You can edit this paste and save as new: