Advanced trigger on two channels via Python wrappers

Post general discussions on using our drivers to write your own software here
Post Reply
Posts: 0
Joined: Sat Jun 19, 2021 11:13 pm

Advanced trigger on two channels via Python wrappers

Post by rileyle »

I would like to acquire data in rapid block mode with an advanced trigger consisting of a logical OR of simple rising level-based triggers on channel A and B. As I understand the API documentation, I should configure my triggers with calls to the ps5000aSetTriggerChannelPropertiesV2(), ps5000aSetTriggerChannelConditionsV2(), and ps5000aSetTriggerChannelDirectionsV2() functions, and that if I call ps5000aSetTriggerChannelConditionsV2() for each of my channel triggers, they will be combined as a logical OR. The triggering code below leads to traces from both channels, but they are not triggered -- the maximum voltages in most traces are below the specified thresholds for both channels.

I have tested the advanced triggering function calls below with each channel separately, and they work. I can also get the behavior I am looking for with PicoScope 6 using the logical triggering menu, so it's clear that the hardware has the capability.

I would be grateful for any assistance.


Code: Select all

channelA = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
channelB = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_"]
mode = ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]
state_true = ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]
clear = 0b00000001
add = 0b00000010
clearadd = 0b00000011

trigConditionA  = [ps.PS5000A_CONDITION(channelA, state_true]
trigPropertiesA = [ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(thresholdA, 0, thresholdA, 0, channelA)]
trigDirectionA  = [ps.PS5000A_DIRECTION(channelA, dir, mode)]
trigConditionB  = [ps.PS5000A_CONDITION(channelB, state_true)]
trigPropertiesB = [ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(thresholdB, 0, thresholdB, 0, channelB)]
trigDirectionB  = [ps.PS5000A_DIRECTION(channelB, dir, mode)]

assert_pico_ok(ps.ps5000aSetTriggerChannelPropertiesV2(self._handle, ctypes.byref(trigPropertiesA[0]), 1, 0))
assert_pico_ok(ps.ps5000aSetTriggerChannelPropertiesV2(self._handle, ctypes.byref(trigPropertiesB[0]), 1, 0))
assert_pico_ok(ps.ps5000aSetTriggerChannelConditionsV2(self._handle, ctypes.byref(trigConditionA[0]), 1, clearadd))
assert_pico_ok(ps.ps5000aSetTriggerChannelConditionsV2(self._handle, ctypes.byref(trigConditionB[0]), 1, add))
assert_pico_ok(ps.ps5000aSetTriggerChannelDirectionsV2(self._handle, ctypes.byref(trigDirectionA[0]), 1))
assert_pico_ok(ps.ps5000aSetTriggerChannelDirectionsV2(self._handle, ctypes.byref(trigDirectionB[0]), 1))

Posts: 0
Joined: Sat Jun 19, 2021 11:13 pm

Re: Advanced trigger on two channels via Python wrappers

Post by rileyle »

Posting my own solution -- of possible use to others.

Multiple properties and directions packed in arrays (passed by reference) are OR'ed. The trigger conditions require multiple calls to OR them.

Code: Select all

channelA = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
channelB = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"]
mode     = ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]

Direction2       = ps.PS5000A_DIRECTION*2 # see ctypes docs
trigDirectionAB  = Direction2(ps.PS5000A_DIRECTION(channelA, dir, mode),
                              ps.PS5000A_DIRECTION(channelB, dir, mode))

thresholdA = self._rescale_V_to_adc('A', threshold)
thresholdB = self._rescale_V_to_adc('B', threshold)
trigPropertiesAB = \
                                                   0, 0, 0, channelA),
                                                   0, 0, 0, channelB))

state_true      = ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]
trigConditionA  = ps.PS5000A_CONDITION(channelA, state_true)
trigConditionB  = ps.PS5000A_CONDITION(channelB, state_true)

# Multiple directions/properties: logical OR
                                   ctypes.byref(trigDirectionAB), 2))
                               ctypes.byref(trigPropertiesAB), 2, 0))

clear     = 1 # 0b00000001
add       = 2 # 0b00000010
# Multiple conditions: Logical AND; Multiple calls: logical OR
                       ctypes.byref(trigConditionA), 1, (clear+add)))
                              ctypes.byref(trigConditionB), 1, add))
assert_pico_ok(ps.ps5000aSetAutoTriggerMicroSeconds(self._handle, 0))

Post Reply