Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem of continuous square waveform generation

I'm developing my application in Visual C++. The NI-DAQ version is 6.9.3, the card is AT-MIO-16E, OS is windows 98.
I was running the example code: WFMsingleBufRegenerate.c, it worked well. Then I changed the data written to the buffer as follows:

int i;
iStatus = NIDAQMakeBuffer(pdBuffer, ulCount, WFM_DATA_F64);

for (i = 0; i <= 2499; i++)
{
pdBuffer[i] = 2.5;
pdBuffer[i+2500] = 0.0;
}

It was supposed to be a square wave, but I only got two pulse per period.

How to generate square wave and triangle wave by using C++?

Please help me, thanks in advance.

Yinsheng.
0 Kudos
Message 1 of 3
(2,841 Views)
Yinsheng,

The help for the NI-DAQ Example Utility Function NIDAQMakeBuffer() states the following:

"When you select the WFM_DATA_F64 type, the buffer will contain a 10-period sinewave, ranging between the values 0.00 and 4.99. This is useful for analog output waveform generation operations, where the data must be specified as "double-precision" (scaled)."

The code you have added to fill pdBuffer with a square wave only contains one period of a square wave, as opposed to 10. The help for NIDAQMakeBuffer() also states the following:

"When you select the WFM_DATA_I16 type, the buffer will contain a 10-period squarewave, alternating between the values 0 and 2047. This is useful for analog output waveform generation operations, where the each data eleme
nt must be specified as a short integer (binary)."

If you do not want to create your own buffer containing a square wave, you may want to consider the above option. The help for the NI-DAQ Example Utility Functions is available in the following location:

Start >> Programs >> National Instruments >> NI-DAQ >> NI-DAQ Examples Help >> Index >> Utility Functions

Good luck with your application.

Spencer S.
0 Kudos
Message 2 of 3
(2,841 Views)
Spencer,

Thank you very much.

I met more problems. I still used example WFMsingleBufRegenerate.C, and tried the selection of WFM_DATA_I16, but I didn't get any waveform. I was confused, in WFM_DATA_F64 type, the value between 0.00 and 4.99, in WFM_DATA_I16, the value between 0 and 2047, then how did WFM_Scale work? What is the output voltage respectively?

Then I didn't use NIDAQMakeBuffer(), and just create my own buffer containing a square wave, it was still two pulses per period, it seemed NI output the difference of two adjacent voltage, not the absolute value, am I right?

Please help me, thanks in advance.

Yinsheng
0 Kudos
Message 3 of 3
(2,841 Views)