LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop Analog output generation in Mseries DAQ

Hi,
 
I am using M series Multifunction card for analog output generation. I am generating signal continously on analog output by setting the sampleMode to "DAQmx_Val_ContSamps" to generate the samples continously. I want to stop the generation in two conditions.
1) Immediatly by prssing stop button
2) after completion of full cycle.
Can somebody suggest me how to achieve this. 
 
I think DAQmxStop() function stops the generation immediatly.
 
Thanks in Advance 
Gajanan 
0 Kudos
Message 1 of 3
(2,772 Views)

Hello GajananP,

 

There are a couple of things to consider when trying to change the time in which your output will stop.  When using a DAQmx Write call to write values to an analog output there is no way to stop this process before that chunk of data has been written.  If you have a DAQmx Write inside of a loop and each time the loop runs you write your 100 point cycle (I'll assume your cycle consists of 100 points) to the buffer then the fastest that you can stop this output is at the end of 100 points of output.  For instance, if you run your code and you're writing 100 samples at a time and you press the stop button after the first sample has been written then the code will finish outputting the remaining 99 samples and then exit the while loop.

 

If you want to be able to stop generation on a point by point basis then you need to write a single point with the DAQmx Write each time the loop iterates.  In this case you would need to send your 100 point cycle one point at a time each time the while loop iterated so when you press the stop button the loop will stop after a single iteration and at most 1 point will be written after you press stop.  If you want to be able to let the user choose how the generation will be stopped then you can use a case structure and in one case write a full cycle and in the other write point by point.

 

There is one other consideration when doing this and that is how quickly you're updating the output.  In general it is recommended that you write at least 10% of your update rate in Hz each iteration of the loop.  For instance if you are generating 100 points at 100 Hz it is recommended that you write at least 10 points at a time to avoided excessive software loop rates.  Writing 10% of your buffer each iteration would result in the loop running at 10Hz and so the fastest you could stop generation would be 10Hz, or 1/10th of a second (because you’d have to wait for the current DAQmx Write to finish).  Depending upon your specific computer it is likely it can handle running the code at faster than 10Hz, but on any Windows machine running loops at greater than 2kHz can begin to cause buffering problems.  Running the loop at 2 kHz would mean that the generation would be stopped at the end of the current cycle or within 1/2 kHz or 0.0005 seconds.  If you are using a user controlled input to stop the generation it is likely that this delay is very fast compared to the reaction time of the user and the fact that is generates another 0.0005 seconds of data is probably irrelevant.

 

I hope this helps explain how the code will execute.  The basic idea is that the DAQmx Write is a blocking function and once it’s been started it cannot be stopped, but after each loop iteration the code can be stopped.  Since this is the case, if you want to stop the generation faster, then you just have to reduce the time the DAQmx Write takes to execute by reducing the number of samples it has to write.

 

Please reply back with more questions if my explanation was unclear, or if you'd like more information.

 

Have a good night!

Brooks
0 Kudos
Message 2 of 3
(2,751 Views)
Thanks Brooks
your explaination is clear to me.
 
 
Gajanan
0 Kudos
Message 3 of 3
(2,739 Views)