chisel2-deprecated
chisel2-deprecated copied to clipboard
Waveforms are incorrect with multiple clock domains
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:

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.
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);