Back in 2007 I submitted a patch to Comedi to support triggering analog output off the analog input start signal. The patch was accepted (commit 4284c2266987ad08a26f2758cd09fef06d1ce3cf), and is now old news, but I just ran across my notes from developing it, and thought I'd publish them for posterity (and as a reminder to myself in case I have to dig into the internals of Comedi or NI drivers in the future).

Patch notes

To understand the patch, you should understand some portion of National Instrument's Data Acquisition Systems Timing Controller (NI DAQ-STC, see “Understanding NI DAQ-STC” below and the manual for more details).

We are trying to set up the AO timing so it triggers off of the AI start signal. In NI terminology, that means we want AI_START1 to be the source of AO_START1. The possible sources are listed in the DAQ-STC manual in table 5-2, p6-7 (380), where we see that AO_START1's 19th input is AI_START1. To implement this, we need to write to the card's AO_Trigger_Select register (Appendix B, register 67, pB-21 (470)).

Sounds fairly simple, we should just be able to set the appropriate start_arg. However, looking into source of comedi/driver/ni_mio_common.c, we see that no external triggering information is written to the AO_Trigger_Select_register. Looking back through the STC manual, we come across their AO trigger example (3.6.1.4, p3-23 (185)) which shows how to set up AO triggering. Comparing to ni_mio_common.c, we see that the AO triggering configuration in ni_ao_cmd() looks just like the “software triggered” case in NI's example. So it seems impossible to run externally triggered AO.

The patch edits ni_mio_common.c to make it more like NI's example and ni_mio_common.c's own AI code.

Understanding NI DAQ-STC

Consider the timing sequence shown in the Comedi manual. For output, all the same timings apply, but data is flowing the other way.

Here is a translation table between NI's terminology and Comedi's (NI references from STC manual):

Comedi AI NI AO Reference
seq_start AO_START1Fig 3-10, p3-12 (174)
scan_beginUPDATE Fig 3-2, p3-6 (168)
convert TMRDACWR Fig 3-2, p3-6 (168)

There are references to an AO_START as distinct from AO_START1, but it appears to be unsupported:

  • It does not show up in the manual's AO feature list (section 3.2, p3-2 (164), compare to the AI feature list, section 2.2, p2-2 (31))
  • It shows up in some contexts as unsupported (e.g. section 3.6.5, p3-36 (198))