Trouble graphing a signal from a 2205A

Post any questions you may have about our current range of oscilloscopes
Post Reply
searchresults
Newbie
Posts: 0
Joined: Thu Oct 06, 2011 7:48 pm

Trouble graphing a signal from a 2205A

Post by searchresults »

I'm trying to display the signal from an ECG amplifier (aka heartbeat reader.) I have confirmed the ECG unit works well by testing it on an oscilloscope.

However, I'm having trouble with my code to graph the signal from a Picoscope 2205A.

To test my code, I have been running a signal generator directly into my 2205A. I attached an image of my code rendering a triangle wave (with limited success.)

Does anyone know what may be wrong? I'm posting some of my code below.

Code: Select all

static int input_ranges [PS2000_MAX_RANGES] = {10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000};


void ofPicoScope::beginStreaming(int secToRec, int sampPerSec)
{
	bStreamData=true;
	tracePoint=0;

	bufferLength=secToRec;
	sampsPerSec=sampPerSec;

	printf ( "Begin streaming...\n" );

	set_defaults ();

	ps2000_set_trigger ( unitOpened.handle, PS2000_NONE, 0, 0, 0, 0 );

	/* Collect data at 10ms intervals
	* Max BUFFER_SIZE points on each call
	*  (buffer must be big enough for max time between calls
	*/

	cout << "Streaming with " << BUFFER_SIZE << endl;

	//ps2000_run_streaming ( unitOpened.handle, 10,1000, 0 );
	//ps2000_run_streaming_ns (
	ps2000_run_streaming_ns ( unitOpened.handle, 1000000/sampsPerSec, PS2000_US, 10000, 0, 1, 50000 );

	startThread();
}

void ofPicoScope::setup()
{
	printf ( "PS2000 driver example build for openFrameworks\n" );

	printf ( "\n\nOpening the device...\n");

	//open unit and show splash screen
	unitOpened.handle = ps2000_open_unit ();

	printf ( "Handler: %d\n", unitOpened.handle );

	if(!unitOpened.handle) printf("Unable to open the device; check connections.\n"),bInited=false;
	else bInited=true;

	get_info();

	set_voltages(8); //this is where the voltage is selected from the list (see above)
}

void ofPicoScope::set_voltages (int num)
{
  int		i;
	short ch = 0;

  /* See what ranges are available...
   */
  for ( i = unitOpened.firstRange; i <= unitOpened.lastRange; i++ )
  {
    printf ( "%d -> %d mV\n", i, input_ranges[i] );
  }

  if(num > unitOpened.firstRange && num < unitOpened.lastRange){  // sets the voltage to the input...only if it's possible
	unitOpened.channelSettings[ch].range=num;
  }
}

This is where I'm drawing the graph (I'm using openFrameworks):

Code: Select all

void testApp::drawGraph() {
	ofEnableSmoothing();
	ofSetLineWidth(2);
	ofSetColor(201, 219, 84);
	for(unsigned int i=0; picoScope().trace.size()>10&&i
Attachments
I'm passing a triangle wave directly into my Picoscope.  My code is mangling the graph.
I'm passing a triangle wave directly into my Picoscope. My code is mangling the graph.

Hitesh

Re: Trouble graphing a signal from a 2205A

Post by Hitesh »

Hi,

Presumably you have a PicoScope 2205 as opposed to the 2205 MSO?

Try writing the voltage values from the PicoScope to a text file and plotting them in a spreadsheet tool like MS Excel to confirm that the wave appears as expected.

I've seen this kind of effect whilst working on a different application - it's possible the x-axis values are being rounded - it might be worth using a data type such as a double to try and ensure the values are distinct.

Regards,

searchresults
Newbie
Posts: 0
Joined: Thu Oct 06, 2011 7:48 pm

Re: Trouble graphing a signal from a 2205A

Post by searchresults »

Hi Hitesh,
We tried those things out, but we're still having problems.

We think we narrowed it down a bit: it's taking 1/8 second to execute the code below, which is likely causing the jerkiness.

Are we doing something wrong?

Code: Select all


while ( bStreamData )
	{
		ps2000_get_streaming_last_values (unitOpened.handle, ps2000FastStreamingReady);
		ps2000_stop (unitOpened.handle);
		no_of_values = 0;
		no_of_values = ps2000_get_streaming_values_no_aggregation (unitOpened.handle,
										&startTime, // get samples from the beginning
										values_a, // set buffer for channel A
										values_b,	// set buffer for channel B
										NULL,
										NULL,
										&overflow,
										&triggerAt,
										&triggered,
										BUFFER_SIZE_STREAMING);

		ps2000_run_streaming_ns ( unitOpened.handle, 1000000/sampsPerSec, PS2000_US, BUFFER_SIZE_STREAMING, 1, 1, 50000 );  //changed 100 to 50
		
		// Print out all of the readings just received
		if(no_of_values){
			printf ( "%d values\n", no_of_values );
			for (int i = 0; i < no_of_values; i++ ){
				short ch=0;
				if (unitOpened.channelSettings[ch].enabled){
					if(trace.size()=bufferLength*sampsPerSec-1) marker=0;
					}
				}
			}
		}

		
		
		
	}


Hitesh

Re: Trouble graphing a signal from a 2205A

Post by Hitesh »

Hi,

Thanks for your reply.

Looking at the sequencing of the function calls, I would suggest it is better to follow the structure in the Programmer's Guide (see section 3.3.8.10 - Using fast streaming mode), particularly the following:
  • Call ps2000_run_streaming_ns()
  • Setup while loop, inside which call ps2000_get_streaming_last_values()
  • Call ps2000_stop ()
  • Call ps2000_get_streaming_values_no_aggregation()
As you are using auto_stop set to 1, the streaming will stop, then start again on the next iteration of the while loop which isn't a recommended way of doing this. It might be worth setting auto_stop to 0, unless you want to stop after a particular number of samples.

This should give you something like this:

Code: Select all

       ps2000_run_streaming_ns ( unitOpened.handle, 1000000/sampsPerSec, PS2000_US, BUFFER_SIZE_STREAMING, 0, 1, 50000 );  //changed 100 to 50
    
       while ( bStreamData )
       {
          ps2000_get_streaming_last_values (unitOpened.handle, ps2000FastStreamingReady);
          
          // Print out all of the readings just received
          if(no_of_values)
          {
             printf ( "%d values\n", no_of_values );
             
             for (int i = 0; i < no_of_values; i++ )
             {
                short ch=0;
                
                if (unitOpened.channelSettings[ch].enabled)
                {
                   if(trace.size()=bufferLength*sampsPerSec-1) marker=0;
                   }
                }
             }
          } 
        }
        
        ps2000_stop (unitOpened.handle);
          
        no_of_values = 0;
        no_of_values = ps2000_get_streaming_values_no_aggregation (unitOpened.handle,
                                  &startTime, // get samples from the beginning
                                  values_a, // set buffer for channel A
                                  values_b,   // set buffer for channel B
                                  NULL,
                                  NULL,
                                  &overflow,
                                  &triggerAt,
                                  &triggered,
                                  BUFFER_SIZE_STREAMING);
      

Post Reply