please help mie with this

OP #1987265
Rate this post
• ▲ useful
▼ not useful
module count (clk, rst, enable, cnt);

input  clk, rst, enable;
output [3:0] cnt;

reg [3:0] cnt;

always @(posedge clk or posedge rst) // async active high reset
begin
     if(rst)
           cnt <= 0;
     else if(enable)
           cnt <= cnt + 1;
end

endmodule

===================================================================

What is the testbench for this code??
Guest #1987316
Rate this post
• ▲ useful
▼ not useful
This should be a good starting point for you but you definitely should 
make some exercises by modifying it. You could start by applying 
comments to the sections below and posting the result.

HTH, Harald

----(snip)----
`timescale 1ns/1ps;

module top;

reg             clock;
reg             reset;
reg             enable;
wire    [3:0]   counter;

always
    begin
    #5 clock = !clock;
    end

count count_1
    (
    .clk(clock),
    .rst(reset),
    .enable(enable),
    .cnt(counter)
    );

initial
    begin
    clock  = 0;
    reset  = 1;
    enable = 0;
    repeat (2) @(posedge clock);
    reset  = 0;
    repeat (3) @(posedge clock);
    enable  = 1;
    repeat (17) @(posedge clock);
    if (counter != 4'h1)
        begin
        $display("error, counter value is not 1 but should be");
        $stop;
        end
    $display("test ok");
    $stop;
    end

endmodule
----(snap)----
OP #1988483
Rate this post
• ▲ useful
▼ not useful
Thank you... i figure out liao...
thank you so much... but the way what is this i need to understand
=>  repeat (2) @(posedge clock);
    reset  = 0;
    repeat (3) @(posedge clock);
    enable  = 1;
    repeat (17) @(posedge clock);
    if (counter != 4'h1)
        begin
        $display("error, counter value is not 1 but should be");
        $stop;
        end
    $display("test ok");
    $stop;
    end


thank you
Guest #1988835
Rate this post
• ▲ useful
▼ not useful
> but the way what is this i need to understand
> =>  repeat (2) @(posedge clock);
I do not know Verilog, but i would interpret this as
"wait for 2 rising edges of clock"

I would recommend you a book for absolute beginners... :-/

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.