Very basic .vl question

Status
Not open for further replies.

yannoo95170

Member level 1
Joined
May 13, 2013
Messages
36
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,724
Hi,

I just begin with FPGA development on a Linux box, and have a problem with the basic counter example
(the first thing that I have tested just after the standard beginner "Hello, World" example)

counter.vl
Code:
module counter(out, clk, reset);

  parameter WIDTH = 8;

  output [WIDTH-1 : 0] out;
  input 	       clk, reset;

  reg [WIDTH-1 : 0]   out;
  wire 	       clk, reset;

  always @(posedge clk)
    out <= out + 1;

  always @reset
    if (reset)
      assign out = 0;
    else
      deassign out;

endmodule // counter

test.vl
Code:
module test;

  /* Make a reset that pulses once. */
  reg reset = 0;
  initial begin
     # 17 reset = 1;
     # 11 reset = 0;
     # 29 reset = 1;
     # 11 reset = 0;
     # 100 $finish;
     
  end

  /* Make a regular pulsing clock. */
  reg clk = 0;
  always #5 clk = !clk;

  wire [7:0] value;
  counter c1 (value, clk, reset);

  initial
     $monitor("At time %t, value = %h (%0d)",
              $time, value, value);
endmodule // test

This compile fine with iverilog on my Linux box using this makefile
Code:
all : hello test

hello : hello.vl
	iverilog -o hello hello.vl
	vvp hello

test : counter.vl test.vl
	iverilog -o test counter.vl test.vl
	vvp test

but my problem is from the result of vvp test
Code:
yannoo@Ubuntoo:~/dev/FPGA$ make test
iverilog -o test counter.vl test.vl
vvp test
At time                    0, value = xx (x)
At time                   17, value = 00 (0)
At time                   35, value = 01 (1)
At time                   45, value = 02 (2)
At time                   55, value = 03 (3)
At time                   57, value = 00 (0)
At time                   75, value = 01 (1)
At time                   85, value = 02 (2)
At time                   95, value = 03 (3)
At time                  105, value = 04 (4)
At time                  115, value = 05 (5)
At time                  125, value = 06 (6)
At time                  135, value = 07 (7)
At time                  145, value = 08 (8)
At time                  155, value = 09 (9)
At time                  165, value = 0a (10)

I have tested to modify the
Code:
 # 100 $finish;
to values such as
Code:
 # 1000 $finish;
or
Code:
 # 5000 $finish;
and this make more occurences of the counter but **always** a reset of the counter's value at time 57

=> what the signification of the values after the # ?
(the # character does not seem to be one indication of a line of comment such as used into scripts shell)
[this seem to indicate a time + an action but I don't understand if the time is relative to previous "#steps" or global]
 
Last edited:

Hi there,
your code is working absolutely fine..
you are somewhat right in your guess.
#nn indicates the delay in addition to the time spent before this "#"
So effectively your reset routines are working as follows
Code:
  reg reset = 0;
  initial begin
     # 17 reset = 1;      At 17th time unit
     # 11 reset = 0;      
     # 29 reset = 1;      At (17+11+29)=57th time unit
     # 11 reset = 0;
     # 100 $finish;
     
  end

Hence, the reason your counter output, "out" becomes zero at 57th time unit.
To remove this, you should better write the reset routines in the following manner:
Code:
  reg reset = 0;
  initial begin
     # 17 reset = 1;
     # 19 reset = 0;
     # 100 $finish;
     
  end
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…