amaranth/examples/basic/ctr.py

20 lines
430 B
Python
Raw Normal View History

2021-12-09 22:39:50 -07:00
from amaranth import *
from amaranth.cli import main
2018-12-11 13:50:56 -07:00
class Counter(Elaboratable):
def __init__(self, width):
self.v = Signal(width, reset=2**width-1)
2018-12-11 13:50:56 -07:00
self.o = Signal()
def elaborate(self, platform):
m = Module()
m.d.sync += self.v.eq(self.v + 1)
m.d.comb += self.o.eq(self.v[-1])
return m
2018-12-11 13:50:56 -07:00
ctr = Counter(width=16)
if __name__ == "__main__":
main(ctr, ports=[ctr.o])