My objective is when my input "start=1" the shifting is endless, and when I change it to "start=0" the shifting stops.
At that point when my output (result1 = 1) and (result = 5) it should end at the $finish command line. but instead it ends in the $stop in the testbench.
I think the problem is that the two output (result1 and result2) in the 2nd module is not linked in the 1st module.
How can I link the output in the 2nd module to the 1st module so that the condition in my if-else statement in the 1st module is satisfied and will proceed to $finish
.
I preset my testbench code so that when start = 0; it stops at result1 = 1 and result2 = 5.
here is my code //1st module
module random(ps_in, ps_out, clk, start, result1, result2);
input ps_in;
output reg ps_out;
input clk;
input start;
output [2:0] result1; //1st output based on the 2nd module
output [2:0] result2; //2nd output based on the 2nd module
reg count;
initial begin
ps_out = 0;
count = 0;
end
always @ (posedge clk)
if (start!=0) begin
ps_out = ps_in;
end
else if (start!=1 && count!=1) begin
ps_out = ps_in;
count = count + 1;
end
else if (start!=1 && result1==3'b001 && result2==3'b101) begin
$finish; //IT MUST END IN THIS LINE
end
endmodule
//2nd module
module smachine (start,clk,result1,result2);
input start;
input clk;
output [2:0] result1;
output [2:0] result2;
wire feedback1, feedback2, ffq1, ffq2, ffq3, ffq4;
random r1 (feedback1, ffq1, clk, start);
random r2 (ffq1, result1[2], clk, start);
random r3 (result1[2], result1[1], clk, start);
random r4 (result1[1], result1[0], clk, start);
random r5 (result1[0], ffq2, clk, start);
assign feedback1 = (result1[1] ^~ffq2);
random r6 (feedback2, result2[2], clk, start);
random r7 (result2[2], result2[1], clk, start);
random r8 (result2[1], ffq3, clk, start);
random r9 (ffq3, result2[0], clk, start);
random r10(result2[0], ffq4, clk, start);
assign feedback2 = (ffq3 ^~ffq4);
endmodule
here is my testbench
module qqqq;
// Inputs
reg start;
reg clk;
// Outputs
wire [2:0] result1;
wire [2:0] result2;
// Instantiate the Unit Under Test (UUT)
smachine uut (
.start(start),
.clk(clk),
.result1(result1),
.result2(result2)
);
always
#5 clk = ~clk;
initial begin
// Initialize Inputs
#10 start = 1;
clk = 0;
#50 start = 0;
clk = 0;
#50 $stop;
end
endmodule