-
Notifications
You must be signed in to change notification settings - Fork 0
/
dualCounter.v
70 lines (57 loc) · 1.14 KB
/
dualCounter.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Code your design here
module dualCounter (
input clk,
input rst,
output reg [7:0] out,
output reg [3:0] count1,
output reg [3:0] count2
);
always @(posedge clk or posedge rst) begin
if (rst) begin
count1 <= 4'b0;
count2 <= 4'b0;
end
else if (count1 == 4'hF & count2 == 4'hF) begin
count1 <= 4'b0;
count2 <= 4'b0;
end
else if (count1 == 4'hF) begin
count1 <= 4'b0;
count2 <= count2 + 4'b01;
end
else begin
count1 <= count1 + 4'b01;
end
out <= {count2, count1};
end
endmodule
// Code your testbench here
// or browse Examples
`timescale 1ns / 1ps
module tb_dualCounter;
reg clk;
reg rst;
wire [7:0] out;
wire [3:0] count1,count2;
dualCounter uut (
.clk(clk),
.rst(rst),
.out(out),
.count1(count1),
.count2(count2)
);
// Clock generation
always begin
#1 clk = ~clk;
end
// Stimulus
initial begin
$dumpfile("file.vcd");
$dumpvars(1);
clk = 0;
rst = 1;
#10 rst = 0; // Assert reset for 10 time units
#1000; // Run for additional 100 time units
$stop; // Stop simulation
end
endmodule