PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
/****************************************************************************
*
* PicoScope_5242A_init_config
* this function opens the pico scope 5242A and configures the channels and trigger
*
****************************************************************************/
void PicoScope_5242A_init_config(void)
{
char Error[100];
static int statusOpenUnit=1;
PICO_STATUS status=1;
float PS5000A_CHANNEL_A_OFFSET, PS5000A_CHANNEL_B_OFFSET;
int iTriggerThresholdADCCount, iAutoTrigger_ms, autoTriggerMilliseconds;
unsigned int iTriggerDelay;
short nChannelProperties, thresholdUpper, thresholdUpperHysteresis, thresholdLower, thresholdLowerHysteresis;
uint32_t timebase;
int32_t noSamples;
float timeIntervalNanoseconds;
int32_t maxSamples;
uint32_t segmentIndex;
float maximumVoltage, minimumVoltage;
// Structure for trigger conditions
struct tPS5000ATriggerConditions CHA_Conditions = { PS5000A_CONDITION_TRUE, // CHA
PS5000A_CONDITION_DONT_CARE, // CHB
PS5000A_CONDITION_DONT_CARE, // CHC
PS5000A_CONDITION_DONT_CARE, // CHD
PS5000A_CONDITION_DONT_CARE, // external
PS5000A_CONDITION_DONT_CARE, // aux
PS5000A_CONDITION_TRUE, // pulseWidthQualifier
};
// Structure for trigger configuration
PS5000A_TRIGGER_CHANNEL_PROPERTIES CHA_Properties = { 7000, 32, 0,
0,
PS5000A_CHANNEL_A,
PS5000A_LEVEL
};
if(statusOpenUnit != PICO_OK)
{
// Open device
statusOpenUnit = ps5000aOpenUnit(&picohandle, NULL, PS5000A_DR_15BIT);
// Error?
if(statusOpenUnit != PICO_OK)
{
sprintf(Error, "Unable to open PicoScope. Error code : 0x%08lx\n", statusOpenUnit);
MessagePopup("Error", Error);
}
}
// Configure Channels
PS5000A_CHANNEL_A_OFFSET = 0.0;
status = ps5000aSetChannel(picohandle,
PS5000A_CHANNEL_A,
TRUE,
PS5000A_DC,
PS5000A_10V,
PS5000A_CHANNEL_A_OFFSET);
if(status != PICO_OK)
{
sprintf(Error, "Unable to initialize PicoScope channel. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
// Get timebase, just for information
// Sampletime = 5s
// e.g. Samplerate = 1000S/s
// -> sample interval: 1ms
// -> Memory: 5000S/Channel
// timebase @ 15bit resolution: (1ms * 125000000) + 2 = 125002
timebase = 125002;
noSamples = 5000;
segmentIndex = 0;
while (ps5000aGetTimebase2(picohandle,
timebase,
noSamples,
NULL, //&timeIntervalNanoseconds,
NULL, //&maxSamples,
segmentIndex))
{
timebase++;
}
// Set trigger conditions
status = ps5000aSetTriggerChannelConditions(picohandle,
&CHA_Conditions,
1); // 1 condition structure
if(status != PICO_OK)
{
sprintf(Error, "Unable to set PicoScope trigger conditions. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
// Configure trigger
status = ps5000aSetTriggerChannelDirections(picohandle,
PS5000A_RISING, // CHA
PS5000A_NONE, // CHB
PS5000A_NONE, // CHC
PS5000A_NONE, // CHD
PS5000A_NONE, // ext
PS5000A_NONE); // aux
if(status != PICO_OK)
{
sprintf(Error, "Unable to initialize PicoScope trigger direction. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
autoTriggerMilliseconds = 5000;
nChannelProperties = 1; // the size of the channelProperties array. If zero, triggering is switched off. -> 1 channel triggered
status = ps5000aSetTriggerChannelProperties(picohandle,
&CHA_Properties,
nChannelProperties,
NULL,
autoTriggerMilliseconds);
if(status != PICO_OK)
{
sprintf(Error, "Unable to initialize PicoScope trigger channel properties. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
}
/****************************************************************************
*
* PicoScope_5242A_arm
* this function arms 5242A to capture data
*
****************************************************************************/
void PicoScope_5242A_arm(void)
{
char Error[100];
short sReady;
int i=0;
int16_t retry;
PICO_STATUS status=1;
long timeInterval = 1;
unsigned long maxSamples;
// Sampletime = 5s
// e.g. Samplerate = 1000S/s
// -> sample interval: 1ms
// -> Memory: 5000S/Channel
// timebase @ 15bit resolution: (1ms * 125000000) + 2 = 125002
int noOfPreTriggerSamples = 500, noOfPostTriggerSamples = 5000, timeIndisposedMs;
unsigned int timebase = 125002, segmentIndex = 0;
status = ps5000aRunBlock(picohandle,
noOfPreTriggerSamples,
noOfPostTriggerSamples,
timebase,
&timeIndisposedMs,
segmentIndex,
NULL,
NULL);
if(status != PICO_OK)
{
sprintf(Error, "Unable to arm PicoScope. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
}
/****************************************************************************
*
* PicoScope_5242A_get_data
* Download data recorded by PicoScope
*
****************************************************************************/
void PicoScope_5242A_get_data(short *ChannelA, short *ChannelB)
{
char Error[100];
int i=0, bufferLth;
unsigned int segmentIndex, startIndex, noOfSamples;
short sReady, overflow;
PICO_STATUS status=1;
// Wait for 13 seconds for PicoScope to get ready
do
{
status = ps5000aIsReady(picohandle, &sReady);
Sleep(100);
i++;
if(i>=130)
{
MessagePopup("Error", "Trigger Fehler!");
break;
}
} while(!sReady);
// Configure PicoScop data buffer for Channel A
bufferLth = 5000;
segmentIndex = 0;
status = ps5000aSetDataBuffer(picohandle,
PS5000A_CHANNEL_A,
ChannelA,
bufferLth,
segmentIndex,
PS5000A_RATIO_MODE_NONE);
if(status != PICO_OK)
{
sprintf(Error, "Unable to set PicoScope data buffer. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
// download recorded data for Channel A
startIndex = 0;
noOfSamples = 5000;
status = ps5000aGetValues(picohandle,
startIndex,
&noOfSamples,
PS5000A_RATIO_MODE_NONE,
PS5000A_RATIO_MODE_NONE,
segmentIndex,
&overflow);
if(status != PICO_OK)
{
sprintf(Error, "Unable to download recorded data from PicoScope. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
}
void PicoScope_5242A_close(void)
{
PICO_STATUS status=1;
char Error[100];
// close device
status = ps5000aStop(picohandle);
if(status != PICO_OK)
{
sprintf(Error, "Unable to close PicoScope. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
ps5000aCloseUnit(picohandle);
}
int main (int argc, char *argv[])
{
short sVoltageData[5000]={0};
short sCurrentData[5000]={0};
int i=0;
if (InitCVIRTE (0, argv, 0) == 0) return -1; /* out of memory */
// Open and configure PicoScope
PicoScope_5242A_init_config();
// Arm PicoScope to capture data
PicoScope_5242A_arm();
// Get data recorded by PicoScope
PicoScope_5242A_get_data(sVoltageData, sCurrentData);
PicoScope_5242A_close();
return 0;
}
Code: Select all
struct tPS5000ATriggerConditions CHA_Conditions = { PS5000A_CONDITION_TRUE, // CHA
PS5000A_CONDITION_DONT_CARE, // CHB
PS5000A_CONDITION_DONT_CARE, // CHC
PS5000A_CONDITION_DONT_CARE, // CHD
PS5000A_CONDITION_DONT_CARE, // external
PS5000A_CONDITION_DONT_CARE, // aux
PS5000A_CONDITION_TRUE, // pulseWidthQualifier
};
Code: Select all
struct tPS5000ATriggerConditions CHA_Conditions = { PS5000A_CONDITION_TRUE, // CHA
PS5000A_CONDITION_DONT_CARE, // CHB
PS5000A_CONDITION_DONT_CARE, // CHC
PS5000A_CONDITION_DONT_CARE, // CHD
PS5000A_CONDITION_DONT_CARE, // external
PS5000A_CONDITION_DONT_CARE, // aux
PS5000A_CONDITION_TRUE, // pulseWidthQualifier
};
Code: Select all
struct tPS5000ATriggerConditions CHA_Conditions = { PS5000A_CONDITION_TRUE, // CHA
PS5000A_CONDITION_DONT_CARE, // CHB
PS5000A_CONDITION_DONT_CARE, // CHC
PS5000A_CONDITION_DONT_CARE, // CHD
PS5000A_CONDITION_DONT_CARE, // external
PS5000A_CONDITION_DONT_CARE, // aux
PS5000A_CONDITION_DONT_CARE, // pulseWidthQualifier
};
Code: Select all
PicoScope_5242A_init_config();
// Arm PicoScope to capture data
PicoScope_5242A_arm();
Sleep(400); // <----- wait is important
// I send my signal
// Get data recorded by PicoScope
PicoScope_5242A_get_data(sVoltageData, sCurrentData);
PicoScope_5242A_close();