2

I can't for the life of me figure out how to enable a software trigger using National Instruments DAQ mx. Documentation vaguely mentions properties, or that it can only be used with a switch device, but it's very incomplete. The one example page on the NI website is completely blank, of course. I don't have or want LabView.

I'm just trying to set it up so it acquires and generates 1000 samples simultaneously. There is lots of documentation for analog or digital hardware trigger, but I just want to be able to start the generation/acquisition on the same software instruction.

If I issue two sequential instructions (one for generate samples, one for acquire samples) it's probably good enough, but I'd really like to do it properly, as I don't know the timing skew between starting two tasks.

So how do I generate a software trigger to start 2 tasks simultaneously?

BTW I'm using PyDAQmx with a USB6363 device on Windows 7 x64.

Thanks

Sonicsmooth
  • 2,673
  • 2
  • 22
  • 35

1 Answers1

2

Measurement Synchronization

In order to have a single event start two tasks simultaneously, the two subsystems must be electrically synchronized. There are two ways to synchronize subsystems, and both require sharing a different electric signal:

  1. Synchronized start
  2. Synchronized sampling

With just the first, the two tasks will start at the same moment, but their individual clocks may skew or drift as time passes. When on the same device, like in your situation, drift is impossible since there is only one oscillator on the device. A single device is always self-coherent in time; in other words, a single device already has synchronized sampling. When synchronizing different devices, both the start trigger and the sample clock signals must be shared.

Synchronized Start

In order to electrically synchronize the start of two tasks, they must use the same start trigger signal, which can be programmed from the DAQmx API using the device's internal signal names [1].

In your example, you want to start the analog input and analog output tasks on a software event. The AI and AO subsystems must first be electrically coupled, and then the software event can trigger both to start.

I realize you're using PyDAQmx, but here is the pseudocode in C (the official API):

TaskHandle analogInputHandle;
TaskHandle analogOutputHandle;

// Other configuration...

// Connect AO start to AI start
DAQmxCfgDigEdgeStartTrig(analogOutputHandle, "ai/StartTrigger", DAQmx_Val_Rising);

// Arm the AO task
// It won't start until the start trigger signal arrives from the AI task
DAQmxStartTask(analogOutputHandle);

// Start the AI task
// This generates the AI start trigger signal and triggers the AO task
DAQmxStartTask(analogInputHandle);    

In this way, the AI and AO subsystems have been configured to use the ai/StartTrigger signal to begin their tasks, and when the program starts the AI task, the device generates a pulse on-demand and the two measurements begin together.

[1] NI-DAQmx Help :: Terminal Names
http://zone.ni.com/reference/en-XX/help/370466V-01/TOC22.htm

Joe Friedrichsen
  • 1,976
  • 14
  • 14
  • Thanks, I was able to find the SynchAI-AO.c file in the installed documentation. It makes sense; I was missing the concept that you could connect internal electrical signals to trigger things. I'm converting to Python now :) – Sonicsmooth May 18 '15 at 17:17
  • Where in this sequence should the tasks be started? – Eric Jul 29 '16 at 01:42
  • 1
    Thanks @Eric. I updated my response to include more details. In short: start the AO task (the *slave*) before starting the AI task (the *master*). – Joe Friedrichsen Jul 29 '16 at 14:15
  • I see you got rid of `SendSoftwareTrigger`, which I was finding would just crash. – Eric Jul 30 '16 at 01:11
  • The [NI documentation for labview's DAQmx](http://www.ni.com/tutorial/5376/en/#toc2) suggests you should also call `TaskControl(handle, Val_Task_Reserve)` before starting either task. Do you know why it suggests this? I find it works both with and without it – Eric Jul 30 '16 at 01:12
  • The link describes how to synchronize tasks on a cDAQ chassis, which unlike an X Series device, has more than one timing engine to run an acquisition. In order for them to share the same electrical signals for synchronization, it's important to assign the master task a specific timing engine, via `Reserve`, so that you can tell the slave task which signals to use. The paragraph below Figure 2 explains in a little more detail. – Joe Friedrichsen Aug 01 '16 at 14:25