Esempio n. 1
0
/****************************************************************************
 * set_defaults - restore default settings
 ****************************************************************************/
void set_defaults (void)
{
	short ch = 0;
  ps2000_set_ets ( unitOpened.handle, PS2000_ETS_OFF, 0, 0 );

	for (ch = 0; ch < unitOpened.noOfChannels; ch++)
	{
		ps2000_set_channel ( unitOpened.handle,
			                   ch,
												 unitOpened.channelSettings[ch].enabled ,
												 unitOpened.channelSettings[ch].DCcoupled ,
												 unitOpened.channelSettings[ch].range);
	}
}
Esempio n. 2
0
void collect_block_ets (void)
{
	int		i;
	int		trigger_sample;
	FILE 	*fp;
	short 	auto_trigger_ms = 0;
	long 	time_indisposed_ms;
	short 	overflow;
	long  	ets_sampletime;
	short ok;
	short ch;

	printf ( "Collect ETS block...\n" );
	printf ( "Collects when value rises past 1500mV\n" );
	printf ( "Press a key to start...\n" );
	getch ();

	set_defaults ();

	/* Trigger enabled
	* Channel A - to trigger unsing this channel it needs to be enabled using ps2000_set_channel
	* Rising edge
	* Threshold = 1500mV
	* 10% pre-trigger  (negative is pre-, positive is post-)
	*/
	unitOpened.trigger.simple.channel = PS2000_CHANNEL_A;
	unitOpened.trigger.simple.delay = -10.f;
	unitOpened.trigger.simple.direction = PS2000_RISING;
	unitOpened.trigger.simple.threshold = 1500.f;


	ps2000_set_trigger ( unitOpened.handle,
		(short) unitOpened.trigger.simple.channel,
		mv_to_adc (1500, unitOpened.channelSettings[(short) unitOpened.trigger.simple.channel].range),
		unitOpened.trigger.simple.direction ,
		(short) unitOpened.trigger.simple.delay,
		auto_trigger_ms );

	/* Enable ETS in fast mode,
	* the computer will store 60 cycles
	*  but interleave only 4
	*/
	ets_sampletime = ps2000_set_ets ( unitOpened.handle, PS2000_ETS_FAST, 60, 4 );
	printf ( "ETS Sample Time is: %ld\n", ets_sampletime );
	/* Start it collecting,
	*  then wait for completion
	*/
	ok = ps2000_run_block ( unitOpened.handle, BUFFER_SIZE, timebase, 1, &time_indisposed_ms );

	printf ( "Waiting for trigger..." );
	printf ( "Press a key to abort\n" );

	while ( (!ps2000_ready (unitOpened.handle)) && (!kbhit ()) )
	{
		Sleep (100);
	}

	if ( kbhit () )
	{
		getch ();
		printf ( "data collection aborted\n" );
	}
	else
	{
		ps2000_stop ( unitOpened.handle );
		/* Get the times (in microseconds)
		*  and the values (in ADC counts)
		*/
		ok = (short)ps2000_get_times_and_values ( unitOpened.handle,
																							times,
																							unitOpened.channelSettings[PS2000_CHANNEL_A].values,
																							unitOpened.channelSettings[PS2000_CHANNEL_B].values,
																							NULL,
																							NULL,
																							&overflow,
																							PS2000_PS,
																							BUFFER_SIZE);

		/* Print out the first 10 readings,
		*  converting the readings to mV if required
		*/

		printf ( "Ten readings around trigger\n" );
		printf ( "(ps)\t(mv)\n");

		/* This calculation is correct for 10% pre-trigger
		*/
		trigger_sample = BUFFER_SIZE / 10;

		for ( i = trigger_sample - 5; i < trigger_sample + 5; i++ )
		{
			printf ( "%ld\t", times [i]);
			for (ch = 0; ch < unitOpened.noOfChannels; ch++)
			{
				if (unitOpened.channelSettings[ch].enabled)
				{
					printf ( "%d\t\n", adc_to_mv (unitOpened.channelSettings[ch].values[i], unitOpened.channelSettings[ch].range));
				}
			}
			printf ("\n");
		}

		fp = fopen ( "data.txt","w" );
		if (fp != NULL)
		{
			for ( i = 0; i < BUFFER_SIZE; i++ )
			{
				fprintf ( fp, "%ld,", times[i] );
				for (ch = 0; ch < unitOpened.noOfChannels; ch++)
				{
					if (unitOpened.channelSettings[ch].enabled)
					{
						fprintf ( fp, "%ld, %d, %d", times[i],  unitOpened.channelSettings[ch].values[i], adc_to_mv (unitOpened.channelSettings[ch].values[i], unitOpened.channelSettings[ch].range) );
					}
				}
				fprintf (fp, "\n");
			}
			fclose( fp );
		}
		else
			printf("Cannot open the file data.txt for writing. \nPlease ensure that you have permission to access. \n");
	}
}