Test and Measurement Forum

Sample C Program Output for Pico 2000 Series

Post your C and C++ discussions here

Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Thu May 19, 2016 1:39 am

Hello All,

I have compiled and ran the Sample C program that comes with the SDK for our Picoscope 2000 series. The numbers that output to a file are shown below. These numbers don't make sense to me except for the time values (First value in each row). It seems as if these values are overflowed values. The function I am executing is collect_block_immediate(). Am I missing something in the program? Please advise.


0 ,-3866684, 65352,,-655371, 31071,
20000 ,15073220, -59306,,-655371, 31071,
40000 ,-3866684, 65352,,-655371, 31071,
60000 ,-3866684, 65352,,-655371, 31071,
80000 ,-3866684, 65352,,-655371, 31071,
100000 ,-3866684, 65352,,-655371, 31071,
120000 ,-3931931, 55396,,-655371, 31071,
140000 ,-3866684, 65352,,-655371, 31071,
160000 ,-3931931, 55396,,-655371, 31071,
180000 ,-3931931, 55396,,-655371, 31071,
200000 ,-3931931, 55396,,-720618, 21115,
220000 ,-3866684, 65352,,-655371, 31071,
240000 ,15007973, 61812,,-655371, 31071,
260000 ,-3931931, 55396,,-655371, 31071,
280000 ,-3866684, 65352,,-655371, 31071,
300000 ,-3866684, 65352,,-655371, 31071,
320000 ,-3931931, 55396,,-655371, 31071,
340000 ,-3931931, 55396,,-655371, 31071,
360000 ,-3931931, 55396,,-655371, 31071,
380000 ,-3866684, 65352,,-655371, 31071,
400000 ,-3866684, 65352,,-655371, 31071,
420000 ,15073220, -59306,,-655371, 31071,
440000 ,15073220, -59306,,-720618, 21115,
460000 ,-3931931, 55396,,-655371, 31071,
480000 ,15007973, 61812,,-655371, 31071,
500000 ,15007973, 61812,,-655371, 31071,
520000 ,15073220, -59306,,-720618, 21115,
540000 ,-3866684, 65352,,-655371, 31071,
560000 ,-3931931, 55396,,-655371, 31071,
580000 ,-3931931, 55396,,-655371, 31071,
600000 ,15073220, -59306,,-655371, 31071,
620000 ,-3866684, 65352,,-655371, 31071,
640000 ,15007973, 61812,,-720618, 21115,
660000 ,15007973, 61812,,-655371, 31071,
680000 ,15007973, 61812,,-655371, 31071,
700000 ,15073220, -59306,,-655371, 31071,
...
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Thu May 19, 2016 5:01 pm

Hello all,

I have now also posted the sample C code from the SDK. Please look and let me
know what I might be doing wrong or what is causing the numbers to
overflow in the output.

Code: Select all
void collect_block_immediate (void)
{
   int32_t      i;
   int32_t    time_interval;
   int16_t    time_units;
   int16_t    oversample;
   int32_t    no_of_samples = BUFFER_SIZE;
   FILE    *fp;
   int16_t    auto_trigger_ms = 0;
   int32_t    time_indisposed_ms;
   int16_t    overflow;
   int32_t    max_samples;
   int16_t ch = 0;

   printf ( "Collect block immediate...\n" );
   printf ( "Press a key to start\n" );
   _getch ();

   set_defaults ();

   /* Trigger disabled */
   ps2000_set_trigger ( unitOpened.handle, PS2000_NONE, 0, PS2000_RISING, 0, auto_trigger_ms );

   /*  find the maximum number of samples, the time interval (in time_units),
   *       the most suitable time units, and the maximum oversample at the current timebase
   */

   oversample = 1;
   while (!ps2000_get_timebase ( unitOpened.handle,
                        timebase,
           no_of_samples,
                        &time_interval,
                        &time_units,
                        oversample,
                        &max_samples))
   timebase++;

   printf ( "timebase: %hd\toversample:%hd\n", timebase, oversample );

   /* Start it collecting,
   *  then wait for completion
   */

   ps2000_run_block ( unitOpened.handle, no_of_samples, timebase, oversample, &time_indisposed_ms );
   
   while ( !ps2000_ready ( unitOpened.handle ) )
   {
      [b]Sleep[/b]( 100 );
   }

   ps2000_stop ( unitOpened.handle );

   /* Should be done now...
   *  get the times (in nanoseconds)
   *   and the values (in ADC counts)
   */
   long result = ps2000_get_times_and_values ( unitOpened.handle, times,
                           unitOpened.channelSettings[PS2000_CHANNEL_A].values,
                           unitOpened.channelSettings[PS2000_CHANNEL_B].values,
                           NULL,
                           NULL,
                           &overflow, time_units, no_of_samples );

   /* Print out the first 10 readings,
   *  converting the readings to mV if required
   */
   printf ( "First 10 readings\n" );
   printf ( "Value\n" );
   printf ( "(%s)\n", adc_units ( time_units ) );

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


   
      if( (fp  = fopen( "data.txt","w" )) == NULL )
            printf( "The file 'data.txt' was not opened\n" );
      else
            printf( "The file 'data.txt' was opened\n" );


   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, ",%d, %d,", unitOpened.channelSettings[ch].values[i],
                                 adc_to_mv ( unitOpened.channelSettings[ch].values[i],   unitOpened.channelSettings[ch].range) );
         }
      }
      fprintf(fp, "\n");
   }
   fclose(fp);
}
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Hitesh » Tue May 24, 2016 8:56 am

Hi Rogue95,

Could you please provide the following information:

  • Voltage range settings for channels A and B
  • PicoScope device being used
  • Version of the ps2000 dll that is being used
  • Input signal being applied

Regards,
Hitesh

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

Re: Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Thu May 26, 2016 12:00 am

Hi Hitesh,

Thanks for replying and helping me. Sorry for my my delay in replying. I've been researching the answers to give you.

Please note that I have not changed any settings in the C++ sample code. I'm just running it with the defaults. I have taken the sample C++ code from the PicoSDK, copied it, and pasted it into my old Visual C++ 6.0 IDE. I had to comment out a few lines to make it compile and work properly, but it connects to a Picoscope and fetches the device information just fine (i.e. driver version, USB version, hardware version, device model, serial number, and calendar date). Of course, the problem is in the Channel A and B data that gets printed out (as you can see from the list of numbers I had sent in one of the previous posts). The data looks like overflowed numbers.

Now to answer your questions:

1) Voltage range settings for channels A and B - Well, when I pull up the Picoscope screen, it shows +/- 10V for Channel A and +/- 5V for Channel B. Does this sound correct? If not, let me
know where to look.

2) PicoScope device being used -
Picoscope 2000 Series, model 2204A

3) Version of the ps2000 dll that is being used -
The dll is from PicoSDK version 10.6.10.24 for 32-bit PC

4) Input signal being applied - I'm not sure how to answer this question. I know our Picoscopes
are connected to inverters which are going through a battery of tests for durability, reliability, etc... The inverter that is currently connected has 48V input. Does this answer the question?
If not, please let me know where to look.
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Thu May 26, 2016 4:41 pm

Hi Hitesh,

I got more accurate answers to your questions. Please see below.
Hope to hear back from you soon.

1) Voltage range settings for channels A and B - It is actually +/- 10V for Channel A and
+/- 1V for Channel B.

2) PicoScope device being used - Picoscope 2000 Series, model 2204A

3) Version of the ps2000 dll that is being used - The dll is from PicoSDK version 10.6.10.24
for 32-bit PC

4) Input signal being applied - DC voltages
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Tue May 31, 2016 10:22 pm

Hi Hitesh,

Is there any more information that you need?
Please let me know.

Thanks,

Rogue95
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Hitesh » Wed Jun 01, 2016 9:52 am

Hi Rogue95,

Thank you for the information.

What is the DC voltage level you are measuring and what is the value of the overflow flag when you call ps2000_get_times_and_values()?

Regards,
Hitesh

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

Re: Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Fri Jun 03, 2016 12:52 am

Hi Hitesh,

This is the answer my Boss and head engineer have given: The DC voltage we are measuring is 48v (range of about 35v to 70v), but a 10 to 1 resistive divider is used which attenuates the signal so that is why the channel A is set to +/- 10v (35 to 70v divided by 10 is 3.5 to 7 volts). The maximum voltage presented to the Picoscope is less than 10v.

The overflow flag has a value of -859045888 after calling ps2000_get_times_and_values().

Again, for this sample C program which I got from the PicoSDK, I have not changed any code.
I'm running it as is in my Visual C++ 6.0 compiler/IDE. The information I get for the Driver version, Device name, Serial number, etc..., are correct, but the output for the values are incorrect.
Please advise.

Thanks,

Rogue95
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Hitesh » Fri Jun 03, 2016 10:27 am

Hi Rogue95,

Rogue95 wrote:The overflow flag has a value of -859045888 after calling ps2000_get_times_and_values().


Is that when you print to screen or view the value of the variable using the debugging tools in Visual Studio?

How do the array values appear in the debugger window if you choose to add a watch on the variables?

Are you using the default compiler settings for your IDE?

Regards,
Hitesh

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

Re: Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Fri Jun 03, 2016 11:28 pm

Hi Hitesh,

I am taking the overflow flag variable, converting it into a string, and
then printing it out onto a message box.

Actually, the way I'm setup, I'm compiling the code at my PC, and then
running the executable on another PC that is attached to the Picoscope
and test fixture for the inverter that is getting tested.
So, in other words, I wouldn't be able to run the debugger on the PC
with the Picoscope, and, hence, can't use the watch variables.

As far as I can remember, yes, I'm using the default compiler settings on
my VC++ 6.0 compiler.

Please advise.

Thanks,

Rogue95
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Hitesh » Mon Jun 06, 2016 8:21 am

Hi Rogue95,

Are you able to disconnect the PicoScope and connect it to your Development PC at all?

It would be helpful to see the code you are using to display the overflow flag value.

Regards,
Hitesh

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

Re: Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Tue Jun 07, 2016 8:10 pm

Hi Hitesh,

It would be difficult to remove the Picoscope and connect it to my PC.
It's currently attached to a rack by the engineers.

The code I'm using to display the value is in the below snippet.
Please take a look and let me know.

- Rogue95


int32_t i;
int32_t time_interval;
int16_t time_units;
int16_t oversample;
int32_t no_of_samples = BUFFER_SIZE;
FILE *fp;
int16_t auto_trigger_ms = 0;
int32_t time_indisposed_ms;
int16_t overflow;
int32_t max_samples;
int16_t ch = 0;

...
long result = ps2000_get_times_and_values ( unitOpened.handle, times,
unitOpened.channelSettings[PS2000_CHANNEL_A].values, unitOpened.channelSettings[PS2000_CHANNEL_B].values,
NULL, NULL, &overflow, time_units, no_of_samples );

CString temp;
temp.Format("Overflow = %d", overflow);
AfxMessageBox(temp); // *** Overflow value gets displayed to the screen. ***
...
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Hitesh » Thu Jun 09, 2016 8:02 am

Hi Rogue95,

Are you able to print the value of overflow to a console window?

What happens if you change the data type from int16_t to short?

If this does not help, would you be able to send a copy of your project to support@picotech.com so that we can try running it here?

Regards,
Hitesh

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

Re: Sample C Program Output for Pico 2000 Series

Postby Rogue95 » Fri Jun 10, 2016 11:25 pm

Hi Hitesh,

I printed the value of the overflow flag to a console window
via the printf statement, but got the same result. Value is still -859045888.

I also changed the datatype from int16_t to short, but that only
made the compiler error. It stated that parameter 7 in the
ps2000_get_times_and_values() call required an int16_t instead
of a short. So no luck here. :(

I have went ahead and emailed you the Visual C++ 6 project. Please
run it on your end with a Picoscope 2000 series (model 2204A if possible)
and let me know if you can get it to output the correct numbers.
Please Note: In the program, I am choosing option "B" (Immediate block). Thanks.

- Rogue95
Rogue95
Newbie
 
Posts: 0
Joined: Wed Apr 20, 2016 7:56 pm

Re: Sample C Program Output for Pico 2000 Series

Postby Hitesh » Tue Jun 21, 2016 9:10 am

Hi Rogue95,

I'm just posting an update here for the benefit of other Users.

Having conducted some tests, I think that this is due to a project setting. Using a more up to date version of Microsoft Visual Studio (including Express editions) with your source files would be advised (our example C code solutions are saved with Visual C++ Express 2010) and it might be better to start with a new project and check the settings.

I will wait to hear back on your e-mail support ticket.

Regards,
Hitesh

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


Return to C and C++

Who is online

Users browsing this forum: No registered users and 1 guest