LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing DAQmx digital write and analog read - a real head-scratcher

Solved!
Go to solution

I am trying to synchronize digital write and analog in DAQmx (2019). Since I ultimately want what I write to be dependent on what I read, I am putting them both in a loop and reading and writing in chunks of N data points per iteration. Now, I have previously done this with analog write and analog read and there was no problem - I put run task before the loop starts, and then reading and writing happen at nearly the same time.

 

But with digital write, I am running into strange problems:

 

1) If I put run task before the loop starts, I receive the error "Generation cannot be started because the output buffer is empty." Analog write does not result in this error. 

2) If I put run task after the first iteration of the loop, the digital write comes at a large delay (nearly a second) after analog read, as is apparent both by reading in the 'current write position' and by connecting the write output port to the read input port on my I/O breakout board and checking the delay between what I write and what I read. This same thing happens if I do it with analog write instead. This is strange because in all the NI examples they have the run task come after write (and the same problem with 'current write position' exists in these official examples as well!)

 

I wrote a short program to demonstrate this issue. In it, you can modify both whether it does digital write or analog write, and whether the run task is before or after the first write. The ONLY combination that works is analog write and run task before the first write. Anything else either results in an error or a delay - see the calculated 'Read/write difference', and also if you can try connecting the digital and analog outputs to your analog input and see that the pulse in the write graph comes at a long delay in the read graph!

 

Anyway I've been stuck on this for many days. Any help would be much appreciated.

 

New Bitmap Image (4).jpg

0 Kudos
Message 1 of 4
(2,383 Views)

By the way, I realize this could be dependent on the I/O device. I am using a PCIe-6351, which has 12 analog inputs, 2 analog outputs, and 1 8-bit digital port. I also tried it on a PCIe-6343 where I had to change the 8-bit digital write to its 32-bit version, but then got the same error/delay.

0 Kudos
Message 2 of 4
(2,290 Views)

I managed to fix the delay simply by replacing the clock source on the digital output timing with the 10 MHz reference clock. I have no idea why that worked - why is there a delay problem with the onboard clock? There is also still an asymmetry between digital and analog output in that I am still getting an error if I put 'run task' before the first digital write regardless of the clock source, while if I put 'run task' after analog write it results in a large delay, so they necessarily end up being at different places for my digital and analog writes.

 

I haven't been able to find an explanation for these issues in the documentation. If anyone could at least link the right pages for me to read it would be very helpful.

0 Kudos
Message 3 of 4
(2,250 Views)
Solution
Accepted by topic author Michaelas

Problem solved by switching to hardware-timed single point mode:

 

http://www.ni.com/documentation/en/ni-daqmx/latest/mxcncpts/controlappcase2/

Message 4 of 4
(2,219 Views)