generated from TinyTapeout/tt06-verilog-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a clock divider and a 3 bit counter 0 -> 6
- Loading branch information
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2024 Fabio Ramirez Stern | ||
* SPDX-License-Identifier: Apache-2.0 | ||
****************************************************** | ||
* Divides the 1 MHz clock to a 10 Hz clock | ||
*/ | ||
|
||
`define default_netname none | ||
|
||
module clockDivider ( | ||
input wire clk_in, | ||
input wire res, | ||
input wire ena, | ||
output wire clk_out | ||
); | ||
reg[16:0] counter = 0; | ||
parameter div = 100000; // 1 MHz / 100'000 = 10 Hz | ||
|
||
always @(posedge clk_in or res) begin | ||
if (!res) begin // async reset | ||
counter <= 0; | ||
clk_out <= 0; | ||
end else begin | ||
if (counter < (div-1)) begin // count up | ||
counter <= counter + 1; | ||
end else begin // reset counter and invert output | ||
counter <= 0; | ||
clk_out <= ~clk_out; | ||
end | ||
end | ||
end | ||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2024 Fabio Ramirez Stern | ||
* SPDX-License-Identifier: Apache-2.0 | ||
****************************************************** | ||
* Counts up to 6 | ||
*/ | ||
|
||
`define default_netname none | ||
|
||
module counter6 ( | ||
input wire clk, // clock | ||
input wire ena, // enable | ||
input wire res, // reset | ||
output wire max, // high when max value (6) reached | ||
output wire [2:0] cnt // 3 bit counter output | ||
) | ||
|
||
reg[2:0] counter = 0; | ||
parameter max_count = 6; | ||
|
||
always @(posedge clk_in or res) begin | ||
if (!res) begin // async reset | ||
cnt <= 0; | ||
max <= 0; | ||
end else if (ena) begin | ||
if (cnt < max_count - 1) begin | ||
cnt <= cnt + 1; | ||
end else begin | ||
cnt <= 0; | ||
end | ||
end | ||
end | ||
|
||
always @(cnt) begin | ||
if (cnt == max_count) begin | ||
max <= 1; | ||
end else begin | ||
max <= 0; | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters