I'm trying to simulate the working of t-flipflop.
`timescale 1ns / 1ps
module t_flipflop(
input t,
input clk,
input clear,
output q,
output qbar
);
wire sbar, rbar;
assign sbar= ~(t & clk & qbar & clear);
assign rbar= ~(t & clk & q);
assign q= ~(sbar & qbar);
assign qbar= ~(rbar & q & clear);
endmodule
Now in output the value of q toggles when t=1, but the value of qbar is always 1
Also when t=1, q is always 0 and qbar is 1.
What am i doing wrong?
Test fixture -
`timescale 1ns / 1ps
module test_t_flipflop;
// Inputs
reg t;
reg clk;
reg clear;
// Outputs
wire q;
wire qbar;
// Instantiate the Unit Under Test (UUT)
t_flipflop uut (
.t(t),
.clk(clk),
.clear(clear),
.q(q),
.qbar(qbar)
);
initial begin
clear=1'b0;
#34 clear=1'b1;
end
initial begin
t=1'b0;
clk=1'b0;
forever #15 clk=~clk;
end
initial begin
#10 t=1;
#95 t=0;
#40 t=1;
end
EDIT: Added the complete test fixture code.
i want to implement this with the data flow model, to understand it clearly