2

I am getting a different clock period, when I am simulating the Endian Swapper example of Cocotb in VHDL and Verilog mode using QuestaSim. The clock is generated in the same way for both modes in the provided example code:

@cocotb.coroutine
def clock_gen(signal):
    while True:
        signal <= 0
        yield Timer(5000)
        signal <= 1
        yield Timer(5000)


@cocotb.coroutine
def run_test(dut): # stripped un

    cocotb.fork(clock_gen(dut.clk))

When running in Verilog mode with:

make SIM=questa GUI=1

the clock period is 1000 ns (one thousand nano-seconds), and thus, the time resolution is 100 ps.

When running in VHDL mode with:

make SIM=questa GUI=1 TOPLEVEL_LANG=vhdl

the clock period is 10000 ns (ten thousand nano-seconds), and thus, the time resolution is 1 ns.

I am using the same clock generation in two other VHDL projects. In one I am getting a clock period of 10000 ns too, (1 ns resolution). But in the other one, the clock period is only 10 ns, giving a resolution of 1 ps.

Why differs the time resolution in all these run modes and projects?

How do I specifiy the time resolution consistently?

Martin Zabel
  • 3,589
  • 3
  • 19
  • 34
  • Worth noting there is a `cocotb.clock.Clock` class for convenience, which saves having to repeatedly define a `clock_gen` coroutine. – Chiggs Mar 31 '16 at 11:12

2 Answers2

3

No time resolution is specified for the vsim command within the runsim.do file generated by the Makefiles. Thus, the default time resolution of the simulator is used as specified in the modelsim.ini. One of the other VHDL projects had a private modelsim.ini with a time resolution set to 1 ps (Resolution = ps) instead of the default 1 ns (Resolution = ns).

Additional vsim arguments can be specified by the Makefile variable VSIM_ARGS of the Cocotb build system. But setting this variable on the command line with:

make SIM=questa GUI=1 "VSIM_ARGS=-t 1ps"

does not work as expected because other required vsim arguments have now been stripped of.

One has to set this variable in the project-specific Makefile instead, e.g., just before including the system-wide Makefiles:

VSIM_ARGS=-t 1ps

include $(COCOTB)/makefiles/Makefile.inc
include $(COCOTB)/makefiles/Makefile.sim

This way, one gets a consistent time resolution across VHDL and Verilog. The parameter has to be set for every project accordingly.

Martin Zabel
  • 3,589
  • 3
  • 19
  • 34
  • See also [issue 115](https://github.com/potentialventures/cocotb/issues/115) where we discuss defining time in absolute units, which would solve this at the Python level. After [#383](https://github.com/potentialventures/cocotb/pull/383) was merged we know the absolute time precision so defining timers in terms of units shouldn't be too difficult. – Chiggs Mar 31 '16 at 11:10
  • @Chiggs Regarding issue #383, is there already a Python function to call `vhpi_get_phys(vhpiResolutionLimitP, NULL)`? I didn't find one in the sources. – Martin Zabel Mar 31 '16 at 14:02
2

Since cocotb 1.3.0, you can use COCOTB_HDL_TIMEUNIT and COCOTB_HDL_TIMEPRECISION makefile variables to define timescale in a simulator agnostic way.

Bob
  • 13,867
  • 1
  • 5
  • 27