How to set the frequency of a square waveform on a non-clocked digital output channel

Hello, I want to code a squareWave on a Non-Clocked digital output channel, but I need it to have a specific frequency, meaning I want the "1" state for 0.5 seconds and "0" on the other 0.5 seconds. I know I can increase the output vector size, but how do I know to which time does this correspond? (session rate cannot be used)
Is there a way to set such rate?
My actual code is as follows:
d=daq.getDevices();
s = daq.createSession('ni');
ao=addDigitalChannel(s,'Dev1','port0/line0','OutputOnly');
ai=addDigitalChannel(s,'Dev1','port0/line1','InputOnly');
oneCycle = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1];
squareWave = repmat(oneCycle, [1, 10]);
for i=1:length(squareWave)
outputSingleScan(s,squareWave(i));
data(i)=inputSingleScan(s);
end

回答 (1 件)

Vinod
Vinod 2016 年 1 月 16 日

0 投票

What is the samplerate of the session, s?

2 件のコメント

Raquel Flores
Raquel Flores 2016 年 1 月 17 日
I cannot set a samplerate for this session because in my USB-6003 DAQ the digital channels are non clocked, so automatically only singleScans are available. I cannot queue data.
Vinod
Vinod 2016 年 1 月 19 日
One solution in this situation is to set up a timer object that toggles the state of pin. The frequency of the timer object callback being executed will control the frequency of your output square wave. Note that given that timing is being accomplished in software, having other applications that may load your CPU (like an anti-virus, or power saving mode on a laptop, for example) may cause the timing to be messed up.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangePeriodic Waveform Generation についてさらに検索

質問済み:

2016 年 1 月 13 日

コメント済み:

2016 年 1 月 19 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by