Skip to content

Commit de2cbb6

Browse files
committedAug 2, 2016
genlib/cdc: add GrayDecoder
1 parent d535f90 commit de2cbb6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎migen/genlib/cdc.py

+14
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,17 @@ def __init__(self, width):
143143
self.q_binary.eq(self.q_next_binary),
144144
self.q.eq(self.q_next)
145145
]
146+
147+
148+
class GrayDecoder(Module):
149+
def __init__(self, width):
150+
self.i = Signal(width)
151+
self.o = Signal(width)
152+
153+
# # #
154+
155+
o_comb = Signal(width)
156+
self.comb += o_comb[-1].eq(self.i[-1])
157+
for i in reversed(range(width-1)):
158+
self.comb += o_comb[i].eq(o_comb[i+1] ^ self.i[i])
159+
self.sync += self.o.eq(o_comb)

0 commit comments

Comments
 (0)
Please sign in to comment.