4

I am trying to generate waveform in verilog using the code below but the result aren't as expected.

initial begin
    d = 1'b0;
#8  d <= 1'b1;
#15 d <= 1'b0;
end

Its initial value is 0(OK), at t=8, its 1(OK) but at t=23, its 0. Instead i want it to be 0 at t=15 relative to t=0 and not to t=8(i.e. previous statement).

Is there a way to do so? I have tried interchanging blocking and non-blocking assignments but no luck!

2 Answers 2

4

You could do this:

initial fork
    d = 1'b0;
#8  d = 1'b1;
#15 d = 1'b0;
join

All the statements inside fork join will be executed concurrently.

Or you could do this:

initial     d = 1'b0;
initial  #8 d = 1'b1;
initial #15 d = 1'b0;

Clearly, the three initial blocks will be executed concurrently.

If you really wanted to schedule 3 events from procedural (sequential) code, then you could do this:

initial begin
  d  =     1'b0;
  d <=  #8 1'b1;
  d <= #15 1'b0;
end

This uses intra-assignment delays together with non-blocking assignments.

http://www.edaplayground.com/x/4MiS

Sign up to request clarification or add additional context in comments.

2 Comments

Does that mean using inter-assignment delays advance the simulation time?
@devvaibhav I'm not sure what you mean exactly. However, section9.4.5 of IEEE1800-2012 ("Intra-assignment timing controls") says "An intra-assignment delay or event control shall delay the assignment of the new value to the left-hand side, but the right-hand expression shall be evaluated before the delay, instead of after the delay.". If you add an intra-assignment delay to a non-blocking assignment, then execution continues immediately after and the assignment occurs after the delay. So, you are effectively scheduling an event to take place some time in the future.
-3
module top_module(
    input [2:0] vec,
    output [2:0] outy,
    output out0,
    output out1,
    output out2
);

    assign outy = vec;
    assign out0 = vec[0];
    assign out1 = vec[1];
    assign out2 = vec[2];

endmodule

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.