Triggering and Acquisition 5203

Post your C and C++ discussions here
Post Reply
Posts: 1
Joined: Tue Mar 18, 2008 3:48 pm

Triggering and Acquisition 5203

Post by jecuzens » Wed Mar 26, 2008 2:39 pm


I just started trying to program the 5203 and ran into a bit of a problem when it came to getting data out of the scope. Whenever I used the GetValues function to retrieve the data from the scope I started getting an invalid handle error even though all of the functions had been returning PICO_OK until that point for my block read. I thought that the problem may be due to the fact that I am using sdk 13 but had the old pico software installed (11). So I downloaded the latest pico software and tried using that but it appears that I can't get the scope to trigger anymore (despite restarting the scope, uninstalling the driver and reinstalling, and restarting my computer). Is there a way I can know that the firmware was updated? I noticed that the new pico software uses 1.3.2 of the ps5000.dll while sdk 13 uses Is this a problem???

Anyway, here is my acquisition code:

Code: Select all

status = ps5000OpenUnit(&m_InstrumentID);

//range = PS5000_100MV
status = ps5000SetChannel(m_InstrumentID, PS5000_CHANNEL_A, TRUE, TRUE, range);

//dDelayTime = 25000; fSampleTime = 2e-9
unsigned long ulTrigDelay = unsigned long(dDelayTime/(fSampleTime*8.0));
status = ps5000SetTriggerDelay(m_InstrumentID,ulTrigDelay);

//dTrigLevel = 0
	short sTriggerVoltage = mv_to_adc((short)dTrigLevel, m_Channel);

	//default structs
	struct tTriggerChannelProperties sourceDetails;
	sourceDetails.thresholdMajor = sTriggerVoltage;
	sourceDetails.thresholdMinor = sTriggerVoltage;
	sourceDetails.hysteresis = 0;//256 * 10;
	sourceDetails.thresholdMode = LEVEL;
	struct tTriggerConditions conditions;
	conditions.channelA = CONDITION_DONT_CARE;
	conditions.channelB = CONDITION_DONT_CARE;
	conditions.channelC = CONDITION_DONT_CARE;
	conditions.channelD = CONDITION_DONT_CARE;
	conditions.external = CONDITION_DONT_CARE;
	conditions.aux = CONDITION_DONT_CARE;
	conditions.pulseWidthQualifier = CONDITION_DONT_CARE;
	directions.channelA = NONE;
	directions.channelB = NONE;
	directions.channelC = NONE;
	directions.channelD = NONE;
	directions.ext = NONE;
	directions.aux = NONE;

	//Determine the trigger parameters
	if (m_Channel == PS5000_CHANNEL_A){ = PS5000_CHANNEL_B;
		conditions.channelB = CONDITION_TRUE;
		directions.channelB = RISING;
	} else { = PS5000_CHANNEL_A;
		conditions.channelA = CONDITION_TRUE;
		directions.channelA = RISING;

	//Convert the structures into the appropriate typedefs
	TRIGGER_CHANNEL_PROPERTIES *tproperties = reinterpret_cast<TRIGGER_CHANNEL_PROPERTIES*>(&sourceDetails);
	TRIGGER_CONDITIONS *tconditions = reinterpret_cast<TRIGGER_CONDITIONS*>(&conditions);

	//Configure the properties for this trigger using the properties struct (properties can be compounded)
	status = ps5000SetTriggerChannelProperties(m_InstrumentID, tproperties, 1, FALSE, 0);
	if (status != PICO_OK)
		return FALSE;

	//Configure the conditions of the trigger using the conditions struct (conditions can be compounded)
	status = ps5000SetTriggerChannelConditions(m_InstrumentID, tconditions, 1);
	if (status != PICO_OK)
		return FALSE;

	status = ps5000SetTriggerChannelDirections(m_InstrumentID,

//m_lSpectrumSize = 7040; m_SampleBuffer = (short*)malloc(m_lSpectrumSize * sizeof(short));
	status = ps5000SetDataBuffer(m_InstrumentID, m_Channel, m_SampleBuffer, m_lSpectrumSize);

//unNPointsToAcquire = 7040; m_ulTimeBase = 1
	status = ps5000RunBlock(m_InstrumentID,

//Callback function
void CALLBACK CallBackBlock(short handle, PICO_STATUS status, void * pParameter)
	// flag to say done reading data
	reinterpret_cast<CPicoScope*>(pParameter)->m_bAcquisitionComplete = TRUE;

	// store the acquisition status
	reinterpret_cast<CPicoScope*>(pParameter)->m_psAcquisitionStatus = status;

	//Unit must be stopped before any other scope interactions take place (happens after callback)

	unsigned long ulSampleCount = m_lSpectrumSize;

	status = ps5000GetValues(m_InstrumentID,0L,&ulSampleCount,1,RATIO_MODE_NONE,0,NULL);
I tried to truncate the code as much as possible but this is the main idea... I know the Callback works because in the event of a timeout (which I calculate) I stop the scope which makes it hit the callback. Just can't figure out why I'm not triggering now.

Any help would be appreciated!

User avatar
Site Admin
Site Admin
Posts: 598
Joined: Wed May 07, 2003 9:45 am

Post by markspencer » Tue May 13, 2008 11:01 am


I am sorry to hear that you are experiencing problem. I have read through your source code and just have a few suggestion to your problem.

The first is that you are only enabling channel A, but you seem to be trying to use channel B as well, ie for triggering. You may have just left this out of the snipet.

The second part is the value for the delay this is most likely overflowing the unsigned long value and thus I can not determine the value.

The lastly does run block return PICO_OK?

Mark Spencer

Post Reply