2013-04-24 13:13:36 -04:00
|
|
|
from random import Random
|
|
|
|
|
2013-05-22 11:11:09 -04:00
|
|
|
from migen.fhdl.std import *
|
2013-04-24 13:13:36 -04:00
|
|
|
from migen.genlib.cdc import GrayCounter
|
|
|
|
from migen.sim.generic import Simulator
|
|
|
|
|
|
|
|
class TB(Module):
|
|
|
|
def __init__(self, width=3):
|
|
|
|
self.width = width
|
|
|
|
self.submodules.gc = GrayCounter(self.width)
|
|
|
|
self.prng = Random(7345)
|
|
|
|
|
|
|
|
def do_simulation(self, s):
|
2013-04-25 07:11:15 -04:00
|
|
|
print("{0:0{1}b} CE={2} bin={3}".format(s.rd(self.gc.q),
|
|
|
|
self.width, s.rd(self.gc.ce), s.rd(self.gc.q_binary)))
|
2013-04-24 13:13:36 -04:00
|
|
|
s.wr(self.gc.ce, self.prng.getrandbits(1))
|
|
|
|
|
|
|
|
sim = Simulator(TB())
|
|
|
|
sim.run(35)
|