ps2405 API - Advanced OR trigger for channels C+D (Python)

Forum for discussing PicoScope version 6 (non-automotive version)
Post Reply
markokram
Newbie
Posts: 0
Joined: Wed Dec 22, 2021 4:50 pm

ps2405 API - Advanced OR trigger for channels C+D (Python)

Post by markokram »

Hi,

can you help me out with this code? I'm trying to get OR condition working with triggers in channels C OR D. Also, if you can provide overall tips on how to make AND, OR, and pulse width triggers (pwq+ps2000aSetTriggerDelay) work, I'd appreciate it a lot.

I'm using Python wrappers and at the moment. I got simple trigger work well, but my problem with this code is that it will trigger only on either channel, but not on both. I mean, when I test it, it seems to trigger only on D channel and never in C.

I provide only the code related to the trigger. Other parts of the data retrieval work just fine:

Code: Select all


from ctypes import byref
from picosdk.ps2000a import ps2000a as ps, \
     PS2000A_TRIGGER_CONDITIONS, PS2000A_TRIGGER_CHANNEL_PROPERTIES, \
     PS2000A_TRIGGER_CHANNEL_PROPERTIES, PS2000A_PWQ_CONDITIONS

# Channel C ...
triggerConditions1 = PS2000A_TRIGGER_CONDITIONS(0, 0, 1, 0, 0, 0, 0, 0)
ps.ps2000aSetTriggerChannelConditions(chandle, byref(triggerConditions1), 2)
# ... or D.
triggerConditions2 = PS2000A_TRIGGER_CONDITIONS(0, 0, 0, 1, 0, 0, 0, 0)
ps.ps2000aSetTriggerChannelConditions(chandle, byref(triggerConditions2), 2)

upper_threshold_bits = int(2**16 * (upper_threshold) / 100)
hysteresis = int(2.5 / 100 * upper_threshold_bits)
threshold_mode = ps.PS2000A_THRESHOLD_MODE["PS2000A_LEVEL"]

triggerProperties1 = PS2000A_TRIGGER_CHANNEL_PROPERTIES(
    upper_threshold_bits, hysteresis, 0, 0, ps.PS2000A_CHANNEL["PS2000A_CHANNEL_C"], threshold_mode
)

triggerProperties2 = PS2000A_TRIGGER_CHANNEL_PROPERTIES(
    upper_threshold_bits, hysteresis, 0, 0, ps.PS2000A_CHANNEL["PS2000A_CHANNEL_D"], threshold_mode
)

ps.ps2000aSetTriggerChannelProperties(chandle, byref(triggerProperties1), 1, 0, 1000)
ps.ps2000aSetTriggerChannelProperties(chandle, byref(triggerProperties2), 1, 0, 1000)

triggerDirection1 = ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_RISING"]
triggerDirection2 = ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_RISING"]

ps.ps2000aSetTriggerChannelDirections(chandle, 0, 0, triggerDirection1, 0, 0, 0)
ps.ps2000aSetTriggerChannelDirections(chandle, 0, 0, 0, triggerDirection2, 0, 0)

I have tried to look at the ps2000a.py file and manual, but they don't give me a good idea of what to do.

-Marko

markokram
Newbie
Posts: 0
Joined: Wed Dec 22, 2021 4:50 pm

Re: ps2405 API - Advanced OR trigger for channels C+D (Python)

Post by markokram »

I got this working with OR type of conditions, but could someone help, how to make it work with AND and XOR type of condition? In the example below I'm using A and B channels opposite to original topic C+D:

Code: Select all

from picosdk.ps2000a import ps2000a as ps, PS2000A_TRIGGER_CONDITIONS, PS2000A_TRIGGER_CHANNEL_PROPERTIES, PS2000A_PWQ_CONDITIONS

# Channel A OR B Advanced Trigger with ps2000a

chandle = ctypes.c_int16()

# Trick is to duplicate conditions and property schemas

trigger_conditions_n = 2

Condition = PS2000A_TRIGGER_CONDITIONS * trigger_conditions_n
trigger_conditions = Condition(
   PS2000A_TRIGGER_CONDITIONS(1, 0, 0, 0, 0, 0, 0, 0),
   PS2000A_TRIGGER_CONDITIONS(0, 1, 0, 0, 0, 0, 0, 0)
)

ps.ps2000aSetTriggerChannelConditions(chandle, byref(trigger_conditions), trigger_conditions_n)

upper_threshold = 2000 # mV
upper_hysteresis = 2.5 # %
# I'm not using lower threshold and hysteresis...
threshold_bits = int(2**16 * upper_threshold / 100)
hysteresis = int(upper_hysteresis / 100 * threshold_bits)
threshold_mode = ps.PS2000A_THRESHOLD_MODE["PS2000A_LEVEL"]

trigger_properties_n = 2

Property = PS2000A_TRIGGER_CHANNEL_PROPERTIES * trigger_properties_n 

trigger_properties = Property(
   PS2000A_TRIGGER_CHANNEL_PROPERTIES(
       threshold_bits, hysteresis, 0, 0, ps.PS2000A_CHANNEL["PS2000A_CHANNEL_A"], threshold_mode
   ),
   PS2000A_TRIGGER_CHANNEL_PROPERTIES(
       upper_threshold_bits, hysteresis, 0, 0, ps.PS2000A_CHANNEL["PS2000A_CHANNEL_B"], threshold_mode
   )
)

auto_trigger_ms = 200

ps.ps2000aSetTriggerChannelProperties(chandle, byref(trigger_properties), trigger_properties_n, 0, auto_trigger_ms)

triggerDirection = ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_RISING"]

# Trigger directions needs to be set separately.
ps.ps2000aSetTriggerChannelDirections(chandle, triggerDirection, 0, 0, 0, 0, 0)
ps.ps2000aSetTriggerChannelDirections(chandle, 0, triggerDirection, 0, 0, 0, 0)


Martyn
Site Admin
Site Admin
Posts: 4499
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: ps2405 API - Advanced OR trigger for channels C+D (Python)

Post by Martyn »

For AND you will need both channels to be in the same Trigger Conditions statement

Code: Select all

PS2000A_TRIGGER_CONDITIONS(1, 1, 0, 0, 0, 0, 0, 0),
For XOR you will need to use FALSE

Code: Select all

PS2000A_TRIGGER_CONDITIONS(1, 2, 0, 0, 0, 0, 0, 0),
PS2000A_TRIGGER_CONDITIONS(2, 1, 0, 0, 0, 0, 0, 0),
Martyn
Technical Support Manager

markokram
Newbie
Posts: 0
Joined: Wed Dec 22, 2021 4:50 pm

Re: ps2405 API - Advanced OR trigger for channels C+D (Python)

Post by markokram »

Cool, thanks!

With AND I'm a bit confuced about the time window when trigger works. Is it dependant of the time base meaning there must BE pulse exactly at the same index in the buffer?

-Marko

Post Reply