|
2 | 2 | # Copyright (C) 2018-2020 Pico Technology Ltd. See LICENSE file for terms. |
3 | 3 | # |
4 | 4 | # PS6000 BLOCK MODE ADVANCED TRIGGER EXAMPLE |
5 | | -# This example opens a 6000 driver device, sets up two channels and a level drop out advanced trigger then collects a block of data. |
| 5 | +# This example opens a 6000 driver device, sets up one channel and a window pulse width advanced trigger then collects a block of data. |
6 | 6 | # This data is then plotted as mV against time in ns. |
7 | 7 |
|
8 | 8 | import ctypes |
9 | 9 | import numpy as np |
10 | 10 | from picosdk.ps6000 import ps6000 as ps |
11 | 11 | import matplotlib.pyplot as plt |
12 | | -from picosdk.functions import adc2mV, assert_pico_ok |
| 12 | +from picosdk.functions import adc2mV, assert_pico_ok, mV2adc |
13 | 13 |
|
14 | 14 | # Create chandle and status ready for use |
15 | 15 | chandle = ctypes.c_int16() |
|
32 | 32 | status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0) |
33 | 33 | assert_pico_ok(status["setChA"]) |
34 | 34 |
|
35 | | -# Set up channel B |
36 | | -# handle = chandle |
37 | | -# channel = PS6000_CHANNEL_B = 1 |
38 | | -# enabled = 1 |
39 | | -# coupling type = PS6000_DC = 1 |
40 | | -# range = PS6000_2V = 7 |
41 | | -# analogue offset = 0 V |
42 | | -# bandwidth limiter = PS6000_BW_FULL = 0 |
43 | | -chBRange = 7 |
44 | | -status["setChB"] = ps.ps6000SetChannel(chandle, 1, 1, 1, chBRange, 0, 0) |
45 | | -assert_pico_ok(status["setChB"]) |
46 | | - |
47 | | -# Set up level drop out tirgger on A |
| 35 | +# Set up level drop out trigger on A |
48 | 36 | triggerConditions = ps.PS6000_TRIGGER_CONDITIONS(ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_TRUE"], |
49 | | - ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
50 | | - ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
51 | | - ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
52 | | - ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
53 | | - ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
54 | | - ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_TRUE"]) |
| 37 | + ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
| 38 | + ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
| 39 | + ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
| 40 | + ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
| 41 | + ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
| 42 | + ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_TRUE"]) |
55 | 43 | nTriggerConditions = 1 |
56 | 44 |
|
57 | 45 | status["setTriggerChannelConditions"] = ps.ps6000SetTriggerChannelConditions(chandle, ctypes.byref(triggerConditions), nTriggerConditions) |
58 | 46 | assert_pico_ok(status["setTriggerChannelConditions"]) |
59 | 47 |
|
60 | | -status["setTriggerChannelDirections"] = ps.ps6000SetTriggerChannelDirections(chandle, ps.PS6000_THRESHOLD_DIRECTION["PS6000_RISING_OR_FALLING"], ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], |
61 | | - ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"]. ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], |
62 | | - ps.PS6000_THRESHOLD_DIRECTION[PS6000_NONE"]) |
| 48 | +status["setTriggerChannelDirections"] = ps.ps6000SetTriggerChannelDirections(chandle, |
| 49 | + ps.PS6000_THRESHOLD_DIRECTION["PS6000_INSIDE"], |
| 50 | + ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], |
| 51 | + ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], |
| 52 | + ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], |
| 53 | + ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], |
| 54 | + ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"]) |
63 | 55 | assert_pico_ok(status["setTriggerChannelDirections"]) |
64 | 56 |
|
65 | 57 | maxADC = ctypes.c_int16(32512) |
66 | 58 | threshold = mV2adc(109.2, chARange, maxADC) |
67 | | -hysteresis = mV2adc(109.2 * 0.015), chARange, maxADC |
| 59 | +hysteresis = mV2adc((109.2 * 0.015), chARange, maxADC) |
68 | 60 | channelProperties = ps.PS6000_TRIGGER_CHANNEL_PROPERTIES(threshold, |
69 | | - hysteresis, |
70 | | - threshold, |
71 | | - hysteresis, |
72 | | - ps.PS6000_CHANNEL["PS6000_CHANNEL_A"], |
73 | | - ps.PS6000_THRESHOLD_MODE["PS6000_LEVEL"]) |
| 61 | + hysteresis, |
| 62 | + (threshold * -1), |
| 63 | + hysteresis, |
| 64 | + ps.PS6000_CHANNEL["PS6000_CHANNEL_A"], |
| 65 | + ps.PS6000_THRESHOLD_MODE["PS6000_WINDOW"]) |
74 | 66 | nChannelProperties = 1 |
75 | 67 | auxOutputEnable = 0 |
76 | | -autoTriggerMilliseconds = 1000 |
| 68 | +autoTriggerMilliseconds = 10000 |
77 | 69 | status["setTriggerChannelProperties"] = ps.ps6000SetTriggerChannelProperties(chandle, ctypes.byref(channelProperties), nChannelProperties, auxOutputEnable, autoTriggerMilliseconds) |
78 | 70 | assert_pico_ok(status["setTriggerChannelProperties"]) |
79 | 71 |
|
80 | | -pwqConditions = ps.PS6000_PWQ_CONDTIONS(ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_TRUE"], |
| 72 | +pwqConditions = ps.PS6000_PWQ_CONDITIONS(ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_TRUE"], |
81 | 73 | ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
82 | 74 | ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
83 | 75 | ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
84 | 76 | ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], |
85 | 77 | ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"]) |
86 | 78 | nPwqConditions = 1 |
87 | 79 | direction = ps.PS6000_THRESHOLD_DIRECTION["PS6000_RISING_OR_FALLING"] |
88 | | -lower = 390625 #samples at timebase 8 is 10 ms |
89 | | -upper = lower |
| 80 | +upper = 390625 #samples at timebase 8 is 10 ms |
| 81 | +lower = upper |
90 | 82 | type = ps.PS6000_PULSE_WIDTH_TYPE["PS6000_PW_TYPE_GREATER_THAN"] |
91 | 83 | status["setPulseWidthQualifier"] = ps.ps6000SetPulseWidthQualifier(chandle, ctypes.byref(pwqConditions), nPwqConditions, direction, lower, upper, type) |
92 | 84 | assert_pico_ok(status["setPulseWidthQualifier"]) |
93 | 85 |
|
94 | 86 | # Set number of pre and post trigger samples to be collected |
95 | | -preTriggerSamples = 2500 |
96 | | -postTriggerSamples = 2500 |
| 87 | +preTriggerSamples = 390625*2 |
| 88 | +postTriggerSamples = 390625 |
97 | 89 | maxSamples = preTriggerSamples + postTriggerSamples |
98 | 90 |
|
99 | 91 | # Get timebase information |
|
145 | 137 | status["setDataBuffersA"] = ps.ps6000SetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0) |
146 | 138 | assert_pico_ok(status["setDataBuffersA"]) |
147 | 139 |
|
148 | | -# Set data buffer location for data collection from channel B |
149 | | -# handle = chandle |
150 | | -# source = PS6000_CHANNEL_B = 1 |
151 | | -# pointer to buffer max = ctypes.byref(bufferBMax) |
152 | | -# pointer to buffer min = ctypes.byref(bufferBMin) |
153 | | -# buffer length = maxSamples |
154 | | -# ratio mode = PS6000_RATIO_MODE_NONE = 0 |
155 | | -status["setDataBuffersB"] = ps.ps6000SetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0) |
156 | | -assert_pico_ok(status["setDataBuffersB"]) |
157 | | - |
158 | 140 | # create overflow loaction |
159 | 141 | overflow = ctypes.c_int16() |
160 | 142 | # create converted type maxSamples |
|
175 | 157 |
|
176 | 158 | # convert ADC counts data to mV |
177 | 159 | adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) |
178 | | -adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) |
179 | 160 |
|
180 | 161 | # Create time data |
181 | 162 | time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value) |
182 | 163 |
|
183 | | -# plot data from channel A and B |
| 164 | +# plot data from channel A |
184 | 165 | plt.plot(time, adc2mVChAMax[:]) |
185 | | -plt.plot(time, adc2mVChBMax[:]) |
186 | 166 | plt.xlabel('Time (ns)') |
187 | 167 | plt.ylabel('Voltage (mV)') |
188 | 168 | plt.show() |
|
0 commit comments