Latest Post

Ads

Verilog: JK Flip Flop Behavioral Modelling using If Else Statement with Testbench Code

Verilog Code for JK Flip Flop Behavioral Modelling using If Else with Testbench Code

module JK_FF(
    input J,K,clock,reset,
    output q, qb
    );
reg q, qb; 

always @ (posedge (clock))
    begin 
        if (reset)
            begin
               q <= 0;
               qb <=1;
            end   
        else
            begin
               if (J != K)
                    begin
                    q <= J;
                    qb <= K;
                    end 
               else if (J == 1 && K == 1) 
                    begin 
                    q <= 1'bZ; 
                    qb <= 1'bZ; 
                    end 
            end
end  
endmodule

//Testbench code for JK Flip Flop Behavioral Modelling using If Else Statement

initial begin
// Initialize Inputs 
J = 0; K = 0; 
// Wait 100 ns for global reset to finish 
#100;
// Add stimulus here 
#100; J=0; K=1; 
#100; J=1; K=0; 
#100; J=1; K=1;
end
initial begin 
#100 
$monitor(“clock=%b, reset=%b, J=%b, K=%b, q=%b, qb=%b”, clock, reset, J, K, q, qb); 
end 
endmodule

Comments

Ads

Popular posts from this blog

VLSI: BCD to Excess 3 and Excess 3 to BCD Dataflow Modelling

Full Subtractor Verilog Code in Structural/Gate Level Modelling with Testbench

VLSI: 4-1 MUX Dataflow Modelling with Testbench

VLSI: Half Subtractor and Full Subtractor Gate Level Modelling

VLSI: 1-4 DEMUX (Demultiplexer) Dataflow Modelling with Testbench