Picoscope 6000 triggered streaming examples

Post your C and C++ discussions here
Post Reply
mcsquared2718
Newbie
Posts: 0
Joined: Wed Aug 24, 2011 3:30 pm

Picoscope 6000 triggered streaming examples

Post by mcsquared2718 »

Has anyone got any experience of using the triggered streaming function in the example program for the Picoscope 6000?

Using the unmodified example code, the triggered streaming function appears to start streaming even when no signal is applied to the inputs of the scope. It also does not autostop after the specified number of pretrigger+posttrigger samples have been captured.

The triggering seems to work fine in block mode.

Has anyone else experienced this behaviour?
Thanks!

mcsquared2718
Newbie
Posts: 0
Joined: Wed Aug 24, 2011 3:30 pm

Re: Picoscope 6000 triggered streaming examples

Post by mcsquared2718 »

I might also add that when autostop is changed from true to false in the call to ps6000RunStreaming, the oscilloscope never triggers at all, regardless of what signal is applied.

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

Re: Picoscope 6000 triggered streaming examples

Post by Martyn »

Here are a few simple changes that I have made to the sample program that should help to show how it works

Firstly the CallBackStreaming function was not taking notice of the trigger return values

Code: Select all

short		g_triggered = 0;
unsigned long g_trigAt = 0;

/****************************************************************************
* Callback
* used by PS6000 data streaimng collection calls, on receipt of data.
* used to set global flags etc checked by user routines
****************************************************************************/
void PREF4 CallBackStreaming(	short handle,
															unsigned long noOfSamples,
															unsigned long	startIndex,
															short overflow,
															unsigned long triggerAt,
															short triggered,
															short autoStop,
															void	*pParameter)
{
	// used for streaming
	g_sampleCount = noOfSamples;
	g_startIndex	= startIndex;
	g_autoStopped		= autoStop;

	// flag to say done reading data
	g_ready = TRUE;

	
	g_triggered = triggered;

	if(triggered)
		g_trigAt = triggerAt;
}
The StreamDataHandler has been simplified to run on Channel A only, without writing to file, and with no aggregation. It will now show a running count of samples and give an indication of when the trigger occurs and how many samples are taken post trigger.

Code: Select all

/****************************************************************************
* Stream Data Handler
* - Used by the two stream data examples - untriggered and triggered
* Inputs:
* - unit - the unit to sample on
* - preTrigger - the number of samples in the pre-trigger phase 
*					(0 if no trigger has been set)
***************************************************************************/
void StreamDataHandler(UNIT * unit, unsigned long preTrigger)
{
	unsigned long sampleCount= BUFFER_SIZE * 1000;
	short * buffer[1];
	PICO_STATUS status;
	unsigned long sampleInterval = 1;
	int index = 0;
	int totalSamples; 
	int totalAtTrigger = 0;
	int postTriggerSamples;
	short hasBeenTriggered = 0;

	buffer[0] = (short*) malloc(sampleCount * sizeof(short));
	status = ps6000SetDataBuffer(	unit->handle, 
																		PS6000_CHANNEL_A, 
																		buffer[0],
																		sampleCount, 
																		PS6000_RATIO_MODE_NONE);	

	printf("Waiting for trigger...Press a key to abort\n");
	g_autoStopped = FALSE;
	g_triggered = 0;
	g_trigAt = 0;

	status = ps6000RunStreaming(unit->handle, 
															&sampleInterval, 
															PS6000_US,
															preTrigger, 
															1000000 - preTrigger, 
															//FALSE,
															TRUE,
															1,
															PS6000_RATIO_MODE_NONE,
															sampleCount);

	printf("\nps6000RunStreaming status = 0x%x\n", status);
	printf("Streaming data...Press a key to abort\n");

	totalSamples = 0;
	while (!_kbhit() && !g_autoStopped)
	{
		/* Poll until data is received. Until then, GetStreamingLatestValues wont call the callback */
		Sleep(100);
		g_ready = FALSE;

		status = ps6000GetStreamingLatestValues(unit->handle, CallBackStreaming, NULL);

		if (g_ready && g_sampleCount > 0) /* can be ready and have no data, if autoStop has fired */
		{
			if(g_triggered)
			{
				hasBeenTriggered = 1;
				totalAtTrigger = totalSamples + g_trigAt;
			}

			totalSamples += g_sampleCount;

			printf("Collected %li samples\r", totalSamples);

			if(g_triggered)
			{
				printf("\n\nTriggered at %lu\n", totalAtTrigger);
			}
		}
	}

	if(hasBeenTriggered)
	{
		printf("Number of post trigger samples: %lu", (totalSamples - (totalAtTrigger - 1)));
	}

	ps6000Stop(unit->handle);

	if (!g_autoStopped) 
		printf("data collection aborted\n");

	printf("\nPress key to continue\n");
	_getch();

	free(buffer[0]);
}
Finally the TriggerChannelProperties hysteresis values have been reduced to a small value (10) and trigger level increased to 500mV to prevent early triggering

Code: Select all

/****************************************************************************
* CollectStreamingTriggered
*  this function demonstrates how to collect a stream of data
*  from the unit (start collecting on trigger)
***************************************************************************/
void CollectStreamingTriggered(UNIT * unit)
{
	short triggerVoltage = mv_to_adc(500,	unit->channelSettings[PS6000_CHANNEL_A].range); // ChannelInfo stores ADC counts
	struct tPwq pulseWidth;
	
	struct tPS6000TriggerChannelProperties sourceDetails = {	triggerVoltage,
																														10,
																														triggerVoltage,
																														10,
																														PS6000_CHANNEL_A,
																														PS6000_LEVEL};
	
	struct tPS6000TriggerConditions conditions = {	PS6000_CONDITION_TRUE,
																									PS6000_CONDITION_DONT_CARE,
																									PS6000_CONDITION_DONT_CARE,
																									PS6000_CONDITION_DONT_CARE,
																									PS6000_CONDITION_DONT_CARE,
																									PS6000_CONDITION_DONT_CARE,
																									PS6000_CONDITION_DONT_CARE };

	struct tTriggerDirections directions = {	PS6000_RISING,
																						PS6000_NONE,
																						PS6000_NONE,
																						PS6000_NONE,
																						PS6000_NONE,
																						PS6000_NONE };

	memset(&pulseWidth, 0, sizeof(struct tPwq));

	printf("Collect streaming triggered...\n");
	printf("Data is written to disk file (data.txt)\n");
	printf("Press a key to start\n");
	_getch();
	SetDefaults(unit);

	/* Trigger enabled
	* Rising edge
	* Threshold = 500mV */
	SetTrigger(unit->handle, &sourceDetails, 1, &conditions, 1, &directions, &pulseWidth, 0, 0, 0);

	StreamDataHandler(unit, 1000);
}
The condition where triggering does not occur when AutoStop is set to FALSE is embedded in the driver and has been reported to the development team.
Martyn
Technical Support Manager

Post Reply