Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Manipulating an analog output signal

I'm trying to write a very simple application that sends out an analog
waveform, of which the user (myself) can increse/decrease the
amplitude by pressing a button. This is my init code (amplitude
starting at 4.0):


ampl = 4.0;
for(int i=0;i<1000;i++)
data[i] = ampl*sin((double)i*2.0*PI/1000.0);

DAQmxCreateTask("",&taskHandle);
DAQmxCreateAOVoltageChan(taskHandle,"Dev1/
ao1","",-5.0,5.0,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(taskHandle,"",
1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);
DAQmxWriteAnalogF64(taskHandle,
1000,0,0.0,DAQmx_Val_GroupByChannel,data,&res,NULL);
DAQmxStartTask(taskHandle);

then i have 2 routine which adjust ampl, refill the data array and
call Write again :

if (ampl < 10)
ampl++;

for(int i=0;i<1000;i++)
data[i] = ampl*sin((double)i*2.0*PI/1000.0);

int32 res;
DAQmxWriteAnalogF64(taskHandle,
1000,0,0.0,DAQmx_Val_GroupByChannel,data,&res,NULL);

this works nicely, but whenever I press the up or down buttons, it
takes around 8 seconds before my oscilloscope sees the changes !!
Somehow, the new data is only inserted after a long time

what am I doing wrong ???
0 Kudos
Message 1 of 3
(2,843 Views)

Hi,

Your logic seems to be correct but it would be easier to tell what the problem is if the entire code or project was available.  Please post project so that we can see if the problem occurs in another part of the application.

0 Kudos
Message 2 of 3
(2,817 Views)
Hello!

I have a theory about what is happening.  Let me explain what your task is doing.  You create a buffer of 1000 samples that you prewrite with your first waveform.  The default behavior of the streaming in DAQmx is to regenerate the data in this buffer.  What this means is that this data is written to your device over and over until the FIFO is full, and then keeps being written whenever room is available.  When you write new data, you won't see it until the data that is already in the FIFO has been output to your Analog Ouput channels.  Lets take, for example, a 6259.  This device has a FIFO size of 8191 samples.  Since you are using 1 channel at 1 kHz, then emptying that FIFO would take about 8 seconds.  Therefore, when you change the data in your buffer you aren't seeing it being output until 8 seconds have passed.

To remedy this, I suggest setting your regen mode to "DAQmx_Val_DoNotAllowRegen" using "DAQmxSetWriteRegenMode".  However, this will cause some other behavior.  When you do not allow regeneration, you must continually write data to your buffer.  If the buffer empties and there is room in the FIFO you will get a buffer underflow error.  So you need to be writing data as fast as you are generating it.

I hope this helps!
------
Zach Hindes
NI R&D
0 Kudos
Message 3 of 3
(2,799 Views)