Test and Measurement Forum

Determining Sample Rate when using 3425

Post general discussions on using our drivers to write your own software here

Determining Sample Rate when using 3425

Postby TerryV01 » Tue Aug 14, 2012 1:22 am

Your help with the following would be appreciated.

Based on your Excel sample code I am using the Block Mode to capture and store data from two channels.

Whilst the program is running fine, I am not able to determine the actual sample rate that the unit is running at.

The spec. states that for two channels, the maximum sample rate is 10MS/sec. and the capture memory for 2 channels is 256k samples per channel.

It seems that I can set the time base “PS3000_get_timebase” ... If this sets the Time base, why does it use "get" rather than "set"

“PS3000_get_timebase” which in the manual says ”selects time bases until the required number of nanoseconds per sample is located” – not sure what this means?

Does the Function return the value of the timebase based on the number of samples it is able to store when running at the maximum sample rate?

Can you please explain the following comments in the sample program and how thjey are achieve with the code:
1 - 'find the maximum number of samples, the time interval (in time_units),
2 - 'the most suitable time units, and the maximum oversample at the current timebase
3 - 'get the times (in nanoseconds)
4 - 'and the values (in ADC counts)


Thanks.
TerryV01
Newbie
 
Posts: 0
Joined: Mon Aug 13, 2012 11:24 pm

Re: Determining Sample Rate when using 3425

Postby Hitesh » Tue Aug 21, 2012 10:43 am

Hi Terry,

The console example is meant to provide some sort of guidance as to how to call the necessary functions in order to collect some data from the device. I guess in this case some of the comments may not make certain things clear.

In the console example, there is a 'set_timebase' function which repeatedly queries the ps3000_get_timebase() function in order to determine which timebases are available for the number of samples desired, after which the user is prompted to select the desired timebase. The entered option is then stored in the 'timebase' variable.

A default timebase of 8 which should correspond to 1/256 of the maximum sample rate.

The ps3000_get_timebase function is used to query the driver to determine the validity of the number of samples required and the timebase selected. If the parameters are correct the function will return 1, otherwise 0 is returned.

Looking at the collect_block_immediate() function in the console example, a while loop is used to query the ps3000_get_timebase() function in order to determine if the timebase selected is valid. If it is, then the function returns the time interval, time units (e.g. milliseconds, microseconds etc.) and the maximum number of samples that are available (this depends on the timebase chosen, number of channels enabled etc.)

In the manual, the line ”selects time bases until the required number of nanoseconds per sample is located” refers to querying the driver to see which timebases and the corresponding time intervals between samples.

The timebase is actually set when the ps3000_run_block() function is called.

With regards to the comments in the sample program:

1 - 'find the maximum number of samples, the time interval (in time_units),


As mentioned above the maximum number of samples indicates the maximum number of samples depending on the number of channels enabled, the timebase chosen and the oversample selected, while time_interval is a pointer to the time interval in nanoseconds between readings at the selected timebase. T

2 - 'the most suitable time units, and the maximum oversample at the current timebase


The most suitable time units is an enumeration returned from the driver indicating the best time units that the results should be measured in. This values is then used in the call to the ps3000_get_times_and_values() function in order to specify the time units for the time values returned.

The oversample factor is user defined - the maximum number of samples is reduced while the time interval is multiplied by this factor respectively.

For 1 and 2, I highly recommend referring to the ps3000_get_timebase definition in the Programmer's Guide:

http://www.picotech.com/document/pdf/ps3000pg-en-2.pdf

The time_interval, time_units and max_samples variables are pointers to data - the driver writes to these memory locations with the values.

3 - get the times (in nanoseconds)


If instead of the ps3000_get_values function, the function ps3000_get_times_and_values (see section 2.4.22 in the Programmer's Guide) were to be called, it would additionally return a pointer to a buffer containing the times between the trigger event and the corresponding sample.

4 - 'and the values (in ADC counts)


The driver will return data from the oscilloscope in the form of ADC count values when the ps3000_get_values function is called; these can then be converted to milliVolts using the adc_to_mv function in the console example.

With regards to calculating the sample rate perhaps you can use the following structure to calculate the time taken to obtain the data:

Code: Select all
LARGE_INTEGER frequency;
LARGE_INTEGER time1;
LARGE_INTEGER time2;

// code to set up buffers etc.

// Ticks
QueryPerformanceFrequency(&frequency);

// start timer
QueryPerformanceCounter(&time1);

// Run Block

// Get Data

QueryPerformanceCounter(&time2);

elapsedTime = (time2.QuadPart - time1.QuadPart) * 1000000.0 / frequency.QuadPart;

sampling_rate = (totalSamples / elapsedTime) * 1000000.0;



The following web article may be of interest:

http://support.microsoft.com/kb/172338

I hope this helps - please let me know if you require any further clarification.

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 1997
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Determining Sample Rate when using 3425

Postby TerryV01 » Thu Aug 23, 2012 9:41 am

Thank you for the response Hitesh but ............
I am looking at the Excel example for the 3425 and referencing the Programmers Guide.
In your response you refer to a 'set_timebase' function - I can’t find such a function mentioned in the program or the 'Programmer's Guide'.
Not sure what the Console example is maybe we are looking at different examples, the “set_timebase” function does not appear to be called in the macro either.
Never the less, if my understanding as explained below is correct then problem solved else please correct where I am wrong.
Thanks:
In the program an integer variable 'timebase' is set to 13. So the user determines this - correct?
The two points that I am concerned with are:
The first is capturing and storing the data with a time stamp and units assigned (ie mV). With capturing data we are concerned with sample rate and timing and data values.
The second is displaying the data – here i am concerned with timebase and scaling units.
Not sure why the time_base affects the sample rate.
I am using 2 channels therefore maximum sample rate is 10MS/s,
Whilst this equates to 100nS sample interval (maximum), this does not line up with the timing in the spreadsheet that is generated when the program runs which is 409600nS.
According to the Programmer’s Guide, 0 is the fastest time base and the options are:
2 power 0 = 1
2 power 1 = 2
2 power 2 = 4
Therefore with timebase set to 13, 2 power 13 = 8192.
Sample Interval = 409600 = Max Sample interval*0.5*2(timebase).

The function ‘ps3000_get_timebase’ returns a ‘1’ if all arguments are within range.
So before calling the function we assign values to:
• handle
• timebase
• no_of_samples
So is timebase set here or below in the 'ps3000_run_block' function as you mention or can it be set in either?
However, the others carry a ‘0’ value when the function is called.
• time_interval,
• time_units,
• oversample,
• max_samples)

So from what you are saying these are generated by the driver and the variable retains the value assigned by the driver?
The adc_to_mv function also does not appear in the manual or the example so I am assuming the data recorded in ADC output needs to be scaled according to the scope settings.
Channel settings are +/- 20V set by the function call ‘ps3000_set_channel’
16 bits covering +/- scale = 65,536 counts
Measured Voltage = (ADC-65536/2)*0.0006103516

As stated above some of the functions mentioned are neither used nor appear in the Programmers Guide that I am using. Not sure what is going on here.
Eg: collect_block_immediate() function
Thanks.
Regards
TerryV01
Newbie
 
Posts: 0
Joined: Mon Aug 13, 2012 11:24 pm

Re: Determining Sample Rate when using 3425

Postby Hitesh » Thu Aug 23, 2012 1:50 pm

Hi Terry,

Apologies for the confusion - I'd seen you were using Excel but was looking at the C Programming language Console
Example that we provide (the PS3000con.c file in the SDK) to help explain things.

The console example consists of a number of functions that make calls to the API functions to perform certain
tasks, so 'set_timebase()' and 'collect_block_immediate()' are C code functions that are not in the Excel macro but
you can refer to them for guidance if you open up the file.

With reference to the descriptions of your understanding:

In the program an integer variable 'timebase' is set to 13. So the user determines this - correct?

Therefore with timebase set to 13, 2 power 13 = 8192.
Sample Interval = 409600 = Max Sample interval*0.5*2(timebase).


The user selects the desired timebase i.e. an index corresponding to the required sample interval.

The formula should actually be:

Code: Select all
sample_interval = max_sample_interval * 2^timebase


where max_sample_interval = 5e-8

The timebase will affect the sample rate as you are choosing the time interval between samples.

For your application, you will need a timebase of 1, and also set channels C and D off explicitly using the ps3000_set_channel() function (set the enabled flag to 0) i.e.

Code: Select all
Call ps3000_set_channel(ps3000_handle, 0, 1, 0, 10) 'Channel A
Call ps3000_set_channel(ps3000_handle, 1, 1, 0, 10) 'Channel B
Call ps3000_set_channel(ps3000_handle, 2, 0, 0, 10) 'Channel C
Call ps3000_set_channel(ps3000_handle, 3, 0, 0, 10) 'Channel D


So before calling the function we assign values to:
• handle
• timebase
• no_of_samples

However, the others carry a ‘0’ value when the function is called.
• time_interval,
• time_units,
• oversample,
• max_samples


The handle value is determined by what is returned when you open the unit. With regards to time_interval, time_units and max_samples, they have to be set to some arbitrary value (preferably zero) as the driver needs a memory address to write the actual values to as the corresponding function parameters are pointers.

Oversample is not a pointer so that should be a specified value (set to 1 I guess in your case).

The timebase is set in the 'ps3000_run_block()' function. The 'ps3000_get_timebase()' function returns data for the
time interval, such as the maximum number of samples and the time interval.

Instead of calling ps3000_get_values(), you will need to call the ps3000_get_times_and_values() function in order to get the times.

The adc_to_mv function also does not appear in the manual


The adc_to_mv function is one defined in the C example in order to help the programmer with code reuse - it is not
available in the Excel example, so as you mention, you need to scale the ADC output.

The formula you need to use is

Code: Select all
milliVolts = (ADC Count / PS3000_MAX_VALUE) * voltage_range_in_mV


where PS3000_MAX_VALUE is 32767 as defined in the Programmer's Guide (see section 2.3.4 Scaling) and
voltage_range_in_mV would be 20000 if you have selected a voltage range of 20V.

I hope this makes things clearer.

Best wishes,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 1997
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Determining Sample Rate when using 3425

Postby TerryV01 » Thu Aug 23, 2012 11:59 pm

Excellent - Thank You Hitesh
TerryV01
Newbie
 
Posts: 0
Joined: Mon Aug 13, 2012 11:24 pm

Re: Determining Sample Rate when using 3425

Postby Hitesh » Fri Aug 24, 2012 8:44 am

No problem - just realised max_sample_interval should really be min_sample_interval as it is the smallest time interval yet corresponds to the highest sampling rate :D
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 1997
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests