Jump to content
  • 0

Assistance Needed with Oscilloscope Integration Using Waveform SDK in Qt


Fausto

Question

Posted for @fahiz.

I am currently developing a custom GUI with Qt, which includes an oscilloscope. I'm utilizing the ADP 3450. My task involves plotting waves with a frequency of 1 million Hz and an amplitude of 1 Vpp. Additionally, it operates in burst mode with a trigger interval of 1 second. Currently, I'm employing FDwfAnalogInAcquisitionMode as scanmodeshift.

I'm encountering below issues:

The time range is very limited (currently at 0.2 seconds), which prevents me from observing more than one wave bunch. Ideally, I would like to visualize multiple pulses over a couple of seconds.

Another issue lies in the plot amplitude, which doesn't reach 0.5 V and -0.5 V. but, increasing the frequency allows it to touch the peaks.

Could you advise on how to address these issues and suggest the correct method for plotting in such cases?
I am adding one screenshot also with this.

 

image.png

 

I am using the SDK (C++) provided by Waveform, and the Qt version is 5.15.3. I am generating and plotting with the same device (ADP 3450). I also attempted generating from another source. I am providing the header file and source file of the basic Qt code (I am using QCustomPlot for plotting).

Header (mainwindow.h):

 

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "qcustomplot.h"
#include <digilent/waveforms/dwf.h>
#include <unistd.h>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void setupRealtimeDataDemo(QCustomPlot *customPlot);

private slots:
    void realtimeDataSlot();

private:
    Ui::MainWindow *ui;
    QTimer dataTimer;
    HDWF hdwf;
    STS sts;
    double hzAcq = 1500000;
    const int nSamples = 2000000;
    QVector<double> rgdSamples;
    int cValid;
    char szError[512];
    double sinAmplitude;
    double sinFrequency;
    double wf_run_time;
    double wf_wait;
};

#define Wait(ts) usleep((int)(1000000*ts))

#endif // MAINWINDOW_H

 

Source code (mainwindow.cpp):

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <fstream>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
    ui->setupUi(this);
    setGeometry(400, 250, 542, 390);
    setupRealtimeDataDemo(ui->customPlot);
    connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
    dataTimer.start(100); // Adjust the interval based on your preference
}

void MainWindow::setupRealtimeDataDemo(QCustomPlot *customPlot) {
    rgdSamples.resize(nSamples);

    if (!FDwfDeviceOpen(-1, &hdwf)) {
        FDwfGetLastErrorMsg(szError);
        return;
    }

    FDwfDeviceAutoConfigureSet(hdwf, 0);

    // Setup sine wave generation parameters
    sinAmplitude = 1.0;
    sinFrequency = 1000000.0;
    wf_run_time = 0.2;
    wf_wait = 0.8;

    // Configure Digilent Analog Out for sine wave generation
    FDwfAnalogOutNodeEnableSet(hdwf, 0, 0, 1);
    FDwfAnalogOutNodeFunctionSet(hdwf, 0, 0, 1); // Sine function
    FDwfAnalogOutNodeFrequencySet(hdwf, 0, 0, sinFrequency);
    FDwfAnalogOutNodeAmplitudeSet(hdwf, 0, 0, sinAmplitude);
    FDwfAnalogOutRunSet(hdwf, 0, wf_run_time);
    FDwfAnalogOutWaitSet(hdwf, 0, wf_wait);
    FDwfAnalogOutRepeatSet(hdwf, 0, 0);
    FDwfAnalogOutConfigure(hdwf, 0, 1);

    // Configure Digilent Analog In for data acquisition
    FDwfAnalogInChannelEnableSet(hdwf, 0, 1);
    FDwfAnalogInChannelRangeSet(hdwf, 0, 5);
    FDwfAnalogInAcquisitionModeSet(hdwf, 1); // acqmodeScanShift
    FDwfAnalogInFrequencySet(hdwf, hzAcq);
    FDwfAnalogInBufferSizeSet(hdwf, nSamples);
    FDwfAnalogInConfigure(hdwf, 1, 0);

    Wait(2);

    FDwfAnalogInConfigure(hdwf, 0, 1);

    // Setup the QCustomPlot for visualization
    customPlot->addGraph();
    customPlot->graph(0)->setPen(QPen(QColor(40, 110, 255)));
    customPlot->axisRect()->setupFullAxesBox();
    customPlot->xAxis->setRange(0, nSamples);
    customPlot->yAxis->setRange(-2.5, 2.5);
    connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
}

void MainWindow::realtimeDataSlot() {
    // Fetch data from the Digilent WaveForms device
    FDwfAnalogInStatus(hdwf, 1, &sts);
    FDwfAnalogInStatusSamplesValid(hdwf, &cValid);
    FDwfAnalogInStatusData(hdwf, 0, rgdSamples.data(), cValid); // Get channel 1 data

    // Convert QVector<double> to QCPGraphDataContainer
    QCPGraphDataContainer dataContainer;
    for (int i = 0; i < rgdSamples.size(); ++i) {
        dataContainer.add(QCPGraphData(i, rgdSamples[i]));
    }

    // Update the plot
    QSharedPointer<QCPGraphDataContainer> dataContainerSharedPointer = QSharedPointer<QCPGraphDataContainer>::create(dataContainer);
    ui->customPlot->graph(0)->setData(dataContainerSharedPointer);
    ui->customPlot->replot();
}

MainWindow::~MainWindow() {
    delete ui;
}

 

I hope this helps! Let me know if you need further details.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi @fahiz @Fausto

Why are you limited to 0.2 sec ? with 1.5M samples and 1.5MHz capture rate the span in 1sec
If you are interested in peaks you can use min/max sampling mode (FDwfAnalogInChannelFilterSet), less samples and lower frequency.

The sampling rate should be at least 4 times than signal frequency, otherwise you see aliasing.
https://www.ni.com/docs/en-US/bundle/labwindows-cvi/page/advancedanalysisconcepts/aliasing.html

image.png

image.png

Link to comment
Share on other sites

  • 0

Hi @attila
Thankyou for your reply.

Actually my goal is to make a GUI it have to continuously plot 1.1 Mhz sine burst mode signal.  So I made a qt gui, and I tried with acqmodescanshift.

    FDwfAnalogInAcquisitionModeSet(hdwf, 1); // acqmodeScanShift
    

In this if I want to increase the time limit, then I have to increase buffer size, so the system is crashing that time.

Can you assist me in finding the best method for continuously plotting a signal, and advise on the logic typically used for continuous plotting?

Thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...