chisel2-deprecated icon indicating copy to clipboard operation
chisel2-deprecated copied to clipboard

Waveforms are incorrect with multiple clock domains

Open jbush001 opened this issue 10 years ago • 1 comments

Given the following code:

val clkA = new Clock()
val clkB = new Clock()
val regA = Reg(outType=Bool(), init=Bool(false), clock = clkA)
val regB = Reg(outType=Bool(), init=Bool(false), clock = clkB)
regA := !regA
regB := !regB

Driven by a test harness:

  setClocks(HashMap(Driver.implicitClock -> 5, c.clkA -> 6, c.clkB -> 7))
  step(100) 

The waveform is lumpy and uneven:

screen shot 2015-07-25 at 2 47 25 pm

The problem is that mod_t::step() calls the generated clock() function, which can advance multiple timesteps, but mod_t::dump() only advances one time step per call:

  int step (bool is_reset, int n) {
      ...
      dump();
      delta += clock(reset);
      ...

  void dump () {
    if (dumpfile != NULL) dump(dumpfile, timestep);
    timestep += 1;
  }

The proper fix is to advance the dump timestep by the number of steps returned from clock. However, this would require reordering the logic.

jbush001 avatar Jul 25 '15 21:07 jbush001

This works correctly when I created my own C++ test harness with the following code:

int numIntervals = module->clock(dat_t<1>(0));
currentTime += numIntervals;
module->dump(waveformFile, currentTime);

jbush001 avatar Jul 25 '15 22:07 jbush001