graycounter: expose binary output
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 25 Apr 2013 11:11:15 +0000 (13:11 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 25 Apr 2013 11:11:15 +0000 (13:11 +0200)
examples/basic/graycounter.py
migen/genlib/cdc.py

index bfc30f56ac721543f4babba496aa93d12f300b27..f623fbf786d87ff7c7488ad24683afae9f46d2f5 100644 (file)
@@ -11,8 +11,8 @@ class TB(Module):
                self.prng = Random(7345)
 
        def do_simulation(self, s):
-               print("{0:0{1}b} CE={2}".format(s.rd(self.gc.q),
-                       self.width, s.rd(self.gc.ce)))
+               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)))
                s.wr(self.gc.ce, self.prng.getrandbits(1))
 
 sim = Simulator(TB())
index 13612cfec5eedeed3d4c4fe3db52b9f1a4510bff..9569e013e3851fa765384ca6cd124d1164dfa8ca 100644 (file)
@@ -78,20 +78,20 @@ class GrayCounter(Module):
                self.ce = Signal()
                self.q = Signal(width)
                self.q_next = Signal(width)
+               self.q_binary = Signal(width)
+               self.q_next_binary = Signal(width)
 
                ###
 
-               q_binary = Signal(width)
-               q_next_binary = Signal(width)
                self.comb += [
                        If(self.ce,
-                               q_next_binary.eq(q_binary + 1)
+                               self.q_next_binary.eq(self.q_binary + 1)
                        ).Else(
-                               q_next_binary.eq(q_binary)
+                               self.q_next_binary.eq(self.q_binary)
                        ),
-                       self.q_next.eq(q_next_binary ^ q_next_binary[1:])
+                       self.q_next.eq(self.q_next_binary ^ self.q_next_binary[1:])
                ]
                self.sync += [
-                       q_binary.eq(q_next_binary),
+                       self.q_binary.eq(self.q_next_binary),
                        self.q.eq(self.q_next)
                ]