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)
{
// Structure for trigger conditions
struct tPS5000ATriggerConditions CHB_Conditions = { PS5000A_CONDITION_DONT_CARE, // CHA
PS5000A_CONDITION_TRUE, // 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
};
// Structure for trigger configuration
struct tPS5000ATriggerChannelProperties CHB_Properties = { 32767, // set higher trigger threshold to maximum (is not used)
0, // set hysteresis minimum
13762, // set lower trigger threshold to 0.21V. 13762 = MAX_ADC_COUNTS / MAX_VOLTAGE * THRESHOLD = 32767 / 0.5V * 0.21V
655, // set hysteresis to 10mV. 655 = MAX_ADC_COUNTS / MAX_VOLTAGE * HYSTERESIS = 32767 / 0.5V * 0.01
PS5000A_CHANNEL_B,
PS5000A_LEVEL
};
char Error[100];
static UNIT unit;
static 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;
// timebase
uint32_t timebase;
int32_t noSamples;
float timeIntervalNanoseconds;
int32_t maxSamples;
uint32_t segmentIndex;
// Open device
status = ps5000aOpenUnit(&picohandle, NULL, PS5000A_DR_15BIT);
// Error?
if(status != PICO_OK)
{
sprintf(Error, "Unable to open PicoScope. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
// Configure Channels
PS5000A_CHANNEL_A_OFFSET = 0.0;
status = ps5000aSetChannel(picohandle,
PS5000A_CHANNEL_A,
TRUE,
PS5000A_DC,
PS5000A_2V,
PS5000A_CHANNEL_A_OFFSET);
if(status != PICO_OK)
{
sprintf(Error, "Unable to initialize PicoScope channel. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
PS5000A_CHANNEL_B_OFFSET = 0.0;
status = ps5000aSetChannel(picohandle,
PS5000A_CHANNEL_B,
TRUE,
PS5000A_DC,
PS5000A_500MV, // normally 5V but 10/1 current probe -> 0.5V
PS5000A_CHANNEL_B_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;
status = ps5000aGetTimebase2(picohandle,
timebase,
noSamples,
&timeIntervalNanoseconds,
&maxSamples,
segmentIndex);
if(status != PICO_OK)
{
sprintf(Error, "Unable to get PicoScope timebase. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
// Set trigger conditions
status = ps5000aSetTriggerChannelConditions(picohandle,
&CHB_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_NONE, // CHA
PS5000A_FALLING_LOWER, // 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 = 10000;
nChannelProperties = 1; // the size of the channelProperties array. If zero, triggering is switched off. -> 1 channel triggered
status = ps5000aSetTriggerChannelProperties(picohandle,
&CHB_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);
}
// Set trigger delay
status = ps5000aSetTriggerDelay(picohandle,
0); // the time between the trigger occurring and the first sample in samples
if(status != PICO_OK)
{
sprintf(Error, "Unable to set PicoScope trigger delay. 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];
static PICO_STATUS status=1;
long timeInterval = 1;
long sampleCount= 6000;
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 = 4500, 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;
static PICO_STATUS status=1;
// finish data capturing
status = ps5000aStop(picohandle);
if(status != PICO_OK)
{
sprintf(Error, "Unable to close PicoScope. Error code : 0x%08lx\n", status);
MessagePopup("Error", Error);
}
// Wait for 13 seconds for PicoScope to get ready
do
{
status = ps5000aIsReady(picohandle, &sReady);
Sleep(100);
i++;
if(i>=130) 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);
}
status = ps5000aSetDataBuffer(picohandle,
PS5000A_CHANNEL_B,
ChannelB,
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)
{
static 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);
}
}
we're using the dll from the delivered CD R10.5.2.1.Which version of the ps5000a.dll are you using?
Exactly, we're calling "PicoScope_5242A_init_config" in the beginning and "PicoScope_5242A_close" in the end. The functions "PicoScope_5242A_arm" and "PicoScope_5242A_get_data" run in a loop.When you refer to the 27th run presumably you are running a loop to collect the data and not opening and closing the unit each time?