P5-35 正緣觸發JK Flip-Flop
module jk_ff(Reset,Clock,J,K,Q,Qbar); // dataflow style
input Reset;
input J,K,Clock;
output Q,Qbar;
reg Q;
wire Qn; // the next state Qn
always @(posedge Clock) begin
if (!Reset) // synchronous reset, active low
Q <= 1'b0;
else
Q <= Qn; // assign the next state
end // always
assign Qn = J & ~Q | ~K & Q; // characteristic equation of JK FF
assign Qbar = ~Q;
endmodule
//test bench//
`timescale 1 ns/1 ps
module jk_test();
reg j,k,clk,reset;
wire q,qn;
// module jk_ff(Reset,Clock,J,K,Q,Qbar);
jk_ff f1(.Reset(reset),.
Q(q),
.Qbar(qn),
.J(j),
.K(k),
.Clock(clk));
initial
begin
$display("time,\t q,\t qn,\t j,\t k,\t clk,\t reset");
$monitor("%g,\t %b,\t %b,\t %b,\t %b,\t %b,\t %b",$time,q,qn,j,k,clk,reset);
clk=1'b0;
reset=1'b0;
#5 reset=1'b1;
#10 {j,k}=2'b00;
#20 {j,k}=2'b01;
#30 {j,k}=2'b10;
#40 {j,k}=2'b11;
end
always #10 clk=~clk;
initial
#200 $stop;
endmodule
沒有留言:
張貼留言