RapidBlock mode

Post any questions you may have about our current range of oscilloscopes
Post Reply
alavudeen
Newbie
Posts: 0
Joined: Tue Jul 28, 2020 9:48 am

RapidBlock mode

Post by alavudeen »

I am using PicoScope 3000 unit for collecting data in Rapid mode. It works fine if the unit is allowed to collect all captures. But the data collected goes wrong if the data collection is stopped by ps3000aStop then download. ps3000aGetNoOfCaptures is used to know number of finished captures before downloading. Very first wave form looks correct. Second one looks like having a some pre trigger samples, third one some more pre trigger samples and so on though the channels are configured for zero pre trigger.

Following hardware and software are used
Picoscope 3203D
PicoSDK 64Bit 10.6.13.97

I used ps3000aCExamples to reproduce the problem. Both A channel and B channels are enabled. Trigger is configured on EXT channel. Trigger pulse is issued at an interval of 2 ms. Numberof capture is set to 1000 and RunBlock is called. StopBlock is called after 200 ms from RunBlock call. Around 100 waveforms will be collected instead of 1000. See below the function collectRapidBlock. Whole file ps3000aCon.c is attached. In my application, Picoscope will be set in Rapid collection mode with maximum number of captures, then stopblock will be called after some time, before finishing all captures. Please advice how to download data

void collectRapidBlock(UNIT * unit)
{
char fileName[1000];
FILE* filePointer;

int16_t i;
int16_t retry;
int16_t channel;
int16_t *overflow;
int16_t ***rapidBuffers;

int32_t nMaxSamples;
int32_t timeIndisposed;
int32_t timeIntervalNs;
int32_t maxSamples;

uint32_t nSegments;
uint32_t nCaptures;
uint32_t capture;
uint32_t nSamples = 1000;
uint32_t nCompletedCaptures;
uint32_t maxSegments;

PICO_STATUS status;

unit->channelSettings[PS3000A_CHANNEL_A].enabled = 1;
unit->channelSettings[PS3000A_CHANNEL_B].enabled = 1;

// Set level trigger on Channel A

int16_t triggerVoltage = mv_to_adc(1000, unit->channelSettings[PS3000A_CHANNEL_A].range, unit);

struct tPS3000ATriggerChannelProperties sourceDetails = { triggerVoltage,
256 * 10,
triggerVoltage,
256 * 10,
PS3000A_CHANNEL_A,
PS3000A_LEVEL};

struct tPS3000ATriggerConditionsV2 conditions = { PS3000A_CONDITION_TRUE,
PS3000A_CONDITION_DONT_CARE,
PS3000A_CONDITION_DONT_CARE,
PS3000A_CONDITION_DONT_CARE,
PS3000A_CONDITION_DONT_CARE,
PS3000A_CONDITION_DONT_CARE,
PS3000A_CONDITION_DONT_CARE,
PS3000A_CONDITION_DONT_CARE};

struct tPwq pulseWidth;

struct tTriggerDirections directions = { PS3000A_RISING,
PS3000A_NONE,
PS3000A_NONE,
PS3000A_NONE,
PS3000A_NONE,
PS3000A_NONE };

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

printf("Collect rapid block triggered...\n");
printf("Collects when value rises past %d", scaleVoltages?
adc_to_mv(sourceDetails.thresholdUpper, unit->channelSettings[PS3000A_CHANNEL_A].range, unit) // If scaleVoltages, print mV value
: sourceDetails.thresholdUpper); // else print ADC Count

printf(scaleVoltages?"mV\n" : "ADC Counts\n");
printf("Press any key to abort\n");

setDefaults(unit);

ps3000aSetSimpleTrigger(unit->handle, 1, PS3000A_EXTERNAL, 9600, PS3000A_FALLING, 0, 0);
// Trigger enabled
//setTrigger(unit, &sourceDetails, 1, &conditions, 1, &directions, &pulseWidth, 0, 0, 0, 0, 0);

// Find the maximum number of segments
status = ps3000aGetMaxSegments(unit->handle, &maxSegments);

printf("Max. number of segments for device: %d\n", maxSegments);

// Set the number of segments
nSegments = 1000;

// Set the number of captures
nCaptures = 1000;

// Segment the memory
status = ps3000aMemorySegments(unit->handle, nSegments, &nMaxSamples);

// Set the number of captures
status = ps3000aSetNoOfCaptures(unit->handle, nCaptures);

// Verify timebase index is valid, sample interval will be device dependent
timebase = 10;

/* Find the maximum number of samples and the time interval (in nanoseconds) */

status = PICO_INVALID_TIMEBASE;

do
{
status = ps3000aGetTimebase(unit->handle, timebase, nSamples, &timeIntervalNs, oversample, &maxSamples, 0);

if (status != PICO_OK)
{
timebase++;
}
}
while (status != PICO_OK);

printf("\nTimebase: %lu Sample interval: %ld ns\n Max samples per channel per segment: %ld\n", timebase, timeIntervalNs, maxSamples);

printf("Starting data capture for %d waveforms...\n", nCaptures);

do
{
retry = 0;

status = ps3000aRunBlock(unit->handle, 0, nSamples, timebase, 1, &timeIndisposed, 0, callBackBlock, NULL);

if(status != PICO_OK)
{
if(status == PICO_POWER_SUPPLY_CONNECTED || status == PICO_POWER_SUPPLY_NOT_CONNECTED)
{
status = changePowerSource(unit->handle, status);
retry = 1;
}
else
{
printf("RapidBlockDataHandler:ps3000aRunBlock ------ 0x%08lx \n", status);
printf("Press any key to continue (data collection will be aborted).\n");
}
}
}
while(retry);

//Wait until data ready
g_ready = 0;
//int waitedms = 0;
//while(!g_ready)// && !_kbhit())
//{
// //Sleep(0);
// waitedms += 100 * 2;
// Sleep(100 * 2);
// if ((waitedms % 1000) == 0)
// {
// printf("Waited.. %d\n", waitedms);
// }
//}
//Sleep((nCaptures + 1) * 2);
Sleep(100 * 2);
printf("g_ready.. %d\n", g_ready);
if (!g_ready)
{
_getch();
status = ps3000aStop(unit->handle);
status = ps3000aGetNoOfCaptures(unit->handle, &nCompletedCaptures);
printf("Rapid capture aborted. %lu complete blocks were captured\n", nCompletedCaptures);
printf("\nPress any key...\n\n");
_getch();

if(nCompletedCaptures == 0)
{
return;
}

// Only display the blocks that were captured
nCaptures = nCompletedCaptures;
}

//Allocate memory

rapidBuffers = (int16_t ***) calloc(unit->channelCount, sizeof(int16_t*));
overflow = (int16_t *) calloc(unit->channelCount * nCaptures, sizeof(int16_t));

for (channel = 0; channel < unit->channelCount; channel++)
{
if(unit->channelSettings[channel].enabled)
{
rapidBuffers[channel] = (int16_t **) calloc(nCaptures, sizeof(int16_t*));
}
else
{
rapidBuffers[channel] = NULL;
}
}

for (channel = 0; channel < unit->channelCount; channel++)
{
if(unit->channelSettings[channel].enabled)
{
for (capture = 0; capture < nCaptures; capture++)
{
rapidBuffers[channel][capture] = (int16_t *) calloc(nSamples, sizeof(int16_t));
}
}
}

for (channel = 0; channel < unit->channelCount; channel++)
{
if(unit->channelSettings[channel].enabled)
{
for (capture = 0; capture < nCaptures; capture++)
{
status = ps3000aSetDataBuffer(unit->handle, (PS3000A_CHANNEL)channel, rapidBuffers[channel][capture], nSamples, capture, PS3000A_RATIO_MODE_NONE);
}
}
}

// Retrieve data
status = ps3000aGetValuesBulk(unit->handle, &nSamples, 0, nCaptures - 1, 1, PS3000A_RATIO_MODE_NONE, overflow);

if (status == PICO_POWER_SUPPLY_CONNECTED || status == PICO_POWER_SUPPLY_NOT_CONNECTED)
{
printf("\nPower Source Changed. Data collection aborted.\n");
}

if (status == PICO_OK)
{

for (channel = 0; channel < unit->channelCount; channel++)
{
sprintf(fileName, "C:\\debugScratch\\C%d", channel);
filePointer = fopen(fileName, "wb");

for (capture = 0; capture < nCaptures; capture++)
{
//printf("\nCapture %d:-\n\n", capture + 1);
void* dataBuff = rapidBuffers[channel][capture];

fwrite(dataBuff, sizeof(short), nSamples, filePointer);

}
fclose(filePointer);
}


//print first 10 samples from each capture
for (capture = 0; capture < nCaptures; capture++)
{
printf("\nCapture %d:-\n\n", capture + 1);

for (channel = 0; channel < unit->channelCount; channel++)
{
if(unit->channelSettings[channel].enabled)
{
printf("Channel %c:\t", 'A' + channel);
}
}

printf("\n");

for(i = 0; i < 10; i++)
{
for (channel = 0; channel < unit->channelCount; channel++)
{
if(unit->channelSettings[channel].enabled)
{
printf(" %6d ", scaleVoltages ?
adc_to_mv(rapidBuffers[channel][capture], unit->channelSettings[PS3000A_CHANNEL_A +channel].range, unit) // If scaleVoltages, print mV value
: rapidBuffers[channel][capture]); // else print ADC Count
}
}
printf("\n");
}
}
}

// Stop
status = ps3000aStop(unit->handle);

//Free memory
free(overflow);

for (channel = 0; channel < unit->channelCount; channel++)
{
if (unit->channelSettings[channel].enabled)
{
for (capture = 0; capture < nCaptures; capture++)
{
free(rapidBuffers[channel][capture]);
}
}
}

for (channel = 0; channel < unit->channelCount; channel++)
{
if (unit->channelSettings[channel].enabled)
{
free(rapidBuffers[channel]);
}
}

free(rapidBuffers);

// Set nunmber of segments and captures back to 1
status = ps3000aMemorySegments(unit->handle, (uint32_t) 1, &nMaxSamples);
status = ps3000aSetNoOfCaptures(unit->handle, 1);
}
Attachments
ps3000aCon.c
(78.34 KiB) Downloaded 367 times

Post Reply