Skip to content

Commit f9fbc92

Browse files
gateware.ripple: add support for a ripple counter, with external clock
1 parent 6bb037e commit f9fbc92

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import logging
2+
from nmigen import *
3+
4+
__all__ = ["RippleCounter"]
5+
6+
class RippleCounter(Elaboratable):
7+
def __init__(self, clk, clk_en=None, rst=None, width=8, logger=None):
8+
self.logger = logger or logging.getLogger(__name__)
9+
self.clk = clk
10+
self.clk_en = clk_en
11+
self.rst = rst
12+
self.width = width
13+
self.count = Signal(width)
14+
15+
def elaborate(self, platform):
16+
if not hasattr(platform, "get_ripple_ff_stage"):
17+
raise NotImplementedError("No Ripple Counter support for platform")
18+
19+
m = Module()
20+
21+
clk_chain = self.clk
22+
23+
for i in range(self.width):
24+
d_out = Signal()
25+
clk_en = self.clk_en if i == 0 else None
26+
m.submodules += platform.get_ripple_ff_stage(d_out, clk_chain, clk_en, self.rst)
27+
m.d.comb += self.count[i].eq(d_out)
28+
clk_chain = d_out
29+
30+
return m

0 commit comments

Comments
 (0)