Guest User

tb_counter

a guest
Jul 5th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #! ../env/bin/python
  2.  
  3. import argparse
  4.  
  5. from amaranth.sim import Simulator
  6.  
  7. from counter import Counter
  8.  
  9. parser = argparse.ArgumentParser(prog='Basic Amaranth Counter',
  10. description='Configures and tests a binary counter',
  11. epilog='Lets see if it works')
  12.  
  13. parser.add_argument('width', type=int, default=4, choices=range(1, 32), help='Bit width of the counter to create')
  14.  
  15. args = parser.parse_args()
  16.  
  17. dut = Counter(args.width)
  18.  
  19. def testbench():
  20. #What's our max val?
  21. maxval = (2**args.width) - 1
  22.  
  23. #Check that the enable works
  24. yield dut.en.eq(0)
  25. for _ in range(maxval + 1):
  26. yield
  27. assert not (yield dut.ovf)
  28.  
  29. #Enable it and check the counter
  30. yield dut.en.eq(1)
  31. for _ in range(maxval):
  32. yield
  33. assert not (yield dut.ovf)
  34. yield
  35. assert (yield dut.ovf)
  36.  
  37. #check that overflow clears on the next clock
  38. yield
  39. assert not (yield dut.ovf)
  40.  
  41.  
  42. if __name__ == "__main__":
  43. sim = Simulator(dut)
  44. sim.add_clock(1e-6)
  45. sim.add_sync_process(testbench)
  46.  
  47. with sim.write_vcd("counter.vcd"):
  48. sim.run()
Add Comment
Please, Sign In to add comment