Skip to content

Bug: Time displayed in waveform view is off by 3 orders of magnitude #17

@gsuberland

Description

@gsuberland

The timescale on the waveform view always shows 3 orders of magnitude too large, e.g. if I have a 1MHz clock with sim.add_clock(1e-6) then it will show each tick being 1ms instead of 1μs.

I believe this is because the Amaranth simulator internally represents timestamps in femtoseconds, whereas d3-wave internally represents time units in nanoseconds:

https://github.com/amaranth-lang/amaranth/blob/9a78ad7fb979f6b3a7088e52cceb9f6ef8a3b5e2/amaranth/sim/core.py#L20-L21

https://github.com/Nic30/d3-wave/blob/a66d9286409b40ff9a62c78f702d8f51dbb099f4/src/timeFormat.ts#L3-L9

Looking at the debug info in the browser developer tools seems to confirm this, as the first nonzero timestamp in a showWaveforms message on a design with a 40MHz clock is 12500000, which is half a 40MHz clock period in femtoseconds rather than picoseconds.

If createTimeFormatterForTimeRange or TIME_UNITS can be overridden to use a new scale where fs is 1 instead of ps, then that may be an elegant fix for the issue.

My temporary workaround has just been to do 1e-3/freq instead of 1/freq in my add_clock calls, thus making the simulator output values that align with the waveform viewer's expectations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions