Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! ../env/bin/python
- import argparse
- from amaranth.sim import Simulator
- from counter import Counter
- parser = argparse.ArgumentParser(prog='Basic Amaranth Counter',
- description='Configures and tests a binary counter',
- epilog='Lets see if it works')
- parser.add_argument('width', type=int, default=4, choices=range(1, 32), help='Bit width of the counter to create')
- args = parser.parse_args()
- dut = Counter(args.width)
- def testbench():
- #What's our max val?
- maxval = (2**args.width) - 1
- #Check that the enable works
- yield dut.en.eq(0)
- for _ in range(maxval + 1):
- yield
- assert not (yield dut.ovf)
- #Enable it and check the counter
- yield dut.en.eq(1)
- for _ in range(maxval):
- yield
- assert not (yield dut.ovf)
- yield
- assert (yield dut.ovf)
- #check that overflow clears on the next clock
- yield
- assert not (yield dut.ovf)
- if __name__ == "__main__":
- sim = Simulator(dut)
- sim.add_clock(1e-6)
- sim.add_sync_process(testbench)
- with sim.write_vcd("counter.vcd"):
- sim.run()
Add Comment
Please, Sign In to add comment