-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhall_testbench.py
73 lines (59 loc) · 2.07 KB
/
hall_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
from migen import *
from migen.genlib.resetsync import AsyncResetSynchronizer
import esc
def print_state(dut):
print(f"hall = {(yield dut.hall)}")
print(f"dir = {(yield dut.dir)}")
print(f"strobe = {(yield dut.strobe)}")
print(f"hall_glitch = {(yield dut.hall_glitch)}")
print(f"phase_observation = {(yield dut.phase_observation)}")
#print(f"hall_prev = {(yield dut.hall_prev)}")
#print(f"hall_error = {(yield dut.hall_error)}")
#print(f"hall_error_prev = {(yield dut.hall_error_prev)}")
#print(f"hall_idx = {(yield dut.hall_idx)}")
#print(f"hall_idx_prev = {(yield dut.hall_idx_prev)}")
#print(f"dir_prev = {(yield dut.dir_prev)}")
def test_0(dut):
pt=esc.phase_table(phase_max=12)
hall_seq = [1,3,2,6,4,5]
hall_seq = hall_seq + hall_seq
yield dut.hall.eq(hall_seq[-1])
yield
assert (yield dut.hall_glitch) == 1 # transition from zero has no defined position
assert (yield dut.strobe) == 0 # exiting error state, don't strobe
yield
assert (yield dut.hall_glitch) == 0 # settled inputs with valid state
assert (yield dut.strobe) == 0 # strobe is off for settled input
for h in hall_seq:
print("forward")
yield dut.hall.eq(h)
yield
yield from print_state(dut)
assert (yield dut.strobe) == 1 # strobe is on after valid transition
yield
yield from print_state(dut)
assert (yield dut.strobe) == 0 # strobe is off for settled input
yield
yield from print_state(dut)
yield dut.hall.eq(hall_seq[0])
yield
yield
hall_seq.reverse()
for h in hall_seq:
print("reverse")
yield dut.hall.eq(h)
yield
yield from print_state(dut)
assert (yield dut.strobe) == 1 # strobe is on after valid transition
yield
yield from print_state(dut)
assert (yield dut.strobe) == 0 # strobe is off for settled input
yield
yield from print_state(dut)
def testbench(dut):
print("testing hall observer device")
yield from test_0(dut)
if __name__ == "__main__":
pt=esc.phase_table(phase_max=12)
hall_observer = esc.ObserverHall(pt)
run_simulation(hall_observer, testbench(hall_observer))