question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected behavior with simple dff example - unexpected triggering at time==0

See original GitHub issue

From: https://github.com/cocotb/cocotb/pull/1529#pullrequestreview-387867775

# test_dff.py

import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import FallingEdge

@cocotb.test()
async def test_dff_simple(dut):
    """ Test that d propagates to q """

    clock = Clock(dut.clk, 10, units="us")  # Create a 10us period clock on port clk
    cocotb.fork(clock.start())  # Start the clock

    for i in range(10):
        await RisingEdge(dut.clk)  # Synchronize ourselves with the clock
        val = random.randint(0, 1)
        dut.d <= val  # Assign the random value val to the input port d
        await FallingEdge(dut.clk)
        assert dut.q == val, "output q was incorrect on the {}th cycle".format(i)
  6000.00ns ERROR    cocotb.regression                         regression.py:396  in _score_test                     Test Failed: test_dff_simple (result was ValueError)
                                                                                                                     Traceback (most recent call last):
                                                                                                                       File "/examples/dff_simple/test_dff.py", line 20, in test_dff_simple
                                                                                                                         assert dut.q == val, "output was incorrect on the {}th cycle".format(i)
                                                                                                                       File "/cocotb/handle.py", line 409, in __eq__
                                                                                                                         return self.value == other
                                                                                                                       File "/cocotb/binary.py", line 439, in __eq__
                                                                                                                         return self.value == other
                                                                                                                       File "/cocotb/binary.py", line 296, in value
                                                                                                                         return self.integer
                                                                                                                       File "/cocotb/binary.py", line 287, in integer
                                                                                                                         return self._convert_from[self.binaryRepresentation](self._str)
                                                                                                                       File "/cocotb/binary.py", line 193, in _convert_from_unsigned
                                                                                                                         return int(resolve(x), 2)
                                                                                                                       File "/cocotb/binary.py", line 45, in resolve
                                                                                                                         raise ValueError("Unable to resolve to binary >%s<" % string)
                                                                                                                     ValueError: Unable to resolve to binary >z<
  6000.00ns ERROR    cocotb.regression                         regression.py:227  in tear_down                       Failed 1 out of 1 tests (0 skipped)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
cmarqucommented, Apr 13, 2020

There is also “The Facts and Fallacies of Verilog Event Scheduling: Is the IEEE 1364 Standard Right or Wrong?”: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.611.4282&rep=rep1&type=pdf

0reactions
marlonjamescommented, Dec 3, 2020

In all the simulators tested besides Modelsim or VCS, RisingEdge dumps you before the HDL resolves, so you must wait for ReadWrite or ReadOnly to have the HDL resolve the signals so you can read the correct values. Modelsim and VCS fail when waiting on ReadWrite after RisingEdge.

We should investigate whether Modelsim and VCS infact dump you in ReadWrite after a RisingEdge, or if some other issue is to blame. Assuming that is the case, what should be done about it?

Part of the issue may stem from the fact that dut.clk <= 1 in the custom_clock forked task is just scheduling the clock edge for Scheduler._do_writes() to perform. _do_writes() waits for ReadWrite (and is the first task to run), then updates the signal values. Then other tasks waiting on ReadWrite are run. RisingEdge(dut.clk) is triggered after returning from the ReadWrite callback, before the HDL resolves, since the signal has changed value.

Modelsim and VCS may have issues registering for another cbReadWriteSynch callback with 0 delay right after it was just called.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Verilog Nonblocking Assignments With Delays, Myths ...
Consider a simple delay buffer model with a propagation delay of 5ns, where the delay has been added to a Verilog specify block....
Read more >
Teaching Expected and Unexpected Behaviors
What do I mean by expected and unexpected behaviors? Expected behavior is simply behavior that is normal, reasonable and anticipated.
Read more >
VCS® MX/VCS MXi™ User Guide
VCS MX uses the following three basic steps to compile, elaborate ... propagate during the simulation and can cause unexpected behavior.
Read more >
Static Timing Analysis for Nanometer Designs - WordPress.com
unexpected pass-through of data through a flip-flop: that is, it ensures that ... Functional behavior across clock cycles: The static timing analysis.
Read more >
VCS®/VCSi™ User Guide
How VCS Prevents Time 0 Race Conditions . ... unpredictable, it can cause unexpected problems during simulation. It is easy to ... module...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found