Skip to content

Commit

Permalink
genlib/cdc: add GrayDecoder
Browse files Browse the repository at this point in the history
sbourdeauducq committed Aug 2, 2016
1 parent d535f90 commit de2cbb6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions migen/genlib/cdc.py
Original file line number Diff line number Diff line change
@@ -143,3 +143,17 @@ def __init__(self, width):
self.q_binary.eq(self.q_next_binary),
self.q.eq(self.q_next)
]


class GrayDecoder(Module):
def __init__(self, width):
self.i = Signal(width)
self.o = Signal(width)

# # #

o_comb = Signal(width)
self.comb += o_comb[-1].eq(self.i[-1])
for i in reversed(range(width-1)):
self.comb += o_comb[i].eq(o_comb[i+1] ^ self.i[i])
self.sync += self.o.eq(o_comb)

0 comments on commit de2cbb6

Please sign in to comment.