Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Memory behaviour in simulation #34

Closed
adamgreig opened this issue Feb 1, 2019 · 0 comments
Closed

Unexpected Memory behaviour in simulation #34

adamgreig opened this issue Feb 1, 2019 · 0 comments

Comments

@adamgreig
Copy link
Contributor

adamgreig commented Feb 1, 2019

I noticed in my design that two memories, both defined the same way and in the same clock domain, seemed to have different write behaviours:

This first one is what I'd expect: one cycle after addr=2 and data=2, mem(2) gets the value 2:

image

This is the weird one: last cycle's data is written to this cycle's slot:

image

I made a small reproduction of the buggy case:

from nmigen import Module, Memory, Signal
from nmigen.back import pysim

def test_mem():
    m = Module()
    mem = Memory(8, 32)
    m.submodules.wrport = wrport = mem.write_port()
    ctr = Signal(4)
    m.d.sync += [
        wrport.data.eq(ctr + 0x30),
        wrport.addr.eq(ctr),
        wrport.en.eq(1),
        ctr.eq(ctr + 1),
    ]

    vcdf = open("membug.vcd", "w")
    with pysim.Simulator(m, vcd_file=vcdf) as sim:
        def testbench():
            for _ in range(5):
                yield
            for idx in range(5):
                print(idx, ":", hex((yield mem[idx])))
        sim.add_clock(1e-6)
        sim.add_sync_process(testbench())
        sim.run()

if __name__ == "__main__":
    test_mem()

image

Moving the assignments to wrport.addr and wrport.data into a comb block restores the expected behaviour, so I guess it's to do with the addr/data being driven from a sync block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants