I wrote a small function in C++ Builder to make use of AWG with 2205:
// Freq: frequency in Hertz (0-100000), Peak: amplitude/DC level in mV (0-2000)
bool PicoScope2205Write(float Freq, short Peak)
{
long offsetVoltage;
unsigned long pkToPk;
PS2000_WAVE_TYPE waveType;
if (Freq > 0)
{
offsetVoltage = 0; // symetrical output
pkToPk = (unsigned long)Peak*2000; // Peak-Peak in uV
waveType = PS2000_SQUARE; // square waveform
}
else
{
offsetVoltage = (long)Peak*1000; // positive DC level in uV
pkToPk = 0; // any value
waveType = PS2000_DC_VOLTAGE; // DC level output
}
return (ps2000_set_sig_gen_built_in(handle, // opened scope
offsetVoltage,
pkToPk,
waveType,
Freq, // start frequency
Freq, // no sweep: stop freq same as start
0, // frequency step
0, // time interval between 2 steps
PS2000_UP, // sweep type
0) == NULL);// number of sweeps
}
The aim is to output a fixed DC level if Freq is 0 and generate square wave otherwise. The problem is that the function works well with Freq=0 but do nothing if Freq>0 (SIGNAL OUT stays at 0V). It only works if I change the ps2000_set_sig_gen_built_in calling as following (please note the bold text):
return (ps2000_set_sig_gen_built_in(handle, // opened scope
offsetVoltage,
pkToPk,
waveType, Freq*1.0, // start frequency Freq*1.0, // no sweep: stop freq same as start
0, // frequency step
0, // time interval between 2 steps
PS2000_UP, // sweep type
0) == NULL);// number of sweeps
But then the DC level output option (Freq=0) doesn't work anymore. I think it's a type conversion matter but don't understand why and where.
Can anybody help me out of this situation. I'm not very skillful in C++ programming. Thanks in advance.
Thanks for your suggestion. I've read all examples provided with the package. I've also tried to pass direct values to ps2000_set_sig_gen_built_in or separated my own function into 2 sub-function (1 for generating square wave and 1 for output DC level), and they just work fine as I expected.
Now I just wonder why I can not combine them in a common function (to simplify my program) like the one I've implemented.
In addition, Freq*1.0 could be replaced with anything meaningless like Freq*1 or Freq+0 to have the same effect.