Skip to content

Commit 9113113

Browse files
author
neil.hamilton
committed
Update ps5000a.py with pulse width type enum
1 parent 75353e6 commit 9113113

File tree

2 files changed

+71
-17
lines changed

2 files changed

+71
-17
lines changed

picosdk/ps5000a.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _define_conditionsInfo():
148148

149149
return {k.upper(): v for k, v in locals().items() if k.startswith("PS5000A")}
150150

151-
PS5000AConditionsInfo = _define_conditionsInfo()
151+
ps5000a.PS5000AConditionsInfo = _define_conditionsInfo()
152152

153153
ps5000a.PS5000A_THRESHOLD_MODE = make_enum([
154154
"PS5000A_LEVEL",
@@ -169,6 +169,8 @@ def _define_conditionsInfo():
169169
'PS5000A_RATIO_MODE_AVERAGE': 4,
170170
}
171171

172+
ps5000a.PICO_RATIO_MODE = {k[19:]: v for k, v in ps5000a.PS5000A_RATIO_MODE.items()}
173+
172174
ps5000a.PS5000A_TIME_UNITS = make_enum([
173175
'PS5000A_FS',
174176
'PS5000A_PS',
@@ -179,7 +181,13 @@ def _define_conditionsInfo():
179181
'PS5000A_MAX_TIME_UNITS',
180182
])
181183

182-
ps5000a.PICO_RATIO_MODE = {k[19:]: v for k, v in ps5000a.PS5000A_RATIO_MODE.items()}
184+
ps5000a.PS5000A_PULSE_WIDTH_TYPE = make_enum([
185+
'PS5000A_PW_TYPE_NONE',
186+
'PS5000A_PW_TYPE_LESS_THAN',
187+
'PS5000A_PW_TYPE_GREATER_THAN',
188+
'PS5000A_PW_TYPE_IN_RANGE',
189+
'PS5000A_PW_TYPE_OUT_OF_RANGE',
190+
])
183191

184192

185193

ps5000aExamples/ps5000aBlockExample.py

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@
3838

3939
# Set up channel A
4040
# handle = chandle
41-
channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
41+
channelA = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
4242
# enabled = 1
4343
coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"]
44-
chARange = ps.PS5000A_RANGE["PS5000A_20V"]
44+
chARange = ps.PS5000A_RANGE["PS5000A_2V"]
4545
# analogue offset = 0 V
46-
status["setChA"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chARange, 0)
46+
status["setChA"] = ps.ps5000aSetChannel(chandle, channelA, 1, coupling_type, chARange, 0)
4747
assert_pico_ok(status["setChA"])
4848

4949
# Set up channel B
5050
# handle = chandle
51-
channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"]
51+
channelB = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"]
5252
# enabled = 1
5353
# coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"]
5454
chBRange = ps.PS5000A_RANGE["PS5000A_2V"]
5555
# analogue offset = 0 V
56-
status["setChB"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chBRange, 0)
56+
status["setChB"] = ps.ps5000aSetChannel(chandle, channelB, 1, coupling_type, chBRange, 0)
5757
assert_pico_ok(status["setChB"])
5858

5959
# find maximum ADC count value
@@ -63,16 +63,62 @@
6363
status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC))
6464
assert_pico_ok(status["maximumValue"])
6565

66-
# Set up single trigger
67-
# handle = chandle
68-
# enabled = 1
69-
source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
70-
threshold = int(mV2adc(500,chARange, maxADC))
71-
# direction = PS5000A_RISING = 2
72-
# delay = 0 s
73-
# auto Trigger = 1000 ms
74-
status["trigger"] = ps.ps5000aSetSimpleTrigger(chandle, 1, source, threshold, 2, 0, 1000)
75-
assert_pico_ok(status["trigger"])
66+
# Parameters
67+
chA=0 # channel A
68+
chB=1 # channel B
69+
maxADC = ctypes.c_int16(32767)
70+
NB=2 #NB=nConditions=nDirections=nChannelProperties
71+
rg=2000 # range of voltage in millivolt
72+
threshold=1000
73+
thresholdLower=0
74+
hyteresis=0
75+
window=False
76+
direction=2 # Rising
77+
78+
#CONDITIONS
79+
conditions = (ps.PS5000A_CONDITION * NB)()
80+
clear=0x00000001
81+
add=0x00000002
82+
cond_info=clear|add
83+
a = ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]
84+
conditions[0]= ps.PS5000A_CONDITION(channelA, ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"])
85+
conditions[1]= ps.PS5000A_CONDITION(channelB, ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"])
86+
status["maximumValue_"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC))
87+
assert_pico_ok(status["maximumValue_"])
88+
status["setTriggerChannelConditions_"] = ps.ps5000aSetTriggerChannelConditionsV2(chandle,
89+
ctypes.byref(conditions),
90+
NB,
91+
cond_info)
92+
assert_pico_ok(status["setTriggerChannelConditions_"])
93+
94+
# DIRECTIONS
95+
if window==True:
96+
th_mode=ps.PS5000A_THRESHOLD_MODE["PS5000A_WINDOW"]
97+
else:
98+
th_mode=ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]
99+
triggerDirections=(ps.PS5000A_DIRECTION * NB)()
100+
triggerDirections[0] = ps.PS5000A_DIRECTION(chA, direction, th_mode)
101+
triggerDirections[1] = ps.PS5000A_DIRECTION(chB, direction, th_mode)
102+
status["setTriggerChannelDirections_"] = ps.ps5000aSetTriggerChannelDirectionsV2(chandle, ctypes.byref(triggerDirections), NB)
103+
assert_pico_ok(status["setTriggerChannelDirections_"])
104+
105+
# PROPERTIES
106+
thUpper = mV2adc(threshold, chARange, maxADC)
107+
thLower = mV2adc(thresholdLower, chARange, maxADC)
108+
hysteresis=0
109+
triggerProperties = (ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2 * NB)()
110+
triggerProperties[0] = ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(thUpper,
111+
hysteresis,
112+
thLower,
113+
hysteresis,
114+
0)
115+
triggerProperties[1] = ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(thUpper,
116+
hysteresis,
117+
thLower,
118+
hysteresis,
119+
1)
120+
status["setTriggerChannelProperties_"] = ps.ps5000aSetTriggerChannelPropertiesV2(chandle, ctypes.byref(triggerProperties), NB, 0)
121+
assert_pico_ok(status["setTriggerChannelProperties_"])
76122

77123
# Set number of pre and post trigger samples to be collected
78124
preTriggerSamples = 2500

0 commit comments

Comments
 (0)