Question

I am a starter programmer - QT is new to me.

The overall task: Need to generate a square wave signal using NI BNC2110 DAQ and controlled by QT creator. I am accessing the daq using DAQmx driver. Thus, I can set the digital output on the daq buy writing to it.

The approach: In order to generate a square wave, I would just toggle the digital output on the daq by periodically writing 0 or 1 to the output. So, I need some kind of trigger that will do it periodically. There is only one thing that comes to my mind - using some kind of interrupts (i remember using such interrupts when programming microcontroller - the clock, when reaching some value, would trigger the interrupt).

If anyone could give me a hint on how to solve this problem. (I wish to run triggering at 1-10Mhz, so at least microsecond resolution is desirable)

Thank you very much in advance

Était-ce utile?

La solution

Here is some related information on the resolution of QTimer.

QTimer's resolution is about 15 ms or so on Windows.

I believe it uses something similar to GetTickCount().

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724408(v=vs.85).aspx

The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds.

http://qt-project.org/doc/qt-4.8/qtimer.html#accuracy-and-timer-resolution

Timers will never time out earlier than the specified timeout value and they are not guaranteed to time out at the exact value specified. In many situations, they may time out late by a period of time that depends on the accuracy of the system timers.

The accuracy of timers depends on the underlying operating system and hardware. Most platforms support a resolution of 1 millisecond, though the accuracy of the timer will not equal this resolution in many real-world situations.

If Qt is unable to deliver the requested number of timer clicks, it will silently discard some.

Autres conseils

There are a few ways to do this (see the timer documentation). The "Qt way" would be to use a QTimer, but it may be slightly faster to user the timer event. (Though, as I said in the comment, you will need a different approach to get the resolution you need.)

Let's say you have DacControl object that toggles the DAC. It will need to be a QObject so it can connect to the timeout() signal:

class DacControl : public QObject
{
    Q_OBJECT

public:
    DacControl() {
        timer.setInterval(0);
        connect(&timer, SIGNAL(timeout()), this, SLOT(toggleDac()));
    }

    // The timer is not running (and the DAC is not toggled) until this call
    void start() {
        timer.start();
    }

private slots:
    void toggleDac();

private:
    QTimer timer;
};

You'll note that I set the timer interval to 0 ms. This will cause the timer to emit its timeout() signal every time the Qt event loop is run (so the speed is dependent on the platform you are running on, and is likely to vary a lot depending on what else the program is doing). In my experience, I've achieved better performance with an interval of 0 than with a very small interval (e.g., 1 to about 20 or so).

Hopefully this gets you started to prove the setup works, even if this can't achieve the performance you need in the end.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top