skycanny
Junior Member level 3
Verilog HDl and modelsim have been exposed to me for only one week. Today , I describe a Counter with 4 width using verilog HDL and simulate it by modelsim. However ,an unexpected simulating result occers.The following is my source verilog HDL counter:
module counter(clk,clr,dir,ce,data_out);
input clk,clr,dir,ce;
output [3:0] data_out;
reg [3:0] data_out;
integer direction;
always@ (posedge clk)
begin
if(dir == 1'b1)
direction = 1;
else
direction = -1;
if(clr == 1'b0)
data_out = {4{1'b0}};
else if (ce == 1'b0)
data_out = data_out + direction;
end
endmodule
Could you explain this phenomina to me or would you please find the buggs in the source file? Thanks a lot!!! The attachment is the simulating wave.
module counter(clk,clr,dir,ce,data_out);
input clk,clr,dir,ce;
output [3:0] data_out;
reg [3:0] data_out;
integer direction;
always@ (posedge clk)
begin
if(dir == 1'b1)
direction = 1;
else
direction = -1;
if(clr == 1'b0)
data_out = {4{1'b0}};
else if (ce == 1'b0)
data_out = data_out + direction;
end
endmodule
Could you explain this phenomina to me or would you please find the buggs in the source file? Thanks a lot!!! The attachment is the simulating wave.