Setting advanced trigger for PicoScope 4824

Post your .Net discussions here
Post Reply
RamonG
Newbie
Posts: 0
Joined: Wed May 13, 2015 8:24 pm

Setting advanced trigger for PicoScope 4824

Post by RamonG »

Hi,

I'm working on a block mode example. I've got it working fine using ps4000aSetSimpleTrigger function to configure a trigger, but I really need a windowing method to monitor a dc value to be between two limits.

I'm trying to configure trigger using functions

ps4000SetTriggerChannelConditions
ps4000SetTriggerChannelDirections
ps4000SetTriggerChannelProperties

but error code are returned and I'm no sure why. Here is my portion of code in which I have declared triggers.

Imports.TriggerConditions[] conditions = new Imports.TriggerConditions[1];
conditions[0].Source = Imports.Channel.CHANNEL_A;
conditions[0].Condition = Imports.TriggerState.DontCare;
status = Imports.SetTriggerChannelConditions(handle, ref conditions, 1, Imports.INFO.Add);
// it returned 0 means, so SetTriggerChannelCondition call should be fine

Imports.TriggerDirections[] directions = new Imports.TriggerDirections[1];
directions[0].Direction = Imports.ThresholdDirection.Exit;
directions[0].Source = Imports.Channel.CHANNEL_A;
status = Imports.SetTriggerChannelDirections((short)handle, ref directions, (short)(1));
//it returned 16

Imports.TriggerChannelProperties[] properties = new Imports.TriggerChannelProperties[1];
properties[0].Channel = Imports.Channel.CHANNEL_A;
properties[0].ThresholdMinor = mv_to_adc(200, Imports.Range.Range_10V);
properties[0].ThresholdMajor = mv_to_adc(600, Imports.Range.Range_10V);
properties[0].ThresholdMode = Imports.ThresholdMode.Window;
properties[0].HysteresisMajor = 256;
properties[0].HysteresisMinor = 256;
status = Imports.SetTriggerChannelProperties(handle, ref properties, 1, 0, 0);
//it returned 73

Thanks for any help.
Ramon

Hitesh

Re: Setting advanced trigger for PicoScope 4824

Post by Hitesh »

Hi Ramon,

Referring to the picoStatus.h header file in the SDK, the status code of 16 is 0x10 in Hex, indicating 'PICO_INVALID_CHANNEL'.

Have you enabled the channel using ps4000aSetChannel?

Regarding error code 73, this is 0x49 - 'PICO_INVALID_TRIGGER_PROPERTY'.

What are the numerical values calculated in the code for properties[0].ThresholdMinor and properties[0].ThresholdMajor?

In the function call try:

Code: Select all

status = Imports.SetTriggerChannelProperties(handle, ref properties, (short) 1, (short) 0, 0);
Regards,

RamonG
Newbie
Posts: 0
Joined: Wed May 13, 2015 8:24 pm

Re: Setting advanced trigger for PicoScope 4824

Post by RamonG »

Hi Hitesh,

Yes, I have enabled the channel and return code is 0 (channel is successfully enabled), see my code below.

Code: Select all

status = Imports.SetChannel(handle, Imports.Channel.CHANNEL_A, 1, (short)Imports.coupling.DC, Imports.Range.Range_10V, 0);
//return status = 0 


The numerical values for ThresholdMinor and ThresholdMajor are 655 and 1966, I have replaced the mv_to_adc function with the actual values, I have also update the call as you suggested but I'm still getting error code 73 (PICO_INVALID_TRIGGER_PROPERTY). See my code below.

Code: Select all

Imports.TriggerChannelProperties[] properties = new Imports.TriggerChannelProperties[1];
properties[0].Channel = Imports.Channel.CHANNEL_A;
properties[0].ThresholdMinor = 655; // mv_to_adc(200, Imports.Range.Range_10V); 
properties[0].ThresholdMajor = 1966; // mv_to_adc(600, Imports.Range.Range_10V);
properties[0].ThresholdMode = Imports.ThresholdMode.Window;
properties[0].HysteresisMajor = 256;
properties[0].HysteresisMinor = 256;
status = Imports.SetTriggerChannelProperties(handle, ref properties, (short)1, (short)0, 0);
Thank you for helping.
Ramon

RamonG
Newbie
Posts: 0
Joined: Wed May 13, 2015 8:24 pm

Re: Setting advanced trigger for PicoScope 4824

Post by RamonG »

Hi Hitesh, do you have a code sample showing how to use advanced triggering function is block mode. I have tried to fix my source during last days but at this point I don't have any progress, I'm in the same point as before.

Thank you for helping,
Ramon.

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

Re: Setting advanced trigger for PicoScope 4824

Post by Martyn »

Please use the modified Imports file

[The extension cs has been deactivated and can no longer be displayed.]

and remove the use of ref in the calls

Code: Select all

Imports.TriggerConditions[] conditions = new Imports.TriggerConditions[1];
conditions[0].Source = Imports.Channel.CHANNEL_A;
conditions[0].Condition = Imports.TriggerState.DontCare;
status = Imports.SetTriggerChannelConditions(handle, conditions, 1, Imports.INFO.Add);

Imports.TriggerDirections[] directions = new Imports.TriggerDirections[1];
directions[0].Direction = Imports.ThresholdDirection.Exit;
directions[0].Source = Imports.Channel.CHANNEL_A;
status = Imports.SetTriggerChannelDirections((short)handle, directions, (short)(1));


Imports.TriggerChannelProperties[] properties = new Imports.TriggerChannelProperties[1];
properties[0].Channel = Imports.Channel.CHANNEL_A;
properties[0].ThresholdMinor = mv_to_adc(200, Imports.Range.Range_10V);
properties[0].ThresholdMajor = mv_to_adc(600, Imports.Range.Range_10V);
properties[0].ThresholdMode = Imports.ThresholdMode.Window;
properties[0].HysteresisMajor = 256;
properties[0].HysteresisMinor = 256;
status = Imports.SetTriggerChannelProperties(handle, properties, 1, 0, 0);

Martyn
Technical Support Manager

RamonG
Newbie
Posts: 0
Joined: Wed May 13, 2015 8:24 pm

Re: Setting advanced trigger for PicoScope 4824

Post by RamonG »

Hi Martyn, thank you for the modified version of imports file.

After replace the file, the triggering functions SetTriggerChannelConditions, SetTriggerChannelDirections and SetTriggerChannelProperties returns an status of 0 meaning success. (My code is based on a modified version of PS4000aBlockCaptureGui sample located in SDK)

Now, the problem I'm facing is that scope returns readings immediately after RunBlock called, is like the trigger is being fired although conditions are not met. But if I replace all advanced triggering calls by a SetSimpleTrigger call, the code works perfectly; the trigger is fired when condition is met, so I believe that the rest of the code is correct.

I have attached the source code, hopefully you could take a look. I tried to simplified the code as much as possible to make it easier its reading.

Your support is very appreciated.
Thank you
Ramon.
Attachments
PS4824_BasicSample.zip
sample based on PS4000aBlockCaptureGui from SDK
(73.99 KiB) Downloaded 512 times

antimo
Newbie
Posts: 0
Joined: Thu May 28, 2015 12:17 pm

Re: Setting advanced trigger for PicoScope 4824

Post by antimo »

Hi,

I have the same problem. I downloded and added to my project, "PS4000AImports.cs", and now the PicoScope returns readings immediately.

I also tried with a C example, included in the PS4000Asdk. It is working fine, but it is limited to only 4 channels. The first four channels. I need the trigger modality on all channels and I can't use "SetSimpleTrigger".

Thank you in advance for any help you can provide

Hitesh

Re: Setting advanced trigger for PicoScope 4824

Post by Hitesh »

Hi RamonG and Antimo,

After some investigation the problem was located to an incorrect enum definition in the PS40000AImports.cs file - the CONDITIONS_INFO enum should be:

Code: Select all

public enum CONDITIONS_INFO : int
        {
            Clear = 1,
            Add = 2
        }
New file attached:

[The extension cs has been deactivated and can no longer be displayed.]

With regards to triggering on all channels, unfortunately there is a limit of applying the trigger conditions to up to 4 channels.

Regards,

Eva zhou
Newbie
Posts: 0
Joined: Mon Jul 21, 2014 8:29 am

Re: Setting advanced trigger for PicoScope 4824

Post by Eva zhou »

Hi Hitesh,

I met the same issue , followed you and Martyn's instuction and then solved them. Now i am wondering how to understand the info parameter when it's set as (PS4000A_CONDITIONS_INFO)(PS4000A_CLEAR |PS4000A_ADD) in ps4000aSetTriggerChannelConditions. I have tried trigger on 2 channel, it seems that only this setup is avaliable.

Best Regards
Eva

Hitesh

Re: Setting advanced trigger for PicoScope 4824

Post by Hitesh »

Hi Eva,

Setting

Code: Select all

info = (PS4000A_CONDITIONS_INFO)(PS4000A_CLEAR | PS4000A_ADD);
means that the driver will clear any previous trigger conditions that were set and add the new trigger conditions.

If you wish to add more trigger conditions, you can call the ps4000aSetTriggerChannelConditions again with info set to PS4000A_ADD which will OR the conditions together.

This is explained in the function description in the Programmer's Guide.

Hope this helps.

Eva zhou
Newbie
Posts: 0
Joined: Mon Jul 21, 2014 8:29 am

Re: Setting advanced trigger for PicoScope 4824

Post by Eva zhou »

Hi Hitesh,

Got it! Thanks.

Best Regards
Eva

Eva zhou
Newbie
Posts: 0
Joined: Mon Jul 21, 2014 8:29 am

Re: Setting advanced trigger for PicoScope 4824

Post by Eva zhou »

Hi Hitesh,

Code: Select all

info = (PS4000A_CONDITIONS_INFO)(PS4000A_CLEAR | PS4000A_ADD);
As you said, it means that the driver will clear any previous trigger conditions that were set and add the new trigger conditions. In the sdk guide, "info = PS4000A_CLEAR" also means clear previous conditons and add the current trigger condition. Are there any difference between them?

Eva

Hitesh

Re: Setting advanced trigger for PicoScope 4824

Post by Hitesh »

Hi Eva,

To clarify, please find below the text from the Programmer's Guide:
info, determines whether the function clears previous conditions:
PS4000A_CLEAR, clears previous conditions
PS4000A_ADD, adds the specified conditions (ORing them with previously set conditions, if any)

You can combine both actions by passing
(PS4000A_CONDITIONS_INFO)(PS4000A_CLEAR | PS4000A_ADD)
Hope this helps.

Post Reply