-
Notifications
You must be signed in to change notification settings - Fork 1
/
ppm_input_testbench.py
89 lines (69 loc) · 1.97 KB
/
ppm_input_testbench.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from migen import *
from migen.genlib.resetsync import AsyncResetSynchronizer
import ppm
def print_state(dut):
print(f"prescaler = {(yield dut.prescaler)}")
print(f"active = {(yield dut.active)}")
print(f"ppm = {(yield dut.ppm)}")
print(f"ppm_prev = {(yield dut.ppm_prev)}")
print(f"channel_counter = {(yield dut.channel_counter)}")
print(f"timer = {(yield dut.timer)}")
for chan in range(dut.channels):
print(f"width_{chan} = {(yield dut.widths[chan])}")
def skip_us(dut, us):
print(f"{us} us")
for _ in range(us*dut.prescale):
yield
def test_0(dut):
print(f"blanking time = {(dut.blanking_timeout)}")
print('testing prescaler')
yield
yield
yield
assert (yield dut.prescaler) > 0
yield
yield from print_state(dut)
print("ppm on")
yield dut.ppm.eq(1)
yield from skip_us(dut, 1)
yield from print_state(dut)
yield from skip_us(dut, 299)
print("ppm off")
yield dut.ppm.eq(0)
yield from print_state(dut)
yield from skip_us(dut, 1)
yield from print_state(dut)
yield from skip_us(dut, 700)
print("ppm on")
yield dut.ppm.eq(1)
yield from skip_us(dut, 1)
yield from print_state(dut)
yield from skip_us(dut, 4001)
yield from print_state(dut)
print("ppm off")
yield dut.ppm.eq(0)
yield from skip_us(dut, 1)
yield from print_state(dut)
print("ppm on")
yield dut.ppm.eq(1)
yield from skip_us(dut, 1)
yield from print_state(dut)
def testbench(dut):
print("testing ppm_input device")
yield from test_0(dut)
if __name__ == "__main__":
channels=8
timeout=4000e3
frequency=50
clk_period=1e9/16e6
resolution=1e3
pulse_width=300e3
max_width=2000e3
min_width=500e3
ppm_input = ppm.PPMinput(
channels=channels,
timeout=timeout,
clk_period=clk_period,
resolution=resolution
)
run_simulation(ppm_input, testbench(ppm_input))