Cover ALL the cases: when {j,k} equals 00, 01, 10, 11. This could be done with a case statement.
Put all the logic in 2. inside a always block and sample on rising edge of the clk. Or falling if preferred.
Most importantly, J-K ff is a Flip Flop, which means output value change on the clock edge. Comparing to a latch, the output value changes is based on clock level. With that being said, and examine your code again, you defined a clk but never use it. Or are you coping part of the code here?
You have to use “If” statements in a procedural block(For you it should be in an “always” block) in jkfflop.v. You have to make the code clk sensitive in this file.
You can’t instantiate a module inside “always” block(In seq_circuit1.v).
No I am not saying that.
You can find examples on-line about how/where to write “if” statements and also how to instantiate a module.
Let me write a small template.
//How to write if statements
always @(posedge clk) begin
//if statement is present inside a always block
if(your condition) begin
your statements
end
end
//How to instatiate
module xyz;
//below instantiation is not inside always block
jkflop1(j1,…);
jkflop2(j2…);
//your codes
endmodule
always @(posedge clk) begin
if(J==0 & K==1)
begin
Q = 0;
end
else if(J==1 & K==0)
begin
Q = 1;
end
else if(J==1 & K==1)
begin
Q = ~Q;
end end
endmodule
For me it is working.At least compiling if I change “output Q” to “output reg Q”
By the way it can’t be same error.
There are few more issues in your second file (sequence1.v).
I would suggest go through below link for good coding understanding.
Thanks kiru2006 all fixed. All file compiled with no error.
Sorry for asking stupid question, But I’m new to Verilog. Is the code correct implementation of the logic circuit(see image above).