I tried to generate a waveform for a 4-bit up/down counter in modelsim; my code got compiled, but it is stuck to zero not getting the values based on the values of up_down
.
module up_down_counter(clock, din, load, up_down, resetn, count);
input clock;
input [3:0]din;
input resetn, up_down, load;
output [3:0]count;
reg [3:0]count;
always@(posedge clock)
begin
if(resetn == 1'b1)
begin
count <= 4'b0;
end
else if(load == 1'b1)
begin
count <= din;
end
else if(up_down == 1'b1)
begin
count <= count + 1;
end
else if(up_down == 1'b0)
begin
count <= count - 1;
end
end
endmodule
//testbench
module up_down_test;
reg clock;
reg [3:0]din;
reg resetn, up_down, load;
wire [3:0]count;
up_down_counter DUV(clock, din, load, up_down, resetn, count);
always #8 clock = ~clock;
initial
begin
clock = 1'b0;
resetn = 1'b0;
load = 1'b1;
up_down = 1'b0;
din = 4'b0000;
#200 $finish;
end
always #80 up_down = ~up_down;
initial
$monitor("%d/n",count);
endmodule
These are my codes: one is RTL and another one is a testbench.