amaranth/examples/ctr.py

20 lines
419 B
Python
Raw Normal View History

from nmigen import *
from nmigen.cli import main, pysim
2018-12-11 13:50:56 -07:00
class Counter:
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])