PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
void runSweep(LPCTSTR szPort, double start, double stop, int points) {
_TCHAR buf[400];
//_stprintf_s(buf, _T("%s Start: %lf, Stop: %lf, Steps: %d"), szPort, start, stop, points);
//AfxMessageBox(buf, MB_OK | MB_SYSTEMMODAL | MB_ICONINFORMATION, MB_ICONINFORMATION);
//char ch;
PICO_STATUS status;
UNIT unit;
printf("PS3000A driver example program\n");
printf("\nOpening the device...\n");
//status = PICO_USER_CALLBACK;
//CHECKIT;
//return;
// 1. Open the oscilloscope using ps3000aOpenUnit().
status = openDevice(&unit);
CHECKIT;
// 2. Select channel ranges and AC / DC coupling using ps3000aSetChannel().
const PS3000A_RANGE range = PS3000A_1V;
const float conv = 1.0f / 32512 * 10.0f;
status = ps3000aSetChannel(unit.handle, PS3000A_CHANNEL_A, TRUE, PS3000A_DC, range, 0.0f);
CHECKIT;
// 3.[MSOs only] Set the digital port using ps3000aSetDigitalPort().
;
// 3.5. ps3000aMemorySegments
const uint32_t noCaptures = 128;
const int32_t noSamples = 100000;
int32_t maxSamples = 0;
status = ps3000aMemorySegments(unit.handle, noCaptures, &maxSamples);
CHECKIT;
if (maxSamples < noSamples) {
status = maxSamples;
CHECKIT;
}
// 4. Using ps3000aGetTimebase(), select timebases until the required nanoseconds per sample is located.
float targetTimeIntervalNs = 1.0f;
float timeIntervalNs = 0.0f;
uint32_t timebase = 0;;
{
uint64_t timebaseUpper = 1LL << 32;
int32_t maxSamples2 = 0;
while (((uint64_t)timebaseUpper - (uint64_t)1) > (uint64_t)timebase) {
uint32_t timebaseMid = timebase + (timebaseUpper - timebase) / 2;
status = ps3000aGetTimebase2(unit.handle, timebaseMid, noSamples, &timeIntervalNs, 0, &maxSamples2, 0); // error 14
if (status == PICO_INVALID_TIMEBASE) {
timeIntervalNs = -1;
++timebaseMid;
status = PICO_OK;
}
CHECKIT;
if (timeIntervalNs > targetTimeIntervalNs) {
timebaseUpper = timebaseMid;
}
else {
timebase = timebaseMid;
}
}
while ((status = ps3000aGetTimebase2(unit.handle, timebase, noSamples, &timeIntervalNs, 0, &maxSamples2, 0)) == PICO_INVALID_TIMEBASE) {
++timebase;
}
CHECKIT;
if (maxSamples2 < noSamples) {
status = maxSamples2;
CHECKIT;
}
}
_stprintf_s(buf, _T("Timebase: %d, TimeIntervalNs: %f"), (int)timebase, timeIntervalNs);
AfxMessageBox(buf, MB_OK | MB_SYSTEMMODAL | MB_ICONINFORMATION, MB_ICONINFORMATION);
// 5. Use the trigger setup functions ps3000aSetTriggerChannelConditionsV2(), ps3000aSetTriggerChannelDirections() and ps3000aSetTriggerChannelProperties() to set up the trigger if required.
status = ps3000aSetTriggerChannelProperties(unit.handle, NULL, 0, 0, 0);
CHECKIT;
PS3000A_TRIGGER_CONDITIONS_V2 whatevs;
whatevs.channelA = PS3000A_CONDITION_DONT_CARE;
whatevs.channelB = PS3000A_CONDITION_DONT_CARE;
whatevs.channelC = PS3000A_CONDITION_DONT_CARE;
whatevs.channelD = PS3000A_CONDITION_DONT_CARE;
whatevs.external = PS3000A_CONDITION_DONT_CARE;
whatevs.aux = PS3000A_CONDITION_DONT_CARE;
whatevs.pulseWidthQualifier = PS3000A_CONDITION_DONT_CARE;
whatevs.digital = PS3000A_CONDITION_TRUE;
status = ps3000aSetTriggerChannelConditionsV2(unit.handle, &whatevs, 1);
CHECKIT;
// 6.[MSOs only] Use the trigger setup functions ps3000aSetTriggerDigitalPortProperties() to set up the digital trigger if required.
PS3000A_DIGITAL_CHANNEL_DIRECTIONS trigger;
trigger.channel = PS3000A_DIGITAL_CHANNEL_11;
trigger.direction = PS3000A_DIGITAL_DIRECTION_FALLING;
status = ps3000aSetTriggerDigitalPortProperties(unit.handle, &trigger, 1);
CHECKIT;
// {
// 7. Set the number of memory segments equal to or greater than the number of captures required using ps3000aMemorySegments(). Use ps3000aSetNoOfCaptures() before each run to specify the number of waveforms to capture.
status = ps3000aSetNoOfCaptures(unit.handle, noCaptures);
CHECKIT;
// 8. Start the oscilloscope running using ps3000aRunBlock().
status = ps3000aRunBlock(unit.handle, 50000, 50000, timebase, 0, NULL, 0, NULL, NULL);
CHECKIT;
// 9. Wait until the oscilloscope is ready using the ps3000aIsReady() or wait on the callback function.
for (;;) {
int16_t ready = 0;
status = ps3000aIsReady(unit.handle, &ready);
CHECKIT;
if (ready) break;
}
_stprintf_s(buf, _T("Done."));
AfxMessageBox(buf, MB_OK | MB_SYSTEMMODAL | MB_ICONINFORMATION, MB_ICONINFORMATION);
// 10. Use ps3000aSetDataBuffer() to tell the driver where your memory buffers are.
int16_t *buffers[noCaptures];
for (int segment = 0; segment < noCaptures; segment++) {
buffers[segment] = (int16_t*)malloc(sizeof(int16_t) * noSamples);
if (buffers[segment] == 0) {
status = 1337;
CHECKIT;
}
status = ps3000aSetDataBuffer(unit.handle, PS3000A_CHANNEL_A, buffers[segment], noSamples, segment, PS3000A_RATIO_MODE_NONE);
CHECKIT;
}
// 11. Transfer the blocks of data from the oscilloscope using ps3000aGetValuesBulk().
uint32_t actualSamples = noSamples;
int16_t overflow[noCaptures];
status = ps3000aGetValuesBulk(unit.handle, &actualSamples, 0, noCaptures - 1, 1, PS3000A_RATIO_MODE_NONE, overflow);
CHECKIT;
// 14. Repeat steps 7 to 13 if necessary.
// 15. Stop the oscilloscope using ps3000aStop().
status = ps3000aStop(unit.handle);
CHECKIT;
closeDevice(&unit);
}
Code: Select all
ps3000aSetDigitalPort(unit.handle, PS3000A_DIGITAL_PORT1, 1, 3276 /* 0.5V */);
With regards to the crash, would it be possible to send your code in to support@picotech.com please? I can then test it here.The maximum number of values depends upon the size of the oscilloscope's memory. The memory buffer is shared between the enabled channels, so if two channels are enabled, each receives half the memory. If three or four channels are enabled, each receives a quarter of the memory. These calculations are handled transparently by the driver. The block size also depends on the number of memory segments in use (see ps3000aMemorySegments).
For the PicoScope 3000 and 3000D Series MSOs, the memory is shared between
the digital ports and analog channels. If one or more analog channels is enabled at
the same time as one or more digital ports, the memory per channel is one quarter
of the buffer size.