Test and Measurement Forum

6402A: Problem measuring a basic signal [beginner thread]

Post your C and C++ discussions here

6402A: Problem measuring a basic signal [beginner thread]

Postby jensl » Thu Feb 28, 2013 11:41 am

Hello,

i want to use the PicoScope 6402A for measurements via C-Code (LabWindowsCVI).

I use the example code and tryed to get a basic signal (rectangular 5kHz, 5Vss, 50%DutyCycle, 2,5Voffset) measured via that C-Code over ChannelA. With the PicoScope6 Tool it's no problem to do so ...

But if I try the following code (based on pico exaxmples) all Functions (ps6000xxxxxx) will give me a positiv feedback (PICO_OK = 0) except ps6000GetValues( ... ) ... and thats my problem ... picoscope seems not to see any trigger event.

Maybe some of you guys have some hints for me?
Maybe also someone give me some hints how to use the ps6000GetTimebase() function ... i think theres the problem.
Thanks in advance!

Code: Select all
...
status = ps6000OpenUnit(&(unit.handle), NULL);
...
CollectBlockTriggered(&unit);
....

void CollectBlockTriggered(UNIT *unit)
{

   short triggerVoltage = mv_to_adc(500, unit->channelSettings[PS6000_CHANNEL_A].range);
   short triggerVoltageHys = mv_to_adc(0, unit->channelSettings[PS6000_CHANNEL_A].range);

   struct tPS6000TriggerChannelProperties sourceDetails = {   triggerVoltage,
                  triggerVoltageHys,
                  triggerVoltage,
                  triggerVoltageHys,
                  (PS6000_CHANNEL)(PS6000_CHANNEL_A),
                  PS6000_LEVEL};

   struct tPS6000TriggerConditions conditions = {   PS6000_CONDITION_TRUE,
                  PS6000_CONDITION_DONT_CARE,
                  PS6000_CONDITION_DONT_CARE,
                  PS6000_CONDITION_DONT_CARE,
                  PS6000_CONDITION_DONT_CARE,
                  PS6000_CONDITION_DONT_CARE,
                  PS6000_CONDITION_DONT_CARE};

   struct tPwq pulseWidth;
               struct tTriggerDirections directions = {   PS6000_RISING,
               PS6000_NONE,
               PS6000_NONE,
               PS6000_NONE,
               PS6000_NONE,
               PS6000_NONE };

   memset(&pulseWidth, 0, sizeof(struct tPwq));

   //SetDefaults(unit);

   SetTrigger(unit->handle, &sourceDetails, 1, &conditions, 1, &directions, &pulseWidth, 0, 0, 0);

   BlockDataHandler(unit, "Ten readings after trigger\n", 0);
}

void BlockDataHandler(UNIT * unit, char * text, int offset)
{
   int i = 0, j;
   long timeInterval = 1;
   long sampleCount= BUFFER_SIZE;
   FILE * fp=NULL;
   unsigned long maxSamples;
   short * buffers[PS6000_MAX_CHANNEL_BUFFERS];
   long timeIndisposed;
   PICO_STATUS status;


   buffers[0] = (short*)malloc(sampleCount * sizeof(short));
   buffers[1] = (short*)malloc(sampleCount * sizeof(short));
   status = ps6000SetDataBuffers(unit->handle, (short)0, buffers[0], buffers[1], sampleCount, PS6000_RATIO_MODE_NONE);

   printf("BlockDataHandler:ps6000SetDataBuffers(channel %d) ------ %d \n", i, status);

   while (ps6000GetTimebase(unit->handle, timebase, sampleCount, &timeInterval, oversample, &maxSamples, 0))
   {
      timebase++;
   }

   /* Start it collecting, then wait for completion*/
   if((status = ps6000RunBlock(unit->handle, 0, sampleCount, timebase, oversample,   &timeIndisposed, 0, CallBackBlock, NULL)) != PICO_OK)

   status = ps6000GetValues(unit->handle, 0, (unsigned long*) &sampleCount, 1, PS6000_RATIO_MODE_NONE, 0, NULL);
         printf("BlockDataHandler:ps6000GetValues ------ %i \n", status);
         
         ....
jensl
Newbie
 
Posts: 0
Joined: Thu Feb 28, 2013 11:26 am

Re: 6402A: Problem measuring a basic signal [beginner thread

Postby Martyn » Thu Feb 28, 2013 11:59 am

The return from GetValues will be one of
Code: Select all
PICO_OK
PICO_INVALID_HANDLE
PICO_NO_SAMPLES_AVAILABLE
PICO_DEVICE_SAMPLING
PICO_NULL_PARAMETER
PICO_SEGMENT_OUT_OF_RANGE
PICO_INVALID_PARAMETER
PICO_TOO_MANY_SAMPLES
PICO_DATA_NOT_AVAILABLE
PICO_STARTINDEX_INVALID
PICO_INVALID_SAMPLERATIO
PICO_INVALID_CALL
PICO_NOT_RESPONDING
PICO_MEMORY
PICO_RATIO_MODE_NOT_SUPPORTED
PICO_DRIVER_FUNCTION


I am guessing that, as you are not waiting for a ready from the scope, the return value is either
PICO_NO_SAMPLES_AVAILABLE or PICO_DEVICE_SAMPLING

For the timebase code I would suggest looking at the programmers guide which explains Timebases in Section 3.7, the sample interval for each timebase is
Code: Select all
0 => 200 ps
1 => 400 ps
2 => 800 ps
3 => 1.6 ns
4 => 3.2 ns
5 => 6.4 ns
...
232-1 => ~ 6.87 s

and what is allowable depends upon the number of channels enabled
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: 6402A: Problem measuring a basic signal [beginner thread

Postby jensl » Thu Feb 28, 2013 12:46 pm

Hi Martyn,

found the problem. It was very simple. The Pico wasn't ready to give back those measurements. The device was still sampling.
I insert between ps6000RunBlock(...) & ps6000GetValues(...) a loop with ps6000IsReady(...).
Thanks for your help.

kind regards
jensl
Newbie
 
Posts: 0
Joined: Thu Feb 28, 2013 11:26 am


Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests