0% found this document useful (0 votes)
3 views2 pages

module counter

The document describes a Verilog module for a counter that increments or decrements based on the mode input and resets to zero when the reset input is active. It includes a test bench for simulating the counter's behavior with clock generation and input driving. The test bench also monitors and displays the values of the reset, clock, count, and mode signals during simulation.

Uploaded by

kkandasamy0303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

module counter

The document describes a Verilog module for a counter that increments or decrements based on the mode input and resets to zero when the reset input is active. It includes a test bench for simulating the counter's behavior with clock generation and input driving. The test bench also monitors and displays the values of the reset, clock, count, and mode signals during simulation.

Uploaded by

kkandasamy0303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

module counter (mode,clk,reset,count);

input mode,clk,reset;
output reg [7:0] count;

//internal wires
wire [7:0] count_mux_out, rst_mux_out;

//combinational logic
assign count_mux_out = mode ? count + 1'b1: count - 1'b1;
assign rst_mux_out = reset ? 8'b0 : count_mux_out;

//sequential logic
always @( posedge clk)
begin
count <= rst_mux_out;
end
endmodule

TEST BENCH

module counter_test();

// wire/reg declaration
reg clk, reset, mode;
wire [7:0] count;

// Module instantiation
counter dut_counter (.clk(clk), .mode(mode), .reset(reset), .count(count));

//Generate vcd file


initial begin
$dumpfile("dump.vcd");
$dumpvars(0);
end

// Clock generation
always #5 clk=~clk;

// Driving inputs
initial
begin
clk=0;
reset=1; // active-high reset
#20; // waits 20ns
reset=0;
end

initial
begin
mode=1;
#180
mode=0;
#165
$finish;
end

// Displays values of wires being monitored


initial $monitor("Time = %d rst = %b clk = %b count = %b mode = %b", $time, reset, clk, count, mode);

end module

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy