Porting triggering with PWQ from 2405A to 4244A

Post any questions related to the new PicoScope 7 software
Post Reply
phgphd
Newbie
Posts: 0
Joined: Wed Jun 16, 2021 12:33 am

Porting triggering with PWQ from 2405A to 4244A

Post by phgphd »

I am porting my application from using the Picoscope 2405A to the 4244A and Picoscope 7 library API. The purpose of the application is to capture a transient pulse of bipolar characteristics. The application configures the Picoscope to use Windowing with Pulse Width Qualification triggering. The application works perfectly on the 2405A with libps2000a API. Porting to the libps4000a required significant translations from the libps2000a API, principally with the following API functions: ps4000aSetTriggerChannelConditions, ps4000aSetTriggerChannelDirections, ps4000aSetTriggerChannelProperties, ps4000aSetPulseWidthQualifierConditions, ps4000aSetPulseWidthQualifierProperties. All of these functions return PICO_OK, yet when calling ps4000IsTriggerOrPulseWidthQulaifierEnabled() neither trigger nor pulse width qualifier are enabled. I turned off the pulse width qualifying trigger with no luck. I turned off the window trigger and converted to a simple magnitude trigger and still not able to enable triggering. Otherwise I am able to successfully open and read data in block mode from the 4244A. If anyone can help, it would be greatly appreciated. I show my code below for the aforementioned API functions.

void
AcqPicoscope::setTriggerChannelConditions()
{
#pragma pack(1)
PS4000A_CONDITION triggerConditions[] =
{
{ PS4000A_CHANNEL_A, PS4000A_CONDITION_TRUE }, // enable triggering on channel A only
{ PS4000A_CHANNEL_B, PS4000A_CONDITION_DONT_CARE }, // channel B
{ PS4000A_CHANNEL_C, PS4000A_CONDITION_DONT_CARE }, // channel C
{ PS4000A_CHANNEL_D, PS4000A_CONDITION_DONT_CARE }, // channel D
{ PS4000A_EXTERNAL, PS4000A_CONDITION_DONT_CARE }, // external
{ PS4000A_TRIGGER_AUX, PS4000A_CONDITION_DONT_CARE }, // aux
{ PS4000A_PULSE_WIDTH_SOURCE, PS4000A_CONDITION_TRUE } // pulse width qualifier is enabled
};
#pragma pack(0)

sts = ps4000aSetTriggerChannelConditions(
mConfig.device, &triggerConditions[0], 7, PS4000A_CLEAR);
if (sts != PICO_OK)
{
cout << "Set channel trigger conditions failed: err = " << sts << endl;
mOkay = false;
}
return;
} // end setTriggerChannelConditions()

void
AcqPicoscope::setTriggerChannelDirections()
{
#pragma pack(1)
PS4000A_DIRECTION directionConditions[] =
{
{ PS4000A_CHANNEL_A, PS4000A_THRESHOLD_WINDOW_TRIGGERED }, // enable triggering on channel A only
{ PS4000A_CHANNEL_B, PS4000A_NONE }, // channel B
{ PS4000A_CHANNEL_C, PS4000A_NONE }, // channel C
{ PS4000A_CHANNEL_D, PS4000A_NONE }, // channel D
{ PS4000A_EXTERNAL, PS4000A_NONE }, // external
{ PS4000A_TRIGGER_AUX, PS4000A_NONE } // aux
};
#pragma pack(0)

ps4000aSetTriggerChannelDirections(mConfig.device, // device handle
&directionConditions[0], 6 );
if (sts != PICO_OK)
{
cout << "Set channel trigger directions failed: err = " << sts << endl;
mOkay = false;
}

return;
} // end setTriggerChannelDirections()

void
AcqPicoscope::setTriggerChannelProperties()
{
double maxRange = mConfig.channel[PS4000A_CHANNEL_A].frange;

int16_t uprThreshold = int16_t((mConfig.uprTriggerThreshold/maxRange)
* kPSMaxA2DValue);
int16_t lwrThreshold = int16_t((mConfig.lwrTriggerThreshold/maxRange)
* kPSMaxA2DValue);
uint16_t uprThresholdHystOffset = kPSResolutionInBits;
uint16_t lwrThresholdHystOffset = kPSResolutionInBits;

#pragma pack(1)
PS4000A_TRIGGER_CHANNEL_PROPERTIES triggerChannelProperties[] =
{
{
uprThreshold, uprThresholdHystOffset,
lwrThreshold, lwrThresholdHystOffset,
PS4000A_CHANNEL_A, PS4000A_WINDOW
}
};
#pragma pack(0)

sts = ps4000aSetTriggerChannelProperties(
mConfig.device, &triggerChannelProperties[0], 1, 0, 0);
if (sts != PICO_OK)
{
cout << "Set channel trigger properties failed: err = " << sts << endl;
mOkay = false;
}
return;
} // end setTriggerChannelProperties()

void
AcqPicoscope::setPulseWidthQualifier()
{
// Minimum pulse width in units of samples.
uint32_t minPulseWidth = uint32_t(kMinPulseWidthSamples);

#pragma pack(1)
PS4000A_CONDITION pwqConditions[] =
{
{ PS4000A_CHANNEL_A, PS4000A_CONDITION_TRUE }, // enable pulse width trigger on channel A
{ PS4000A_CHANNEL_B, PS4000A_CONDITION_DONT_CARE }, // channel B
{ PS4000A_CHANNEL_C, PS4000A_CONDITION_DONT_CARE }, // channel C
{ PS4000A_CHANNEL_D, PS4000A_CONDITION_DONT_CARE }, // channel D
{ PS4000A_EXTERNAL, PS4000A_CONDITION_DONT_CARE }, // external
{ PS4000A_TRIGGER_AUX, PS4000A_CONDITION_DONT_CARE } // aux
};
#pragma pack(0)

sts = ps4000aSetPulseWidthQualifierConditions(
mConfig.device, // device handle
&pwqConditions[0], // pointer to condition structure
6, // number of structures
PS4000A_CLEAR
);

if (sts != PICO_OK)
{
cout << "Set pulse width qualifier conditions failed: err = " << sts << endl;
mOkay = false;
}

sts = ps4000aSetPulseWidthQualifierProperties(
mConfig.device, // device handle
PS4000A_RISING_LOWER,
minPulseWidth,
0,
PS4000A_PW_TYPE_GREATER_THAN
);

if (sts != PICO_OK)
{
cout << "Set pulse width qualifier properties failed: err = " << sts << endl;
mOkay = false;
}

return;
} // end setPulseWidthQualifier()

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

Re: Porting triggering with PWQ from 2405A to 4244A

Post by Martyn »

You need to use CLEAR and ADD

Code: Select all

sts = ps4000aSetTriggerChannelConditions(
mConfig.device, &triggerConditions[0], 7, (PS4000A_CLEAR | PS4000A_ADD) );
Attachments
Clear and Add.png
Martyn
Technical Support Manager

phgphd
Newbie
Posts: 0
Joined: Wed Jun 16, 2021 12:33 am

Re: Porting triggering with PWQ from 2405A to 4244A

Post by phgphd »

Thank you. That fixed the issue.

Post Reply