New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sim: Fix clock phase in add_clock having to be specified in ps. #679
Conversation
Codecov Report
@@ Coverage Diff @@
## main #679 +/- ##
==========================================
+ Coverage 81.32% 81.34% +0.01%
==========================================
Files 49 49
Lines 6464 6465 +1
Branches 1526 1526
==========================================
+ Hits 5257 5259 +2
Misses 1015 1015
+ Partials 192 191 -1
Continue to review full report at Codecov.
|
cc @modwizcode |
Illustrative example: from amaranth import *
from amaranth.sim import *
phase0_fail = Signal()
phase90_fail = Signal()
phase180_fail = Signal()
phase270_fail = Signal()
phase0_correct = Signal()
phase90_correct = Signal()
phase180_correct = Signal()
phase270_correct = Signal()
m = Module()
m.domains += ClockDomain("phase0_fail")
m.domains += ClockDomain("phase90_fail")
m.domains += ClockDomain("phase180_fail")
m.domains += ClockDomain("phase270_fail")
m.domains += ClockDomain("phase0_correct")
m.domains += ClockDomain("phase90_correct")
m.domains += ClockDomain("phase180_correct")
m.domains += ClockDomain("phase270_correct")
m.d.comb += [
phase0_fail.eq(ClockSignal("phase0_fail")),
phase90_fail.eq(ClockSignal("phase90_fail")),
phase180_fail.eq(ClockSignal("phase180_fail")),
phase270_fail.eq(ClockSignal("phase270_fail")),
phase0_correct.eq(ClockSignal("phase0_correct")),
phase90_correct.eq(ClockSignal("phase90_correct")),
phase180_correct.eq(ClockSignal("phase180_correct")),
phase270_correct.eq(ClockSignal("phase270_correct"))
]
sim = Simulator(m)
p = 1
# This is what is desired (?)
sim.add_clock(p, phase=0*p/4, domain="phase0_fail")
sim.add_clock(p, phase=1*p/4, domain="phase90_fail")
sim.add_clock(p, phase=2*p/4, domain="phase180_fail")
sim.add_clock(p, phase=3*p/4, domain="phase270_fail")
# This is what is needed (!)
sim.add_clock(p, phase=1e12 * (p/2 + 0*p/8), domain="phase0_correct")
sim.add_clock(p, phase=1e12 * (p/2 + 1*p/8), domain="phase90_correct")
sim.add_clock(p, phase=1e12 * (p/2 + 2*p/8), domain="phase180_correct")
sim.add_clock(p, phase=1e12 * (p/2 + 3*p/8), domain="phase270_correct")
def proc():
for i in range(5):
yield
sim.add_sync_process(proc, domain="phase0_fail")
with sim.write_vcd("bug_clock_phase.vcd"):
sim.run_until(5) |
Thanks! Can you add this as an actual testcase as part of the PR for regression purposes? |
Where would that go? tests/test_sim.py? |
Yes; that's a good place to put it. |
On it. |
That should do it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the suggested changes.
@modwizcode Thanks for the review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there was a bit of a misunderstanding, I clarified the style I intended, sorry about that.
e601170
to
e7233ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @bl0x and @modwizcode! |
Now more in line with the documentation, which states that the process will wait
phase
seconds.Ref:
amaranth/amaranth/sim/core.py
Lines 104 to 106 in c83b51d
This was not true so far.
One had to give the clock phase wait time in ps.