I have 2 clock, clk_a, clk_b[3:0]. clk_b has 4 phases and each differs a bit.
Now i want to record and compare the time difference between
clk_b[0] and clk_a,
clk_b[1] and clk_a,
clk_b[2] and clk_a,
clk_b[3] and clk_a.
Then using this difference to compare with the reference value. They should be the same.
This is done using a fork…join. //code later
Most of the time, the clk_b[i] does not coincide with clk_a, and everything is fine.
When they do coincide, e.g. posedge clk_b[0] coincide with posedge clk_a, their time difference should be zero, ref. time difference is zero. But I cannot get $time to record clk_b[0]'s time at that very same posedge. $time will always record the next posedge, which is wrong for my design.
Below is my code to give you guys a better picture:
//some code
@(posedge clk_a);//wait a posedge
fork
begin
@(posedge clk_a);//desired logic: when clk_a posedge happens, record the time of the next clk_b[0] posedge
@(posedge clk_b[0])//IF clk_b[0] posedge coincides with clk_a posedge, record time of this very coincided posedge.
time_b[0] = $time;//My code now sadly is recording the next clk_b[0] posedge after the coincided one.
end
begin
@(posedge clk_a);
@(posedge clk_b[1])
time_b[1] = $time;
end begin
@(posedge clk_a);
@(posedge clk_b[2])
time_b[2] = $time;
end begin
@(posedge clk_a);
@(posedge clk_b[3])
time_b[3] = $time;
end
join_none
begin
@(posedge clk_a)//record time when clk_a posedge happens
time_a = $time;
end
Would appreciate any thoughts.
Thanks guys.