Question
verilog code needed for the counter using the JK flip flop
Successfully completing a System Verilog +80Pts. Implementation showing the full sequence of ABC readouts Pre-Laboratory Exer

please include the testbench, thanks!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Design of counter of the given sequence * It has direction input (band * ff Direction). O then count sequence is gray code 00State Transition table Neutstalls J-k flipflopinpeche equipment + + Фt T2 и Tikip to oo 1х ох ох о то ох 1 6x о то - от preseK-map Simplification for gik flipflop inputs loop ProLUB 32 = 9tão o + ał go do J2 = a [ po @)) K2 = O POD +1 900 k2= a (ao 6

// verilog code for COUNTER using j-k flipfops

module counter(D,clk,Reset,count);

//input port declaartions

input D,clk,Reset ;

//output port declarations

output [2:0] count ;

  

//internal signal declarations for flipflop inputs

reg [2:0] J,K;

//internal signal declarations for flipflop outputs

reg [2:0] Q,Q_bar;

  

//logic for flipflop input expressions

assign J[2] = ((~Q[1]) & (~(Q[0] ^ D)));

assign K[2] = ((~Q[1]) & (Q[0] ^ D));

assign J[1] = ((Q[2] & (~(Q[0] ^ D))) | ((~Q[2]) & (Q[0] ^ D))) ;

assign K[1] = (((~Q[2]) & (~(Q[0] ^ D))) | (Q[2] & (Q[0] ^ D))) ;

assign J[0] = (Q[1] & (~(Q[2] ^ D)));

assign K[0] = (Q[1] & (Q[2] ^ D));

  

  

//INSTANTIATION of JK flipflops

JK_FF U0 (.J(J[2]),.K(K[2]),.clk(clk),.Reset(Reset),.Q(Q[2]),.Q_bar(Q_bar[2]));

JK_FF U1 (.J(J[1]),.K(K[1]),.clk(clk),.Reset(Reset),.Q(Q[1]),.Q_bar(Q_bar[1]));

JK_FF U2 (.J(J[0]),.K(K[0]),.clk(clk),.Reset(Reset),.Q(Q[0]),.Q_bar(Q_bar[0]));

//combo logic for counter output

assign count = Q;

  

endmodule

//verilog code for J-K flipflop

module JK_FF (J,K,clk,Reset,Q,Q_bar);

  

input J,K,clk,Reset;

output Q,Q_bar;

  

reg temp;

  

always @(posedge clk)

begin

if (Reset==1'b0)

begin

temp <= 1'b0;

end

else begin

case({J,K})

2'b00: temp <= temp;

2'b01: temp <= 1'b0;

2'b10: temp <= 1'b1;

2'b11: temp <= (~temp);

endcase

end

end

  

assign Q = temp ;

assign Q_bar = ~(Q);

  

endmodule

// verilog testbench code for counter

module test_counter ;

  

//inputs

reg D,clock,Reset ;

//outputs

wire [2:0] count;

  

//instantiate counter DUT

counter DUT (D,clock,Reset,count);

  

  

//clock input genartion

initial

begin

clock = 1'b0 ;

forever #5 clock = ~clock ;

end

  

  

initial

begin

$dumpfile("file.vcd");

$dumpvars;

Reset = 1'b0 ;

D=1'b1;#10;

Reset = 1'b1;

D=1'b0;

#80 ;

D= 1'b1;

#70;

D=1'b0;

$finish;

end

endmodule

Add a comment
Know the answer?
Add Answer to:
verilog code needed for the counter using the JK flip flop please include the testbench, thanks!...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT