-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pattern_pulser.py
51 lines (37 loc) · 1.27 KB
/
pattern_pulser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from amaranth import *
from amaranth.sim import *
class PatternPulser(Elaboratable):
def __init__(self):
self.out = Signal()
self.step = Signal(5)
self.ports = (self.out, self.step)
def elaborate(self, platform):
len_ctr = Signal(12, reset=1)
increment = Signal(8, reset=1)
cycle_ctr = Signal(12)
m = Module()
with m.If(cycle_ctr == 0xfff):
m.d.sync += len_ctr.eq(len_ctr + increment)
with m.If(len_ctr + increment > 0xfff):
with m.If(increment == 0x80):
m.d.sync += increment.eq(1)
m.d.sync += self.step.eq(1)
with m.Else():
m.d.sync += increment.eq(increment * 2)
m.d.sync += self.step.eq(self.step + 1)
m.d.sync += cycle_ctr.eq(cycle_ctr + 1)
m.d.comb += [
self.out.eq(cycle_ctr <= len_ctr)
]
return m
if __name__ == '__main__':
dut = PatternPulser()
sim = Simulator(dut)
def proc():
for i in range(256*256*3):
yield
sim.add_clock(1/12e6)
sim.add_sync_process(proc)
with sim.write_vcd('pattern_pulser.vcd', 'pattern_pulser.gtkw',
traces=dut.ports):
sim.run()