Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronise input and output on USB-4431

Solved!
Go to solution

Hi 

 

I have an application which needs to send out a signal on the USB-4431 and then capture it via an input on the same device.

 

Current I'm using two tasks to do this, one for input and another for output. I've found out that a trigger (on the RTSI bus) can sychronise the start operations of the send/capture cycles so that there can be a constant delay between the captured signal and the output signal.

 

Unfortunately the code I've found is for Matlab. I can't find an equivalent for it in the NIdaq C API. The method is described here;http://www.mathworks.in/help/daq/synchronize-analog-input-and-output-using-rtsi.html.

 

What I can't figure out is how to implement this on the analogue input:

ai.ExternalTriggerDriveLine = 'RTSI0';

Can anyone shed any light on how to do this?

 

The rest of the stuff described here, looks to be doable with a  normal trigger:

ao.TriggerType = 'HwDigital';
ao.HwDigitalTriggerSource = 'RTSI0';
ao.TriggerCondition = 'PositiveEdge';

 

Thanks

Nirvtek

 

 

 

0 Kudos
Message 1 of 10
(6,143 Views)

There's an example in the C NIdaq samples. Unfortunately that doesn't use the RTSI clock, but instead is hardcoded to use specific chassis.

 

It doesn't appear to work with a USB-4431:

 

DAQmx Error: NI Platform Services: The specified resource is reserved. The oper
ation could not be completed as specified.
Task Name: _unnamedTask<1>

Status Code: -50103

 

This is the VC_SyncAI_AO example.

0 Kudos
Message 2 of 10
(6,140 Views)
Solution
Accepted by topic author nirvtek

You can synchronize AI and AO by sharing the start trigger between your two tasks.

 

Pick one of your tasks to be the "master" and one to be the "slave" (doesn't matter which).

Setup a digital edge start trigger on the slave task and set the source of the trigger to be the start trigger of the master.

 

Let's assume the following:

Your device's name is "Dev1"

AI is the master task

AO is the slave task

 

Here's what you'd do to synchronize the two:

1) Create the AI and AO tasks in any order you wish

2) Set up timing on both the AI and AO tasks (the sample rates you choose will need to be the same or power-of-2 multiples of one another (e.g. 100K, 50K, 25K, 12.5K, etc..))

3) Configure your slave task (the AO task) to have a digital edge start trigger and make the source be the start trigger from the master task (the AI task). In our case, "Dev1/ai/StartTrigger".

4) Write some data (a sine wave, presumably) to your AO task

5) Start the slave task (the AO task).  The AO task is now in the "started" state, but since you configured a digital start trigger, it won't actually generate data until it sees a digital edge from "Dev1/ai/StartTrigger".

6) Start the master task (the AI task).  The AI task does not have a digital start trigger, so the driver software will immediately generate a start trigger, which also causes a digital edge on "Dev1/ai/StartTrigger", which causes the AO task to start at the exact same time.

7) Read from your AI task.

 

You'll notice some 0's at the start of your AI data. This is a result of something called "Filter Delay" and it is an inherent feature of all DSA devices -- see the DSA user manual and this KB article for more information on what it is and how to deal with it.

 

Hope this helps.

 

EDIT: I just noticed that you pointed out an existing C example. That's exactly what you want. I don't know why you got a resource reserved error -- I tried it out myself and (after changing the AO range from +/-10V to +/-3.5V), it worked just fine.  Try resetting your device in MAX (or by calling DAQmxResetDevice() from your program)

 

Message 3 of 10
(6,107 Views)

Thanks! That answers my question.

0 Kudos
Message 4 of 10
(6,092 Views)

I got this to work really well as far as synching goes, thanks.

 

Unfortunately sometimes I get buffer underflow error (code -200621) from time to time. The message sometimes indicate that the there's too much data and at other times that the internal buffer on the device underran due to bus transfer issues.

 

What's going on? I'm using a 1000 sample input buffer and a 30000 samples output buffer running in a (often) continuouse loop. The output rate is 48 kHz.

 

Error Message NI.PNG

 

0 Kudos
Message 5 of 10
(6,056 Views)

And this:Error Message 2 NI.PNG

 

I managed to get the previous message to disappear by increasing the input buffer size to 100 KS as per http://digital.ni.com/public.nsf/allkb/E1E67695E76BA75B86256DB1004E9B07

0 Kudos
Message 6 of 10
(6,053 Views)

The tasks runs for around 2-3 s @48 kHz. The timeout was set to 10 s and subsequently increased to 30 s.

 

At the end of a run the app locks up for around 10-30 s and then the error pops up.

0 Kudos
Message 7 of 10
(6,028 Views)

May the USB 4431 work with an external sampling clock?

Or a similar card with 24bit resolution but may work wiht a external sampling clock.

0 Kudos
Message 8 of 10
(1,808 Views)

Hi nirvtek,

May the USB 4431 work with an external sampling clock?

Or a similar card with 24bit resolution but may work wiht a external sampling clock.

0 Kudos
Message 9 of 10
(1,807 Views)

@zhm0204 wrote:

Hi nirvtek,

May the USB 4431 work with an external sampling clock?

Or a similar card with 24bit resolution but may work wiht a external sampling clock.


Please do not hijack threads, you've been provided with an answer at https://forums.ni.com/t5/Multifunction-DAQ/USB-Multi-DAQ-card-with-24bit-resolution/td-p/4281755 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 10 of 10
(1,736 Views)