Picoscope 5442A Trigger

Post your C and C++ discussions here
Post Reply
oabel5
Newbie
Posts: 0
Joined: Wed Nov 04, 2015 8:07 am

Picoscope 5442A Trigger

Post by oabel5 »

Hello ,
I wrote the following program . The PicoScope 5442A does not react on triggers. Can anyone tell me where the mistake in my program is?
Thank-you

PS. I apologize for my bad english . If anyone can answer in German or Spanish, I can better understand .

Code: Select all

/****************************************************************************
*
*  PicoScope_5242A_init_config
*  this function opens the pico scope 5242A and configures the channels and trigger
*
****************************************************************************/
void PicoScope_5242A_init_config(void)
{ 
	char Error[100];
	static int statusOpenUnit=1; 
	PICO_STATUS status=1;
	float PS5000A_CHANNEL_A_OFFSET, PS5000A_CHANNEL_B_OFFSET;
	int iTriggerThresholdADCCount, iAutoTrigger_ms, autoTriggerMilliseconds;
	unsigned int iTriggerDelay;
	short nChannelProperties, thresholdUpper, thresholdUpperHysteresis, thresholdLower, thresholdLowerHysteresis;
	uint32_t timebase;
	int32_t noSamples;
	float timeIntervalNanoseconds;
	int32_t maxSamples;
	uint32_t segmentIndex;
	float maximumVoltage, minimumVoltage;
	
	// Structure for trigger conditions
	struct tPS5000ATriggerConditions CHA_Conditions = {	PS5000A_CONDITION_TRUE,	// CHA
		        			                                       PS5000A_CONDITION_DONT_CARE,	// CHB
										       PS5000A_CONDITION_DONT_CARE,	// CHC
										       PS5000A_CONDITION_DONT_CARE,	// CHD
										       PS5000A_CONDITION_DONT_CARE,	// external
										       PS5000A_CONDITION_DONT_CARE,	// aux
										       PS5000A_CONDITION_TRUE,	// pulseWidthQualifier
														};		
	
								 
	// Structure for trigger configuration
	PS5000A_TRIGGER_CHANNEL_PROPERTIES CHA_Properties = {	7000, 													                                                                   32,				      																		    0,				   
													    0,	       
													    PS5000A_CHANNEL_A,
													    PS5000A_LEVEL
	                                                         }; 			


	if(statusOpenUnit != PICO_OK)
	{
	// Open device
	statusOpenUnit = ps5000aOpenUnit(&picohandle, NULL, PS5000A_DR_15BIT);
	// Error?
	if(statusOpenUnit != PICO_OK) 
	{
			sprintf(Error, "Unable to open PicoScope. Error code : 0x%08lx\n", statusOpenUnit);
			MessagePopup("Error", Error);
	}
	}								
	
	// Configure Channels 
	PS5000A_CHANNEL_A_OFFSET = 0.0;
	status = ps5000aSetChannel(picohandle,
							   PS5000A_CHANNEL_A,
		                                           TRUE,
		                                           PS5000A_DC,
		                                          PS5000A_10V,
							   PS5000A_CHANNEL_A_OFFSET);
	if(status != PICO_OK) 
	{
			sprintf(Error, "Unable to initialize PicoScope channel. Error code : 0x%08lx\n", status);
			MessagePopup("Error", Error);
	} 
	
	// Get timebase, just for information
	// Sampletime = 5s
	// e.g. Samplerate = 1000S/s
	// -> sample interval: 1ms
	// -> Memory: 5000S/Channel
	// timebase @ 15bit resolution: (1ms * 125000000) + 2 = 125002
	timebase = 125002;
	noSamples = 5000;
	segmentIndex = 0;
	
	while (ps5000aGetTimebase2(picohandle, 
		                      timebase, 
							  noSamples, 
							  NULL,    //&timeIntervalNanoseconds, 
							  NULL,   //&maxSamples, 
							  segmentIndex))	
	{
		timebase++;
	}
	// Set trigger conditions
	status = ps5000aSetTriggerChannelConditions(picohandle,
											    &CHA_Conditions,
											    1);				// 1 condition structure
	if(status != PICO_OK) 
	{
			sprintf(Error, "Unable to set PicoScope trigger conditions. Error code : 0x%08lx\n", status);
			MessagePopup("Error", Error);
	} 
	
	// Configure trigger
	status = ps5000aSetTriggerChannelDirections(picohandle,
												PS5000A_RISING,    // CHA
												PS5000A_NONE,    // CHB
												PS5000A_NONE,     // CHC
												PS5000A_NONE,     // CHD					
												PS5000A_NONE,     // ext
												PS5000A_NONE);    // aux	   
	if(status != PICO_OK) 
	{
			sprintf(Error, "Unable to initialize PicoScope trigger direction. Error code : 0x%08lx\n", status);
			MessagePopup("Error", Error);
	}
	
	
	autoTriggerMilliseconds = 5000;
	nChannelProperties = 1; // the size of the channelProperties array. If zero, triggering is switched off. -> 1 channel triggered
	status = ps5000aSetTriggerChannelProperties(picohandle,
												&CHA_Properties,
												nChannelProperties,
												NULL,
												autoTriggerMilliseconds);
	if(status != PICO_OK) 
	{
			sprintf(Error, "Unable to initialize PicoScope trigger channel properties. Error code : 0x%08lx\n", status);
			MessagePopup("Error", Error);
	}
}

/****************************************************************************
*
*  PicoScope_5242A_arm
*  this function arms 5242A to capture data
*
****************************************************************************/
void PicoScope_5242A_arm(void)
{
	char Error[100];
	short sReady;
	int i=0;
	int16_t retry;
	PICO_STATUS status=1; 
	
	long timeInterval = 1;
	unsigned long maxSamples;
	
	// Sampletime = 5s
	// e.g. Samplerate = 1000S/s
	// -> sample interval: 1ms
	// -> Memory: 5000S/Channel
	// timebase @ 15bit resolution: (1ms * 125000000) + 2 = 125002
	int noOfPreTriggerSamples = 500, noOfPostTriggerSamples = 5000, timeIndisposedMs;
	unsigned int timebase = 125002, segmentIndex = 0;
	
	status = ps5000aRunBlock(picohandle,
							 noOfPreTriggerSamples,
							 noOfPostTriggerSamples,
							 timebase,
							 &timeIndisposedMs,
							 segmentIndex,
							 NULL,
							 NULL);  

	if(status != PICO_OK) 
	{
			sprintf(Error, "Unable to arm PicoScope. Error code : 0x%08lx\n", status);
			MessagePopup("Error", Error);
	}
}

/****************************************************************************
*
*  PicoScope_5242A_get_data
*  Download data recorded by PicoScope
*
****************************************************************************/
void PicoScope_5242A_get_data(short *ChannelA, short *ChannelB)
{
	char Error[100];
	int i=0, bufferLth;
	unsigned int segmentIndex, startIndex, noOfSamples;
	short sReady, overflow;
	PICO_STATUS status=1;
	
	// Wait for 13 seconds for PicoScope to get ready
	do 
	{
		status = ps5000aIsReady(picohandle, &sReady);
		Sleep(100);
		i++;
		if(i>=130) 
		{
			MessagePopup("Error", "Trigger Fehler!");
			break;
		}
	} while(!sReady);   
	

	// Configure PicoScop data buffer for Channel A
	bufferLth = 5000;
	segmentIndex = 0;
	
	status = ps5000aSetDataBuffer(picohandle,
								  PS5000A_CHANNEL_A,
								  ChannelA,
								  bufferLth,
								  segmentIndex,
								  PS5000A_RATIO_MODE_NONE);
	if(status != PICO_OK) 
	{
			sprintf(Error, "Unable to set PicoScope data buffer. Error code : 0x%08lx\n", status);
			MessagePopup("Error", Error);
	}
	
	// download recorded data for Channel A
	startIndex = 0;
	noOfSamples = 5000;
	status = ps5000aGetValues(picohandle,
							  startIndex,
							  &noOfSamples,
							  PS5000A_RATIO_MODE_NONE,
							  PS5000A_RATIO_MODE_NONE,
							  segmentIndex,
							  &overflow);
	
	if(status != PICO_OK) 
	{
			sprintf(Error, "Unable to download recorded data from PicoScope. Error code : 0x%08lx\n", status);
			MessagePopup("Error", Error);
	}
	
}


void PicoScope_5242A_close(void)
{
	PICO_STATUS status=1;
	char Error[100];
	
	// close device
	status = ps5000aStop(picohandle);
		
	if(status != PICO_OK) 
	{
			sprintf(Error, "Unable to close PicoScope. Error code : 0x%08lx\n", status);
			MessagePopup("Error", Error);
	}
	
	ps5000aCloseUnit(picohandle);
}

int main (int argc, char *argv[])
{
  short sVoltageData[5000]={0};
  short sCurrentData[5000]={0};
  int i=0;

	if (InitCVIRTE (0, argv, 0) == 0)  return -1;    /* out of memory */
	
	
	// Open and configure PicoScope
	PicoScope_5242A_init_config();
	
	// Arm PicoScope to capture data
	PicoScope_5242A_arm();	
		
	// Get data recorded by PicoScope
	PicoScope_5242A_get_data(sVoltageData, sCurrentData);
		
	PicoScope_5242A_close();
	
	return 0;
}

Hitesh

Re: Picoscope 5442A Trigger

Post by Hitesh »

Hi oabel5,

No problem with reading your English :D

In the following code:

Code: Select all

struct tPS5000ATriggerConditions CHA_Conditions = {   PS5000A_CONDITION_TRUE,   // CHA
                                             PS5000A_CONDITION_DONT_CARE,   // CHB
                                             PS5000A_CONDITION_DONT_CARE,   // CHC
                                             PS5000A_CONDITION_DONT_CARE,   // CHD
                                             PS5000A_CONDITION_DONT_CARE,   // external
                                             PS5000A_CONDITION_DONT_CARE,   // aux
                                             PS5000A_CONDITION_TRUE,   // pulseWidthQualifier
                                        };      
If you wish to use the Pulse Width Qualifier as well then you need to call the ps5000aSetPulseWidthQualifier function, otherwise set the pulseWidthQualifier condition to PS5000A_CONDITION_DONT_CARE.

Are you getting any non-zero status codes from the function calls?

Regards,

oabel5
Newbie
Posts: 0
Joined: Wed Nov 04, 2015 8:07 am

Re: Picoscope 5442A Trigger

Post by oabel5 »

Hi,
Thanks for your answer.
Sorry, That was wrong:

Code: Select all

	struct tPS5000ATriggerConditions CHA_Conditions = {	PS5000A_CONDITION_TRUE,	// CHA
		        			                            PS5000A_CONDITION_DONT_CARE,			// CHB
														PS5000A_CONDITION_DONT_CARE,	// CHC
														PS5000A_CONDITION_DONT_CARE,	// CHD
														PS5000A_CONDITION_DONT_CARE,	// external
														PS5000A_CONDITION_DONT_CARE,	// aux
														PS5000A_CONDITION_TRUE,	// pulseWidthQualifier
														};
that's right:

Code: Select all

	struct tPS5000ATriggerConditions CHA_Conditions = {	PS5000A_CONDITION_TRUE,	// CHA
		        			                            PS5000A_CONDITION_DONT_CARE,			// CHB
														PS5000A_CONDITION_DONT_CARE,	// CHC
														PS5000A_CONDITION_DONT_CARE,	// CHD
														PS5000A_CONDITION_DONT_CARE,	// external
														PS5000A_CONDITION_DONT_CARE,	// aux
														PS5000A_CONDITION_DONT_CARE,	// pulseWidthQualifier
														};
I have found the error in the code:

Code: Select all

	PicoScope_5242A_init_config();

	// Arm PicoScope to capture data
	PicoScope_5242A_arm();
	Sleep(400);   // <----- wait is important

        // I send my signal
	
	// Get data recorded by PicoScope
	PicoScope_5242A_get_data(sVoltageData, sCurrentData);

	
	PicoScope_5242A_close();

Hitesh

Re: Picoscope 5442A Trigger

Post by Hitesh »

Hi oabel5,

Before you put the sleep(400) in, was the sReady parameter in the PicoScope_5242A_get_data() function being set to 1 before you collected the data?

Regards,

oabel5
Newbie
Posts: 0
Joined: Wed Nov 04, 2015 8:07 am

Re: Picoscope 5442A Trigger

Post by oabel5 »

sready is not a global variable.
Regards.

Hitesh

Re: Picoscope 5442A Trigger

Post by Hitesh »

Hi Oabel5,

Understood - normally once you have called the ps5000aRunBlock() function, you either wait for the callback function to return and indicate that the device has collected some data or you poll the device by calling ps5000aIsReady.

It should not be necessary to insert a sleep before polling the ps5000aIsReady call - which version of the ps5000a dll are you using?

Regards,

xiaohao
Newbie
Posts: 0
Joined: Thu Jun 15, 2017 9:48 am

Re: Picoscope 5442A Trigger

Post by xiaohao »

Hi oabel5,
I have the same problem as you,
How do you solve it? My equipment is not moving. Can I see your code?



Thank you very much if you can
xiaohao

Hitesh

Re: Picoscope 5442A Trigger

Post by Hitesh »

Hi xiaohao,

A member of our team is dealing with your e-mail support ticket.

Thanks,

Post Reply