Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(digital-design): add verilog #22279

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,13 @@ The diagram illustrates the repository's architecture, which is considered overl
- **Solidity** - Contract-oriented programming language
- **solc-js** - JavaScript bindings for the Solidity compiler

## Digital Design

- **Verilog** - Hardware description language
- **VHDL** - Hardware description language

## Embedded, IoT, Hardware

- **VHDL** - Very High Speed Integrated Circuits Program (VHSIC) hardware description language
- **pySerial** - Serial communication library
- **cantools** - Controller Area Network (CAN) bus tools
- **python-can** - Controller Area Network (CAN) bus library
Expand Down Expand Up @@ -808,6 +812,7 @@ The diagram illustrates the repository's architecture, which is considered overl
- **Snowflake SQL**
- **Spark SQL**
- **Swift**
- **Verilog**
- **VHDL**
- **XML**
- **YAML**
Expand Down Expand Up @@ -998,7 +1003,7 @@ The toroidal propeller allows a small multirotor aircraft to operate more quietl

![OpenSCAD screenshot](https://github.com/hongbo-miao/hongbomiao.com/assets/3375461/00b3e679-66a7-4d9c-8d68-c31c124e0a54)

### VHDL - Very High Speed Integrated Circuits Program (VHSIC) Hardware Description Language
### VHDL - Hardware Description Language

The VHDL waveforms are displayed in GTKWave.

Expand Down
6 changes: 6 additions & 0 deletions digital-design/verilog/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
install:
sudo apt-get install --yes iverilog
compile:
iverilog -o output/main src/main.v
run:
vvp output/main
Empty file.
69 changes: 69 additions & 0 deletions digital-design/verilog/src/main.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module counter_4bit (
input wire clk, // Clock input
input wire rst, // Reset input
output reg [3:0] count // 4-bit counter output
);

// Sequential logic block
always @(posedge clk) begin
if (rst) begin
// Synchronous reset
count <= 4'b0000;
end
else begin
// Increment counter
count <= count + 1;
end
end

endmodule

// Testbench
module counter_4bit_tb;

// Testbench signals
reg clk;
reg rst;
wire [3:0] count;

// Instantiate the counter
counter_4bit counter_inst (
.clk(clk),
.rst(rst),
.count(count)
);

// Clock generation
initial begin
clk = 0;
forever #5 clk = ~clk;
end

// Test stimulus
initial begin
// Initialize
rst = 1;

// Wait for 2 clock cycles
#20;

// Release reset
rst = 0;

// Let it count for a while
#160;

// Apply reset again
rst = 1;
#20;

// End simulation
$finish;
end

// Monitor changes
initial begin
$monitor("Time=%0t rst=%b count=%b", $time, rst, count);
end

endmodule
File renamed without changes.
File renamed without changes.
File renamed without changes.