2015-09-12 07:34:07 -04:00
|
|
|
from migen import *
|
2012-03-05 14:31:41 -05:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2015-09-11 00:44:14 -04:00
|
|
|
# Our simple counter, which increments at every cycle.
|
2013-07-24 12:47:25 -04:00
|
|
|
class Counter(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self):
|
|
|
|
self.count = Signal(4)
|
2013-07-24 12:47:25 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
# At each cycle, increase the value of the count signal.
|
|
|
|
# We do it with convertible/synthesizable FHDL code.
|
|
|
|
self.sync += self.count.eq(self.count + 1)
|
2014-10-17 05:08:37 -04:00
|
|
|
|
2015-09-11 00:44:14 -04:00
|
|
|
|
|
|
|
# Simply read the count signal and print it.
|
|
|
|
# The output is:
|
|
|
|
# Count: 0
|
|
|
|
# Count: 1
|
|
|
|
# Count: 2
|
|
|
|
# ...
|
|
|
|
def counter_test(dut):
|
|
|
|
for i in range(20):
|
|
|
|
print((yield dut.count)) # read and print
|
|
|
|
yield # next clock cycle
|
|
|
|
# simulation ends with this generator
|
|
|
|
|
2012-03-05 14:31:41 -05:00
|
|
|
|
2014-01-26 16:19:43 -05:00
|
|
|
if __name__ == "__main__":
|
2015-04-13 14:07:07 -04:00
|
|
|
dut = Counter()
|
2015-09-11 00:44:14 -04:00
|
|
|
Simulator(dut, counter_test(dut)).run()
|