Code · 1 file
Sample Verilog File
Verilog hardware description: a parameterized counter and a testbench. Every language sample implements the same small program so you can compare them side by side.
Verilog · 986 B
Sample Verilog file
An idiomatic Verilog example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.
CC0 · free for any use · Verified by an independent tool · Report a problem
// Sample Verilog — samplefiles.com
// An 8-bit up-counter with synchronous reset and enable, plus a small testbench.
`timescale 1ns / 1ps
module counter #(parameter WIDTH = 8) (
input wire clk,
input wire rst,
input wire en,
output reg [WIDTH-1:0] count,
output wire overflow
);
assign overflow = en && (count == {WIDTH{1'b1}});
always @(posedge clk) begin
if (rst)
count <= {WIDTH{1'b0}};
else if (en)
count <= count + 1'b1;
end
endmodule
module counter_tb;
reg clk = 0, rst = 1, en = 0;
wire [7:0] count;
wire overflow;File details
Download from the command line
curl -L -o counter.v https://files.samplefiles.com/code/verilog/counter.vwget https://files.samplefiles.com/code/verilog/counter.vhttps://files.samplefiles.com/code/verilog/counter.vprintf '%s %s\n' 5c9b8daf7331f1cc837e6ea3dc531aebe2bd2501c529d3a363da9fe549a5c2fa counter.v | shasum -a 256 -cOr check the download in your browser with the checksum calculator.