Skip to content

Commit 2c5a2cd

Browse files
author
neil.hamilton
committed
Complete the window pulse width advanced trigger setup
1 parent 54e4d2c commit 2c5a2cd

File tree

1 file changed

+29
-49
lines changed

1 file changed

+29
-49
lines changed

ps6000Examples/ps6000BlockAdvancedTriggerExample.py

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# Copyright (C) 2018-2020 Pico Technology Ltd. See LICENSE file for terms.
33
#
44
# 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.
66
# This data is then plotted as mV against time in ns.
77

88
import ctypes
99
import numpy as np
1010
from picosdk.ps6000 import ps6000 as ps
1111
import matplotlib.pyplot as plt
12-
from picosdk.functions import adc2mV, assert_pico_ok
12+
from picosdk.functions import adc2mV, assert_pico_ok, mV2adc
1313

1414
# Create chandle and status ready for use
1515
chandle = ctypes.c_int16()
@@ -32,68 +32,60 @@
3232
status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0)
3333
assert_pico_ok(status["setChA"])
3434

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
4836
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"])
5543
nTriggerConditions = 1
5644

5745
status["setTriggerChannelConditions"] = ps.ps6000SetTriggerChannelConditions(chandle, ctypes.byref(triggerConditions), nTriggerConditions)
5846
assert_pico_ok(status["setTriggerChannelConditions"])
5947

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"])
6355
assert_pico_ok(status["setTriggerChannelDirections"])
6456

6557
maxADC = ctypes.c_int16(32512)
6658
threshold = mV2adc(109.2, chARange, maxADC)
67-
hysteresis = mV2adc(109.2 * 0.015), chARange, maxADC
59+
hysteresis = mV2adc((109.2 * 0.015), chARange, maxADC)
6860
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"])
7466
nChannelProperties = 1
7567
auxOutputEnable = 0
76-
autoTriggerMilliseconds = 1000
68+
autoTriggerMilliseconds = 10000
7769
status["setTriggerChannelProperties"] = ps.ps6000SetTriggerChannelProperties(chandle, ctypes.byref(channelProperties), nChannelProperties, auxOutputEnable, autoTriggerMilliseconds)
7870
assert_pico_ok(status["setTriggerChannelProperties"])
7971

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"],
8173
ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"],
8274
ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"],
8375
ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"],
8476
ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"],
8577
ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"])
8678
nPwqConditions = 1
8779
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
9082
type = ps.PS6000_PULSE_WIDTH_TYPE["PS6000_PW_TYPE_GREATER_THAN"]
9183
status["setPulseWidthQualifier"] = ps.ps6000SetPulseWidthQualifier(chandle, ctypes.byref(pwqConditions), nPwqConditions, direction, lower, upper, type)
9284
assert_pico_ok(status["setPulseWidthQualifier"])
9385

9486
# Set number of pre and post trigger samples to be collected
95-
preTriggerSamples = 2500
96-
postTriggerSamples = 2500
87+
preTriggerSamples = 390625*2
88+
postTriggerSamples = 390625
9789
maxSamples = preTriggerSamples + postTriggerSamples
9890

9991
# Get timebase information
@@ -145,16 +137,6 @@
145137
status["setDataBuffersA"] = ps.ps6000SetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0)
146138
assert_pico_ok(status["setDataBuffersA"])
147139

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-
158140
# create overflow loaction
159141
overflow = ctypes.c_int16()
160142
# create converted type maxSamples
@@ -175,14 +157,12 @@
175157

176158
# convert ADC counts data to mV
177159
adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC)
178-
adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC)
179160

180161
# Create time data
181162
time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value)
182163

183-
# plot data from channel A and B
164+
# plot data from channel A
184165
plt.plot(time, adc2mVChAMax[:])
185-
plt.plot(time, adc2mVChBMax[:])
186166
plt.xlabel('Time (ns)')
187167
plt.ylabel('Voltage (mV)')
188168
plt.show()

0 commit comments

Comments
 (0)