C
Confused Frank
Guest
I wrote a task to feed test vectors to my design, however, I realized some
differences between
"task" and the normal state machines I used to do. One sample code below, I
am expecting the
the signal "trd_sample" to be delayed by one cycle of "trc", i.e. 2nd
posedge of trc. However,
why does the simulation shows on the first posedge of trc?
I have put the modelsim waveform here.
http://img234.imageshack.us/img234/5034/confusedtask7bg.jpg
Thank you in advance.
module sim;
reg clk;
reg rst_n;
reg trw;
reg [3:0] trd;
reg trc;
reg [3:0] trd_sample;
always #5 clk <= ~ clk;
initial begin
clk <= 1'b0;
rst_n <= 1'b1;
#1 rst_n <= 1'b0;
#2 rst_n <= 1'b1;
tx_in;
$stop();
end
task tx_in;
integer i, j;
begin
@ (posedge clk);
@ (posedge clk);
trc <= 1'b0;
trw <= 1'b0;
trd <= 4'h0;
@ (posedge clk);
trc <= 1'b1;
trw <= 1'b1;
trd <= 4'hA;
@ (posedge clk);
trc <= 1'b0;
@ (posedge clk);
trc <= 1'b1;
trd <= 4'h9;
@ (posedge clk);
trc <= 1'b0;
@ (posedge clk);
trc <= 1'b1;
trd <= 4'h8;
@ (posedge clk);
trc <= 1'b0;
@ (posedge clk);
trc <= 1'b1;
trd <= 4'h7;
@ (posedge clk);
@ (posedge clk);
@ (posedge clk);
@ (posedge clk);
end
endtask
always @ (posedge trc or negedge rst_n) begin
if (~rst_n)
trd_sample <= 4'h0;
else begin
if (trw)
trd_sample <= trd;
end
end
endmodule
differences between
"task" and the normal state machines I used to do. One sample code below, I
am expecting the
the signal "trd_sample" to be delayed by one cycle of "trc", i.e. 2nd
posedge of trc. However,
why does the simulation shows on the first posedge of trc?
I have put the modelsim waveform here.
http://img234.imageshack.us/img234/5034/confusedtask7bg.jpg
Thank you in advance.
module sim;
reg clk;
reg rst_n;
reg trw;
reg [3:0] trd;
reg trc;
reg [3:0] trd_sample;
always #5 clk <= ~ clk;
initial begin
clk <= 1'b0;
rst_n <= 1'b1;
#1 rst_n <= 1'b0;
#2 rst_n <= 1'b1;
tx_in;
$stop();
end
task tx_in;
integer i, j;
begin
@ (posedge clk);
@ (posedge clk);
trc <= 1'b0;
trw <= 1'b0;
trd <= 4'h0;
@ (posedge clk);
trc <= 1'b1;
trw <= 1'b1;
trd <= 4'hA;
@ (posedge clk);
trc <= 1'b0;
@ (posedge clk);
trc <= 1'b1;
trd <= 4'h9;
@ (posedge clk);
trc <= 1'b0;
@ (posedge clk);
trc <= 1'b1;
trd <= 4'h8;
@ (posedge clk);
trc <= 1'b0;
@ (posedge clk);
trc <= 1'b1;
trd <= 4'h7;
@ (posedge clk);
@ (posedge clk);
@ (posedge clk);
@ (posedge clk);
end
endtask
always @ (posedge trc or negedge rst_n) begin
if (~rst_n)
trd_sample <= 4'h0;
else begin
if (trw)
trd_sample <= trd;
end
end
endmodule