Skip to content

Commit

Permalink
Merge pull request #16 from yashgupta26/main
Browse files Browse the repository at this point in the history
Fix issue 15 counter
  • Loading branch information
PeanutCoffee committed Oct 5, 2022
2 parents 67d0bb1 + a2f7230 commit e044e40
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Verilog Codes for Hardware Modelling/counter.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module N_bit_sync_counter(x,ud,clk,clr,q,y);

parameter N = 4;

input x,ud,clk,clr;

output reg [N-1:0] q;
output reg y;

always @ (negedge clk,posedge clr)
if (clr==1)
begin
q<=0;
y<=0;
end
else
if (x == 1)
if (ud==1) {y,q} <= q + 1'b1;
else
{y,q} <= q - 1'b1;
endmodule
34 changes: 34 additions & 0 deletions Verilog Codes for Hardware Modelling/counter_tb.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
`timescale 1ns / 1ps

module N_bit_sync_counter_tb;

parameter N = 4;

reg x,ud,clk,clr;
wire [N-1:0] q;
wire y;

N_bit_sync_counter UUT(x,ud,clk,clr,q,y);

initial begin
clk = 0;
forever
#5 clk = ~clk ;
end

initial begin

#5 clr = 1'b1;
#5 clr = 1'b0;
ud=1'b0;

x = 1'b1;
end

initial
begin
$display("\ttime,\tq,\ty");
$monitor("\t%d,\t%b,\t%b",$time,q,y);
end

endmodule

0 comments on commit e044e40

Please sign in to comment.