Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get simultaneous AI/DO?

Hi All,
 
I'm doing simultaneous analog input with digital output, and there are some similar examples in help. But when I write the acquired data into a file, I found that the analog input is delayed by one sample. And the data I've got don't start from the first digital output, but from the default digital value. Could you tell me how can I get rid of that?  Here are my code, and the txt file. Thank you. (I'm using LV 8.5 under windows XP OS)
 
Best wishes
Bo
------------------------
My blog Let's LabVIEW.
Download All
0 Kudos
Message 1 of 11
(4,054 Views)
Is it caused by the reason: the sample clock of the digital output is the analog input sample clock, so the AI happens before the DO?
------------------------
My blog Let's LabVIEW.
0 Kudos
Message 2 of 11
(4,024 Views)
Hi Bo,

I've had a look at your code, but have a couple of questions about your problem!

When you say the analogue input is delayed by one sample, what do you mean exactly - delayed relative to what? Also, how are you identifying that the digital output doesn't update before the AI operation?

A couple of suggestions I would make that may make the timing on the program more predictable:
  • If you want the DO to happen before the AI, put a small wait (1ms) in between the two "Start Task"s to see if this helps. The current implementation should work though - again, how are you measuring this?
  • You could make both the tasks start at exactly the same time with a hardware trigger. At the moment, the software determines when the tasks start, which is unreliable in terms of timing. If you configure the tasks exactly as they are now (sharing a clock) and have them both start operations with a given hardware trigger, this should synchronise the tasks completely. An example of this can be found in the NI example finder at Hardware Input and Output » DAQmx » Synchronisation » Multi-Function-Synch AI-AO-Ext Dig Trigger.vi. Whilst this is synchronising analogue input and output, you could still apply the concept to your existing code.
I hope this helps; if not, please clarify the issue further.

Best regards,
Tom

Applications Engineering, NI UK
0 Kudos
Message 3 of 11
(3,998 Views)

Hi Tom,

Thank you for your reply. I'm sorry about the description of the question. If you check my .txt file you can see that the first two samples are 4.xxx (high), but on the front panel I set the DO as "10......" but not "110...", and the rest are correct. Thus I thought the first sample is not correct, which was the previous amplitude of the DO (in the previous run, the amplitude of DO was 1). Or say, there was an extra sample.  And I just wanted to solve that problem. I tried your first advice but it seemed not work. I didn't try the second one because I haven't got a generator at the moment. But I'll try it ASAP. Thank you again.

Regards,

Bo

------------------------
My blog Let's LabVIEW.
0 Kudos
Message 4 of 11
(3,965 Views)
Hi Bo,

Thanks for clearing that up, I didn't realise you had the DO connected directly to the AI! In that case, the reason you were seeing the issues (or upredictable results in general) is because the tasks start one after the other, and won't necessarily start on the same clock pulse.

To remedy this and get totally reliable results, one would normally set both tasks to trigger off the same pulse. However, since you might not be able to trigger your DO task on your device (a limitation of the hardware), I've altered your code for another solution.

A counter task is set up in parallel with the AI and DO tasks. The counter is then used as the timebase for the other two tasks, so that they share a clock. The counter task is then started AFTER the other two tasks (using a sequence structure to make sure) so that both the tasks start on the same edge. Have a look at the attached code to see what I mean. I slowed the frequency down a bit so you can see it more clearly. This will now show the same behaviour each time round.

The first AI point will be acquired before the DO goes high. This is because the DO gets it's command at the exact same time as the AI clocks the data in; a slight propagation delay means it will not show up on the first sample. If you need to, you could remove the first sample every time with some array manipulation.

I hope this helps and is suitable for you! Please let me know if you have questions about the code.

Best regards,
Tom

Applications Engineering, NI UK
0 Kudos
Message 5 of 11
(3,947 Views)

Hi Tom,

Thank you for your advice. I ran the code but it seemed not work. I got several samples before the expected samples. Any way, I tried your another advice to remove the first samlpe by adding a case function in the loop. And the reresult is OK now. Thank you for your patience.

Best wishes,

Bo

------------------------
My blog Let's LabVIEW.
0 Kudos
Message 6 of 11
(3,908 Views)
Hi Bo,

Only 1 sample came before the 5V spike in testing here, so I'm not sure why you see different results. Still, as long as you can get reliable results with a bit of coding that are what you expect then that sounds great! Glad I could help.

All the best,
Tom

Applications Engineering, NI UK
0 Kudos
Message 7 of 11
(3,906 Views)

Hi Tom,

I set the data of the front panel as "1 0 1 0 0 1 0 0 0 1 0 0 0 0 1", teh frequency was 100Hz, and the samples to read is "-1" which as default. I connected DO0 to AI1, and here is my data:

"0.010791

4.973658

0.011758

4.976235

-0.000160

0.011758

4.972369

-0.000160

1.156492E-6

0.011919

4.977040

1.156492E-6

0.000806

1.156492E-6

0.011436

4.982838

4.977201

0.011275

4.975430"

You can see that the first sample is still extra, and I hope I didn't misunderstand something. Thank you for your reply.

Best wishes

Bo

------------------------
My blog Let's LabVIEW.
0 Kudos
Message 8 of 11
(3,903 Views)
Hi Bo,

This is expected behaviour. As I mentioned above, the first sample will be low, and you can remove that sample programmatically if you need to:

"The first AI point will be acquired before the DO goes high. This is because the DO gets it's command at the exact same time as the AI clocks the data in; a slight propagation delay means it will not show up on the first sample. If you need to, you could remove the first sample every time with some array manipulation."

Everything seems to be working fine, so don't worry about it!

Regards,
Tom

Applications Engineering, NI UK
0 Kudos
Message 9 of 11
(3,899 Views)
Hi Tom,
 
Thank you for your advice.Robot Happy
 
Best wishes
Bo
------------------------
My blog Let's LabVIEW.
0 Kudos
Message 10 of 11
(3,873 Views)