Measurement Studio for VC++

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 4
(6,838 Views)
Hi,

This sounds to me like a buffer problem. I can tell you this: make sure that your button for adjusting the amplitude is read out each time and then you contruct the signal you want to output each time again. Then start the analog write. Then again when the amplitude is adjusted you have to contruct the signal once more and start the write once again and so on.

Also make sure that you put the DoNotAllowRegen attribute On with DAQmxSetWriteAttribute (gTaskHandle, DAQmx_Write_RegenMode, DAQmx_Val_DoNotAllowRegen) for example.
Kind Regards,

Joris Donders
National Instruments
EMEIA GTM Lead for Semiconductor
www.ni.com/semiconductor
0 Kudos
Message 2 of 4
(6,819 Views)
Thanks for your reply , but there are some things still unclear to me :

- when using the DoNotAllowRegen flag, the outgoing signal will stop after one iteration, right ? So i will have to restart it myself. Is this feasible with the DoneEvent() ? Is that callback fast enough to be sure that the signal isn't dropped for too long ?
- I don't fully understand your explanation about reading out & starting the signal : what do yo mean with "is read out each time" ? Or is this exactlt what I said above : start the signal every iteration manually, after reading out the pushbuttons

thanks in advance !

Jeroen
0 Kudos
Message 3 of 4
(6,815 Views)
Hi Jeroen,

You are right about the outgoing signal that will stop after one iteration and you indeed need to start it again manually.
How i see it but that is like it's done in labview is that you have got an program which initialisates everything and then you go to a loop (while loop) where you read the amplitude, build your signal with that amplitude and then start the generation and you keep on doing this until you press stop.

"is read out each time" just means that you have to make sure that you get the updated value of the amplitude each time it changes and then build your signal with this new amplitude before outputting the signal.

About the DoneEvent(), dont have any idea about this, just try and look at the result. Sorry. A loop will centainly do the trick but i don't know if its possible to use a loop in your architecture.
Kind Regards,

Joris Donders
National Instruments
EMEIA GTM Lead for Semiconductor
www.ni.com/semiconductor
0 Kudos
Message 4 of 4
(6,808 Views)