-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_logic-pattern.py
63 lines (45 loc) · 1.66 KB
/
test_logic-pattern.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
from WF_SDK import device, logic, pattern, error # import instruments
import matplotlib.pyplot as plt # needed for plotting
from time import sleep # needed for delays
"""-----------------------------------------------------------------------"""
DIO_IN = 0
DIO_OUT = 0
try:
# connect to the device
device_data = device.open()
"""-----------------------------------"""
# initialize the logic analyzer with default settings
logic.open(device_data)
# set up triggering on DIO0 falling edge
logic.trigger(device_data, enable=True, channel=0, rising_edge=False)
# generate a 100KHz PWM signal with 30% duty cycle on a DIO channel
pattern.generate(device_data, channel=DIO_OUT, function=pattern.function.pulse, frequency=100e03, duty_cycle=30)
sleep(1) # wait 1 second
# record a logic signal on a DIO channel
buffer = logic.record(device_data, channel=DIO_IN)
# limit displayed data size
length = len(buffer)
if length > 10000:
length = 10000
buffer = buffer[0:length]
# generate buffer for time moments
time = []
for index in range(length):
time.append(index * 1e06 / logic.data.sampling_frequency) # convert time to μs
# plot
plt.plot(time, buffer)
plt.xlabel("time [μs]")
plt.ylabel("logic value")
plt.yticks([0, 1])
plt.show()
# reset the logic analyzer
logic.close(device_data)
# reset the pattern generator
pattern.close(device_data)
"""-----------------------------------"""
# close the connection
device.close(device_data)
except error as e:
print(e)
# close the connection
device.close(device.data)