LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Updating amplitude of sine wave voltage output

I am working on a machine which varies pressure sinusoidally by use of a 0-10 V signal.  This machine was programmed by another person, and I am attempting to optimize the code.  I am unable to post the actual code, but I can describe the way the program is written. 

The code measures the current pressure magnitude and based on the average magnitude compared to the target maximum pressure, computes an adjustment to the AO signal amplitude.  Currently, when the signal is adjusted, the sinewave function is called with the new amplitude.  The code continues to clear the task generating the previous sinewave, generate a new task with the updated sinewave, then start the task to write the new sinewave to the AO.  However, when it does this there is a momentary break in the AO signal which I think is causing pressure fluctuation and instability.  Is there a better way to make a smooth transition when the signal is updated?

0 Kudos
Message 1 of 5
(2,296 Views)

You can start with removing the code for destroying and re-createing the task each time. You can create a task and use it for the rest of the program usage. You only need to update the board's memory. 

For a smoother memory update, maybe you can make use of events and callbacks. For example with DAQmxRegisterEveryNSamplesEvent function, you can register a callback that fires after every N samples are written.

In the callback, if it is not ready to write the new sine wave, you can do nothing. Otherwise simply write the new sine samples. Don't stop/discard the task before you write. 

S. Eren BALCI
IMESTEK
Message 2 of 5
(2,282 Views)
Thank you for the solution. That did indeed fix the issue with the rough updating, but now I am intermittently getting a data buffer error (application unable to keep up with hardware acquisition). Any thoughts?
0 Kudos
Message 3 of 5
(2,219 Views)

I think, That means new samples are written before you can read out the old ones. Either increase the buffer size or read them from the buffer more frequently. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 4 of 5
(2,214 Views)

That is what I'm finding from my research of the error code.  I have tried multiple times to increase the buffer size to no avail.  So as I see it there are a couple of options, but I do want to ensure that my understanding is correct:

1)  Currently the program is set to read 10kS and I have manually (through the DAQmxCfgSampleClk function) set the buffer to 100kS.  I can program an asynchronous timer to read more frequently, but if I do so will the read function wait until all 10k samples are available to write into the read array for processing or will it read the available samples (currently the SampleClk function is set to continuous samples with the ReadAnalogF64 function set to read 10k samples)?

2)  The online support manual makes note of if you repeatedly read and write in a while loop without using the start/stop task functions that the program repeatedly stops and starts the task which degrades performance.  This is essentially how the code is set, but I am not sure exactly what this means.  Could periodically stopping and restarting the IO tasks remedy the issue?

 

I am still working on learning the in's and out's of programming, so I apologize if these are silly questions.

0 Kudos
Message 5 of 5
(2,193 Views)