Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Specify end point for Digital output using a Circular Buffer

Solved!
Go to solution

When using DAQmx and an NI DAQ to output a digital signal using a circular buffer (the DAQs buffer). The program runs and works but when the function "DAQmx Stop Task.vi" is called to terminate the task, it stops the buffered output as soon as it is called and does not wait until the buffers pointer has reached the final value in the buffer. I would like the program to wait until the buffers pointer is on the final value in the buffer, does anyone know how to specify this setting?

0 Kudos
Message 1 of 9
(6,264 Views)

Hi there,

 

The VI you'll want to use before "DAQmx Stop Task" is "DAQmx Wait Until Done", it's just a case of wiring it in before the Stop Task.

 

This VI will make your task wait for the generation to complete and ensures that the specified operation is complete before you stop the task. 

 

You can find examples of using DAQmx in LabVIEW's example finder, this can be found in the Help toolbar by clicking on "Find Examples", and then browsing through the examples files under Hardware Input and Output -> DAQmx.

0 Kudos
Message 2 of 9
(6,231 Views)

Just to add to this, I'd recommend having a look at this White Paper:

 

Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications

Message 3 of 9
(6,229 Views)

Thank you for this, I will read the document as well as test the suggested solution as soon as I get the equipment together.

0 Kudos
Message 4 of 9
(6,212 Views)

I have tried this and the "Wait till task done.vi" times out, because the DAQ is set to send a continuos output so the task is never done. I have also tried changing the task from a continuous output to a finite output and this also does not work because the task must be stopped before this can be done. As I understand, if I stop the task then the buffer pointer returns to the first address in memory so this is not an option. If the task is aborted before I attempt to change it to a finite output then I get the error "task must be stopped".

0 Kudos
Message 5 of 9
(6,186 Views)

Apologies, I assumed you were performing a finite task

 

For continuous acquisition, it's standard practice to put the DAQmx Read vi into a while loop which is controlled through the conditional stop terminal, as shown in the image

 

Continuous Input.PNG

You can find examples on this in the LabVIEW example finder (Toolbar -> Help -> Find Examples -> Hardware Input and Output -> DAQmx)

 

If you posted up your code, it could be easier to see what may be tripping your code up?

0 Kudos
Message 6 of 9
(6,181 Views)
Solution
Accepted by topic author michaelmads

If you need the output to stop on exactly the last sample you'll need a way to trigger the stoppage in hardware.  The options available to you will depend on what DAQ hardware you are using, but here are a couple possibilities off the top of my head:

 

1.  Configure a retriggerable finite digital output task (not all hardware supports it).  Configure a counter output to issue a periodic trigger signal with the necessary timing such that the end result is an uninterrupted "continuous" digital output.  When you stop your loop, stop the counter task--the digital output task will finish its generation but the trigger signal will be removed and so it will not continue after that.

 

2.  If you have an extra unused digital output line, add it to your task.  This line should output all 0s except the last sample.  Physically wire this added digital line into a PFI line and use it to trigger a counter output.  Have the counter output generate a single pulse of some long duration (long enough to guarantee the software can respond before it is done).  Use the output of the counter task as a pause trigger for the digital output task.  Don't start the counter task until you exit your loop.  Don't stop the digital output task until you have detected in software that the counter has been triggered.

 

 

If you need the output to stop on approximately the last sample, you could poll the TotalSamplesPerChannelGenerated property after you exit your loop and only stop the task once it reaches a multiple of your circular buffer size.  Doing this doesn't give you any guarantee that it will stop on the last sample (if you're using a device on a bus with higher latency like USB or Ethernet the non-determinism would be worse).

 

 

Best Regards,

John Passiak
Message 7 of 9
(6,157 Views)

Thank you for th suggestion. This is essentially what I am doing except I do not have the "s task done" node because this only works for finite tasks (otherwise the task would always stop after one circular buffer loop due to the use of an "or" gate). The problem is when the stop command is issued the digital output terminates immediately and doesn't wait for the buffer to reach any particualar location in memory (as far as I can tell). A brief description of my code is as shown below:

 

code

 

0 Kudos
Message 8 of 9
(6,133 Views)

The DAQ I have is the Ni 6343, it looks as though I will have to use triggering or something equivalent. It is a bit surprising this option can not be set in the hardware, because the resulting possible solution is much less elegant (and possibly "wastes" a line).

 

Thank you for your post.

0 Kudos
Message 9 of 9
(6,132 Views)