Altera_Forum
Honored Contributor
17 years agoCounter simulation
I got a three bit counter module which reset to 3'b000 every sixth count of clock. when I simulated using quartus II 7.2, I found wrong numbers after count values of 1, 3 and 5. (That is simulation showed count=3 after 1, then count correctly moves to 2. Then count becomes 5 after 3, but then moves correctly to 4. And becomes 1 after 5, but then correctly becomes 0.) The image of the simulation is attached along. (I wonder if these are jitters but how can they be jitters during simulation. Am I doing something wrong here? And how can these be removed?)
Here is my code: module test(clk, reset, tstport); input clk,reset; output [2:0] tstport; reg [2:0] cnt; assign tstport=cnt; /* Implementation of testing the counter */ always @(posedge clk or negedge reset) begin if(reset==1'b0) begin cnt=3'b000; end else begin cnt=cnt+3'b001; //useful $0-$5 (needed only six states) if(cnt>3'b101) cnt=3'b000; end end endmodule