Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Simultaneous Analog Input and output in C++ with the PCI-8259

I am using the PCI 8259 for simultaneous analog input and output.   I first configure a task 1 for analog input of N samples with a clock rate of F.  Since you are not allowed to configure a task with both analog input and output, I configure a second task with the same number of samples, N, and the same clock rate F.  If I then use a DAQmxStartTask(taskHandle1) to start task 1 followed by a DAQmxStartTask(taskHandle2) to start the second task, they start relatively quickly; however, if Windows is busy sometimes they wil get out of sync by one or more samples. I think this is because Task 1 starts sampling before Windows gets around to starting task 2.  To get around this I set both tasks 1 and 2 to start on a digital input, so after I issue the start tasks they are waiting for the digital line to change.  I wait a short time so that I know that they are waiting and then use a third task to flip the digital line so they both start at the same time.  This appears to work.
 
The problem is that in the final instrument, I do not have access to a digital line that I can toggle so this method cannot be used.  I there some way in software to trigger them with the same command or to have one trigger when the other starts?  Is there an alternate way of accomplishing what I am trying?
 
Thanks, bv23
0 Kudos
Message 1 of 3
(3,200 Views)
One way to do it would be to commit both tasks before starting them.
DAQmxTaskControl(taskHandle1,DAQmx_Val_Task_Commit);
DAQmxTaskControl(taskHandle2,DAQmx_Val_Task_Commit);

That would prepare the tasks for running (which is the most time-consuming) and then the DAQmxStartTask() calls would be much faster and would hopefully start the AI and AO in sync (depending on your timing demands).

Hope this helps.
LDP
0 Kudos
Message 2 of 3
(3,184 Views)

Hello bv23,

 

You have nearly everything setup correctly for this to work you just need to change one of two things:

 

1.  If both analog input and analog output tasks are going to be running at the same rate then you can just modify the DAQmxCfgSampClkTiming source for the analog output to be the analog input sample clock.  Then, as long as you start the analog output task first they will be synchronized because even if the analog output is started before the analog input the sample clock won't be available until the analog input is also started.

 

1.  If you want to run both tasks as different rates (though this also works if they run at the same rate).  What you need to do is add a DAQmxCfgDigEdgeStartTrig call to the analog output task and choose the source as the Dev1/aiStartTrigger (where "Dev1" is your device name).  Then, once again you start the analog output task with the DAQmxStartTask call and it will then be waiting for the internal digital edge generated by the DAQmxStartTask call to the analog input.  This will effectively synchronize the start of your two tasks and let you use different (or the same) sample clocks.

 

Either of these methods will allow you to synchronize your two tasks without using the external digital trigger.  Feel free to post back if you have any questions about how to implement these solutions.

 

Cheers,

Brooks
0 Kudos
Message 3 of 3
(3,183 Views)