-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcounter.v
More file actions
46 lines (42 loc) · 1.36 KB
/
counter.v
File metadata and controls
46 lines (42 loc) · 1.36 KB
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
// ----------------------------------
// This is my second Verilog Design
// Design Name: first_counter
// Function: This ia a 4 bit up-counter with
// Synchronous active high reset and
// with active high enable signal
// ----------------------------------
module counter (
clk, // clk input of the design
rst, // active high, asynchronous Reset input
enable, // Active high enable signal for counter
counter_out // 4 bit vector output of the counter
); // End of port list
// ------------Input Ports------------------
input clk;
input rst;
input enable;
// -----------Output Ports------------------
output [3:0] counter_out;
// -----------Input ports Data type---------
// By rule all the input ports should be wires
wire clk;
wire rst;
wire enable;
// ----------Output Ports Data Type---------
// Output port can be a storage element (reg) or a wire
reg [3:0] counter_out;
// ---------Code Starts Here----------------
// Since this counter is a positive edge trigged one,
// We trigger the below block with respect to positive
// edge of the clock.
always @(posedge clk or posedge rst)
begin : COUNTER // Block Name
if (rst == 1'b1) begin
// reset if active, we load the counter output with 4'b0000
counter_out <= #1 4'b0000;
end
else if (enable == 1'b1) begin
counter_out <= #1 counter_out + 1;
end
end // End of Block COUNTER
endmodule // End of the Module counter