Test and Measurement Forum

Coupling issue when using AWG from 5244B

Post your C and C++ discussions here

Coupling issue when using AWG from 5244B

Postby jaray » Thu Jan 28, 2016 3:25 pm

The issue I am having is only related to the software I wrote, and I can not replicate it using PicoScope 6.

The issue is that when I record the signal from the AWG using my software (by running the output from the AWG straight into channel A), the signal is correct ONLY when the input is DC coupled. If the input is AC coupled then it is wrong. I verified this behavior using a TDS 210 bench scope and the same thing happens.

If I use the PicoScope 6 software to read in the CSV file of my signal and output it then everything works great regardless of coupling. It works great using the 5244B as a scope and my TDS 210.

Here is the code used to initialize the AWG:
Code: Select all
void PicoSignal::armSignalGenerator()
{
    PICO_STATUS status;
    pkpk_m = 1200000;   //1.2V pkpk
    long offset = 0;
    deltaphase_m = calculateDeltaFromFrequency(ddsfrequency_m);
    short triggerVoltage = mv_to_adc(100, PS5000A_5V);

    status = ps5000aSetSigGenArbitrary(unitOpened_m->handle,                    //unit handle
                        offset,                                                 //offset voltage
                        pkpk_m,                                                 //PkToPk in microvolts. Max = 4V  +2v to -2V
                        deltaphase_m,                                           //start delta
                        deltaphase_m,                                           //stop delta
                        0,                                                      //deltaPhaseIncrement
                        0,                                                      //dwellCount
                        arbitrarywaveform_m,                                    //waveForm
                        waveformsize_m,                                         //waveFormSize
                        (PS5000A_SWEEP_TYPE)0,                                  //sweepType
                        (PS5000A_EXTRA_OPERATIONS)0,                            //operation
                        PS5000A_SINGLE,                                         //indexMode
                        1,                                                     //shots
                        0,                                                      //sweeps
                        (PS5000A_SIGGEN_TRIG_TYPE) PS5000A_SIGGEN_RISING,       //triggerType
                        (PS5000A_SIGGEN_TRIG_SOURCE) PS5000A_SIGGEN_EXT_IN,  //triggerSource
                        triggerVoltage);
}


Code: Select all
unsigned long PicoSignal::calculateDeltaFromFrequency(double frequency)
{
    unsigned long returnValue = (((frequency * waveformsize_m) / unitOpened_m->AWGFileSize) * AWG_PHASE_ACCUMULATOR * (1/AWG_DAC_FREQUENCY));
    return returnValue;
}


I'm not doing anything that seems out of the ordinary. The function I am inputting into the AWG is being generated on the fly here
Code: Select all
void PicoSignal::generatingFunction(double a, double k, double b, double nu, double q, double m)
{
    double logisticresult = 0;
    QVector <QPointF> samples;
    QString directory = QDir::currentPath().append("/SavedWaveforms/");
    if (!QDir(directory).exists())
        QDir().mkdir(directory);
    QFile file(directory.append("lastusedlogisticfunction.csv"));
    if (file.open(QFile::WriteOnly|QFile::Truncate))
    {
        QTextStream stream(&file);
        for (double t = 0; t<unitOpened_m->AWGFileSize; t++){
            logisticresult = (a + ((k-a) / pow((1 + (q*exp(-b*(t - m)))), (1 / nu))));
            stream /*<< t << "," */<< logisticresult << "\n";
            samples.append(QPointF((t/unitOpened_m->AWGFileSize)*(1000/ddsfrequency_m), logisticresult*normalizingVoltageValue));
        }
        file.close();
        emit functionGenerated(samples);
    }
}


which is code to generate this function: https://en.wikipedia.org/wiki/Generalis ... c_function

Like I said, everything works exactly like it is supposed to as long as the signal is DC coupled. I thought maybe it had to do with how the DDS works to generate the function, but since it works fine if I use PicoScope 6 I can only imagine it has something to do with how I arm the AWG.

EDIT: I attached some images to show what is going on

What the result should look like
Whatitshouldlooklike.PNG


DC Coupling on PicoScope 6
picodc.PNG


AC Coupling on PicoScope 6
picoac.PNG


DC Coupling on my software
dccoupled.PNG


AC Coupling on my software
accoupled.PNG
jaray
Newbie
 
Posts: 0
Joined: Wed Jan 14, 2015 8:47 pm

Re: Coupling issue when using AWG from 5244B

Postby hexamer » Fri Jan 29, 2016 9:55 pm

Any chance this is the issue your dealing with: topic19881.html
hexamer
Advanced User
Advanced User
 
Posts: 62
Joined: Tue Aug 12, 2014 10:09 pm

Re: Coupling issue when using AWG from 5244B

Postby jaray » Mon Feb 01, 2016 3:53 pm

I don't think so. I posted that same question last April, topic16681.html

My work around is pretty simple, when I arm my system (apply the configurations, etc), I go ahead and run a dummy capture.

What I am running into now seems to be a problem with the output of the AWG. Everything works fine if I use their software and output, but when I output the signal using my software something is wrong. I've verified the results using a TDS-210 scope.
jaray
Newbie
 
Posts: 0
Joined: Wed Jan 14, 2015 8:47 pm

Re: Coupling issue when using AWG from 5244B

Postby Martyn » Tue Feb 02, 2016 4:00 pm

I suspect that what you are seeing is due to the generator still outputting a signal at the end of the run.

Therefore I would suggest deliberately setting the generator output to zero at the end of the run, effectively turning it off, before starting the next capture.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Coupling issue when using AWG from 5244B

Postby jaray » Wed Feb 03, 2016 9:02 pm

I will try it out. At first I thought that couldn't be the case since even the first capture has issues, however I am performing a dummy capture to fix the issues posted above.
jaray
Newbie
 
Posts: 0
Joined: Wed Jan 14, 2015 8:47 pm

Re: Coupling issue when using AWG from 5244B

Postby jaray » Wed Feb 03, 2016 9:23 pm

No luck, here is what I have. Turns out I was already adjusting the ddsoutput in between captures. Forgot about that.

Code: Select all
for (int i = 0; i<1024; i++)
        baselineArbitrarywaveform_m.append((unsigned int)0);


Code: Select all
void PicoSignal::loadZeroFunction()
{
    waveformsize_m = (long)baselineArbitrarywaveform_m.size();
    arbitrarywaveform_m = &baselineArbitrarywaveform_m[0];
    PICO_STATUS status;
    pkpk_m = 0;
    long offset = 0;
    unsigned long newddsf = 0;
    deltaphase_m = calculateDeltaFromFrequency(newddsf);

    status = ps5000aSetSigGenArbitrary(unitOpened_m->handle,                    //unit handle
                        offset,                                                 //offset voltage
                        pkpk_m,                                                 //PkToPk in microvolts. Max = 4V  +2v to -2V
                        deltaphase_m,                                           //start delta
                        deltaphase_m,                                           //stop delta
                        0,                                                      //deltaPhaseIncrement
                        0,                                                      //dwellCount
                        arbitrarywaveform_m,                                    //waveForm
                        waveformsize_m,                                         //waveFormSize
                        (PS5000A_SWEEP_TYPE)0,                                  //sweepType
                        (PS5000A_EXTRA_OPERATIONS)0,                            //operation
                        PS5000A_SINGLE,                                         //indexMode
                        1,                                                     //shots
                        0,                                                      //sweeps
                        (PS5000A_SIGGEN_TRIG_TYPE) 0,                           //triggerType
                        (PS5000A_SIGGEN_TRIG_SOURCE) PS5000A_SIGGEN_SOFT_TRIG,  //triggerSource
                        0);
    unitStatus_m = ps5000aSigGenSoftwareControl(unitOpened_m->handle,0);
}
jaray
Newbie
 
Posts: 0
Joined: Wed Jan 14, 2015 8:47 pm

Re: Coupling issue when using AWG from 5244B

Postby AndrewA » Thu Feb 04, 2016 12:57 pm

Hi,

Could you record the first 15 cycles of the AWG output and post them. (AC coupled)

Does this only happen on the first cycle from the AWG?

What if you try setting the the AWG output a dummy number of cycles, then set the AWG to O/P 0v. Before you output your desired signal.
Regards Andrew
Technical Specialist
AndrewA
Zen Master
Zen Master
 
Posts: 178
Joined: Tue Oct 21, 2014 3:07 pm

Re: Coupling issue when using AWG from 5244B

Postby jaray » Thu Feb 04, 2016 3:06 pm

A few notes on how I did this. In order to output 15 waveforms, I changed my shots from 1 to 15. I also had to increase the frequency of the DDS to be larger than my capture. Upon running this, the problem persists. I can see the ADC head toward 0 during the capture but as soon as the next burst happens the problem happens ago.

Here are the first 15 cycles with DC coupling using the 5244B
15cyclesdc.PNG


Here are the first 15 cycles with AC coupling using the 5244B
15cyclesac.PNG


Here are first 15 cycles with DC coupling using a TDS 210
TDS DC.jpg


Here are first 15 cycles with AC coupling using a TDS 210. Note that the results are the same as using the 5244B, the voltage scale is offset in the negative direction by -600mV.
TDS AC.jpg


This seems purely related to the output of the generator. I did notice that the if I set shots to 0 and sweeps to 0 then the output was correct though it started as soon as I initialized the generator without waiting for a trigger.

Here is the entire code for initializing the AWG.

Code: Select all
#include "picosignal.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QDir>
#include <QApplication>


static const unsigned short inputRanges [PS5000A_MAX_RANGES] = {10,20,50,100,200,500,1000,2000,5000,10000,20000};
PicoSignal::PicoSignal(UNIT *&unit, QObject *parent) : unitOpened_m(unit), QObject(parent)
{
    connect(this, SIGNAL(functionGenerated(QVector <QPointF>)), this, SLOT(loadSignal(QVector <QPointF>)));
    for (int i = 0; i<1024; i++)
        baselineArbitrarywaveform_m.append((unsigned int)0);

}

PicoSignal::~PicoSignal()
{

}

void PicoSignal::loadSignal(QVector <QPointF> signalVector)
{
    waveformsize_m = (long)signalVector.size();
    waveformshortvector = convertWaveFormToSamples(signalVector);
    arbitrarywaveform_m = &waveformshortvector[0];
}

void PicoSignal::generateDefaultSignal()
{
    generatingFunction(-1, 1, .0003, 1, 1, 25000);
}
void PicoSignal::setFrequency(double frequency)
{
    ddsfrequency_m = frequency*100;
    emit timeScaledChanged(frequency);
}

void PicoSignal::loadZeroFunction()
{
    waveformsize_m = (long)baselineArbitrarywaveform_m.size();
    arbitrarywaveform_m = &baselineArbitrarywaveform_m[0];
    PICO_STATUS status;
    pkpk_m = 0;
    long offset = 0;
    unsigned long newddsf = 0;
    deltaphase_m = calculateDeltaFromFrequency(newddsf);

    status = ps5000aSetSigGenArbitrary(unitOpened_m->handle,                    //unit handle
                        offset,                                                 //offset voltage
                        pkpk_m,                                                 //PkToPk in microvolts. Max = 4V  +2v to -2V
                        deltaphase_m,                                           //start delta
                        deltaphase_m,                                           //stop delta
                        0,                                                      //deltaPhaseIncrement
                        0,                                                      //dwellCount
                        arbitrarywaveform_m,                                    //waveForm
                        waveformsize_m,                                         //waveFormSize
                        (PS5000A_SWEEP_TYPE)0,                                  //sweepType
                        (PS5000A_EXTRA_OPERATIONS)0,                            //operation
                        PS5000A_SINGLE,                                         //indexMode
                        0,                                                     //shots
                        0,                                                      //sweeps
                        (PS5000A_SIGGEN_TRIG_TYPE) 0,                           //triggerType
                        (PS5000A_SIGGEN_TRIG_SOURCE) PS5000A_SIGGEN_SOFT_TRIG,  //triggerSource
                        0);
    unitStatus_m = ps5000aSigGenSoftwareControl(unitOpened_m->handle,0);
}

void PicoSignal::armSignalGenerator()
{
    PICO_STATUS status;
    pkpk_m = 1200000;   //1.2V pkpk, start signal at -600mV due to offstate of ad8336
    long offset = 0;
    //ddsfrequency_m = 100;
    deltaphase_m = calculateDeltaFromFrequency(ddsfrequency_m);
    short triggerVoltage = mv_to_adc(100, PS5000A_5V);
    //short triggerVoltage = mv_to_adc(20, unitOpened_m->channelSettings[PS5000A_CHANNEL_A].range);

    status = ps5000aSetSigGenArbitrary(unitOpened_m->handle,                    //unit handle
                        offset,                                                 //offset voltage
                        pkpk_m,                                                 //PkToPk in microvolts. Max = 4V  +2v to -2V
                        deltaphase_m,                                           //start delta
                        deltaphase_m,                                           //stop delta
                        0,                                                      //deltaPhaseIncrement
                        0,                                                      //dwellCount
                        arbitrarywaveform_m,                                    //waveForm
                        waveformsize_m,                                         //waveFormSize
                        (PS5000A_SWEEP_TYPE)0,                                  //sweepType
                        (PS5000A_EXTRA_OPERATIONS)0,                            //operation
                        PS5000A_SINGLE,                                         //indexMode
                        15,                                                     //shots
                        0,                                                      //sweeps
                        (PS5000A_SIGGEN_TRIG_TYPE) PS5000A_SIGGEN_RISING,       //triggerType
                        (PS5000A_SIGGEN_TRIG_SOURCE) PS5000A_SIGGEN_EXT_IN,  //triggerSource
                        triggerVoltage);
}

short PicoSignal::mv_to_adc(short mv, short rangeIndex) //maybe shorts?
{
   // return (mv * unitOpened_m->maxADCValue) / (int)inputRanges[rangeIndex];
    return ((int)mv * (int)unitOpened_m->maxADCValue) / (int)inputRanges[rangeIndex];
}
QVector<short> PicoSignal::convertWaveFormToSamples(QVector<QPointF>rawwaveform)
{

    QVector <short> tempvector;

    for (int i = 0; i < rawwaveform.size(); i++)
    {
        tempvector.append((short)round((rawwaveform.at(i).y()/normalizingVoltageValue)*maxSampleConversionValue));
    }
    return tempvector;

}

unsigned long PicoSignal::calculateDeltaFromFrequency(double frequency)
{
    unsigned long returnValue = (((frequency * waveformsize_m) / unitOpened_m->AWGFileSize) * AWG_PHASE_ACCUMULATOR * (1/AWG_DAC_FREQUENCY));
    return returnValue;
}
void PicoSignal::triggerSignalGenerator()
{
   if (systemArmed)
   {
    unitStatus_m = ps5000aSigGenSoftwareControl(unitOpened_m->handle,0);
    systemArmed = false;
   // emit finished();
   }
}
void PicoSignal::generatingFunction(double a, double k, double b, double nu, double q, double m)
{
    double logisticresult = 0;
    QVector <QPointF> samples;
    QString directory = QDir::currentPath().append("/SavedWaveforms/");
    if (!QDir(directory).exists())
        QDir().mkdir(directory);
    QFile file(directory.append("lastusedlogisticfunction.csv"));
    if (file.open(QFile::WriteOnly|QFile::Truncate))
    {
        QTextStream stream(&file);
        for (double t = 0; t<unitOpened_m->AWGFileSize; t++){
            logisticresult = (a + ((k-a) / pow((1 + (q*exp(-b*(t - m)))), (1 / nu))));
            stream /*<< t << "," */<< logisticresult << "\n";
            samples.append(QPointF((t/unitOpened_m->AWGFileSize)*(1000/ddsfrequency_m), logisticresult*normalizingVoltageValue));
        }
        file.close();
        emit functionGenerated(samples);
    }
}


jaray
Newbie
 
Posts: 0
Joined: Wed Jan 14, 2015 8:47 pm

Re: Coupling issue when using AWG from 5244B

Postby jaray » Thu Feb 04, 2016 4:08 pm

I decided to try 1000 cycles and had the same results. These are two subsequent captures.
1000cyclesac.PNG

1000cyclesac2.PNG
jaray
Newbie
 
Posts: 0
Joined: Wed Jan 14, 2015 8:47 pm

Re: Coupling issue when using AWG from 5244B

Postby jaray » Thu Feb 04, 2016 4:45 pm

Through some experimentation with PicoScope 6, this seems to only happen if a function starts negative. Using the built in functions for "ramp up", "manual trigger", "15 cycles", the same problem happens. However if I use say a sine wave everything works great. If set for no trigger everything seems fine, so something about having a non zero starting signal, trigger, and AC coupling does not work.
jaray
Newbie
 
Posts: 0
Joined: Wed Jan 14, 2015 8:47 pm

Re: Coupling issue when using AWG from 5244B

Postby AndrewA » Fri Feb 05, 2016 10:53 am

Hi,
I think the issue is the output of the AWG/signal generator not return to 0 volts when the scope is AC coupled.
See the image below, the built in wave shapes for triangle and square do not return 0 volts, when the AWG is stopped.
If you use the sinewave it does return to 0 volts, and you do not have the scopes DC blocking capacitor slowly decaying back to zero.
AWG and AC coupling.png
AWG square wave and AC coupling

I would suggest programming the AWG waveform shape to always return to 0 volts, stop this issue happening.
I have just hand drawn a Arbitrary waveform. Note the last value must be zero-
AWG and AC coupling test.png
test AWG wave and AC coupling
Regards Andrew
Technical Specialist
AndrewA
Zen Master
Zen Master
 
Posts: 178
Joined: Tue Oct 21, 2014 3:07 pm

Re: Coupling issue when using AWG from 5244B

Postby Martyn » Fri Feb 05, 2016 11:18 am

When you did this
jaray wrote:No luck, here is what I have. Turns out I was already adjusting the ddsoutput in between captures. Forgot about that.

Code: Select all
for (int i = 0; i<1024; i++)
        baselineArbitrarywaveform_m.append((unsigned int)0);


Code: Select all
void PicoSignal::loadZeroFunction()
{
    waveformsize_m = (long)baselineArbitrarywaveform_m.size();
    arbitrarywaveform_m = &baselineArbitrarywaveform_m[0];
    PICO_STATUS status;
    pkpk_m = 0;
    long offset = 0;
    unsigned long newddsf = 0;
    deltaphase_m = calculateDeltaFromFrequency(newddsf);

    status = ps5000aSetSigGenArbitrary(unitOpened_m->handle,                    //unit handle
                        offset,                                                 //offset voltage
                        pkpk_m,                                                 //PkToPk in microvolts. Max = 4V  +2v to -2V
                        deltaphase_m,                                           //start delta
                        deltaphase_m,                                           //stop delta
                        0,                                                      //deltaPhaseIncrement
                        0,                                                      //dwellCount
                        arbitrarywaveform_m,                                    //waveForm
                        waveformsize_m,                                         //waveFormSize
                        (PS5000A_SWEEP_TYPE)0,                                  //sweepType
                        (PS5000A_EXTRA_OPERATIONS)0,                            //operation
                        PS5000A_SINGLE,                                         //indexMode
                        1,                                                     //shots
                        0,                                                      //sweeps
                        (PS5000A_SIGGEN_TRIG_TYPE) 0,                           //triggerType
                        (PS5000A_SIGGEN_TRIG_SOURCE) PS5000A_SIGGEN_SOFT_TRIG,  //triggerSource
                        0);
    unitStatus_m = ps5000aSigGenSoftwareControl(unitOpened_m->handle,0);
}

did you use the software trigger to actually force an output ?

It would be worth checking the output on another scope to be sure.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Coupling issue when using AWG from 5244B

Postby jaray » Mon Feb 08, 2016 3:26 pm

So I adjusted my code so that the last sample is always 0 and the waveform that is created works great in picoscope 6, but I am still having issues in my software. I think the problem stems from once I arm the AWG it sets to a DC level that is the first sample of the waveform. This makes sense for causing the odd behavior since the AC coupling is removing this DC bias.

So what is PicoScope 6 doing to account for this? I would think it would also be armed at the bias of the first sample, but it looks like it always starts at 0.
jaray
Newbie
 
Posts: 0
Joined: Wed Jan 14, 2015 8:47 pm

Re: Coupling issue when using AWG from 5244B

Postby Martyn » Tue Feb 09, 2016 9:09 am

I have managed to replicate the issue with PicoScope 6, it requires the use of the signal generator trigger, set to manual, and outputting one or more cycles of a waveform.

First time around you set the waveform to a sine, this will ensure that the signal generator is outputting 0V at the start and end of the run. Now change the setting to square, but leave a little time before triggering to allow the coupling capacitor to charge, then trigger the generator. This gives the same effect of a square wave, for a fixed number of cycles, offset positively which then decays to zero.

When using the signal generator trigger, it is starting to output the first sample in the buffer until the generator is triggered. If you set both the first and last values in your waveform buffer to zero, the output signal should be correct.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots


Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests