在 Chisel 文档中,我们有一个上升沿检测方法的示例,定义如下:
def risingedge(x: Bool) = x && !RegNext(x)
我的 github项目 blp上提供了所有示例代码。
如果我在声明如下的输入信号上使用它:
class RisingEdge extends Module {
val io = IO(new Bundle{
val sclk = Input(Bool())
val redge = Output(Bool())
val fedge = Output(Bool())
})
// seems to not work with icarus + cocotb
def risingedge(x: Bool) = x && !RegNext(x)
def fallingedge(x: Bool) = !x && RegNext(x)
// works with icarus + cocotb
//def risingedge(x: Bool) = x && !RegNext(RegNext(x))
//def fallingedge(x: Bool) = !x && RegNext(RegNext(x))
io.redge := risingedge(io.sclk)
io.fedge := fallingedge(io.sclk)
}
有了这个 icarus/cocotb 测试平台:
class RisingEdge(object):
def __init__(self, dut, clock):
self._dut = dut
self._clock_thread = cocotb.fork(clock.start())
@cocotb.coroutine
def reset(self):
short_per = Timer(100, units="ns")
self._dut.reset <= 1
self._dut.io_sclk <= 0
yield short_per
self._dut.reset <= 0
yield short_per
@cocotb.test()
def test_rising_edge(dut):
dut._log.info("Launching RisingEdge test")
redge = RisingEdge(dut, Clock(dut.clock, 1, "ns"))
yield redge.reset()
cwait = Timer(10, "ns")
for i in range(100):
dut.io_sclk <= 1
yield cwait
dut.io_sclk <= 0
yield cwait
我永远不会在 io.redge 和 io.fedge 上获得上升脉冲。要获得脉冲,我必须将上升沿的定义更改如下:
def risingedge(x: Bool) = x && !RegNext(RegNext(x))
这是正常行为吗?
[编辑:我用上面给出的 github 示例修改了源示例]