I want to design an counter which counts up to some number, lets say it is 3, for this I write a code that work well with "$finish" but not with "disable".
I want to use this counter for synthesis so I have to use "disable" statement .....
I have attached my both code- (1) With $finish that stops easily & accurately
// Code with $finish
module counter(input wire clk);
reg [23:0]N=24'b0000_0000_0000_0000_0000_0000;
always @ (posedge clk)
begin
if (N == 24'b0000_0000_0000_0000_0000_0011)
begin
$display("Inside If N=%d in Time=",N,$time);
$finish;
end
else
begin
N <= N +1;
$display("Inside Else N=%d in Time=",N,$time);
end
end
endmodule
(2) With disable that not stop at all..
// Code with disable that not stop
module counter(input wire clk);
reg [23:0]N=24'b0000_0000_0000_0000_0000_0000;
always @ (posedge clk)
begin :close
if (N == 24'b0000_0000_0000_0000_0000_0011)
begin
$display("Inside If N=%d in Time=",N,$time);
disable close;
end
else
begin
N <= N +1;
$display("Inside Else N=%d in Time=",N,$time);
end
end
endmodule