mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / Comedi_and_NI_triggering.mdwn
1 Back in 2007 I [submitted a patch][submit] to [[Comedi]] to support
2 triggering analog output off the analog input start signal.  The patch
3 was accepted (commit 4284c2266987ad08a26f2758cd09fef06d1ce3cf), and is
4 now old news, but I just ran across my notes from developing it, and
5 thought I'd publish them for posterity (and as a reminder to myself in
6 case I have to dig into the internals of Comedi or NI drivers in the
7 future).
8
9 Patch notes
10 ===========
11
12 To understand the patch, you should understand some portion of
13 National Instrument's Data Acquisition Systems Timing Controller (NI
14 DAQ-STC, see “Understanding NI DAQ-STC” below and the [manual][] for
15 more details).
16
17 We are trying to set up the AO timing so it triggers off of the AI
18 start signal.  In NI terminology, that means we want `AI_START1` to be
19 the source of `AO_START1`.  The possible sources are listed in the
20 DAQ-STC manual in table 5-2, p6-7 (380), where we see that
21 `AO_START1`'s 19th input is `AI_START1`.  To implement this, we need
22 to write to the card's `AO_Trigger_Select` register (Appendix B,
23 register 67, pB-21 (470)).
24
25 Sounds fairly simple, we should just be able to set the appropriate
26 `start_arg`. However, looking into source of
27 `comedi/driver/ni_mio_common.c`, we see that no external triggering
28 information is written to the `AO_Trigger_Select_register`.  Looking
29 back through the STC manual, we come across their AO trigger example
30 (3.6.1.4, p3-23 (185)) which shows how to set up AO triggering.
31 Comparing to `ni_mio_common.c`, we see that the AO triggering
32 configuration in `ni_ao_cmd()` looks just like the “software
33 triggered” case in NI's example.  So it seems impossible to run
34 externally triggered AO.
35
36 The patch edits `ni_mio_common.c` to make it more like NI's example
37 and `ni_mio_common.c`'s own AI code.
38
39 Understanding NI DAQ-STC
40 ========================
41
42 Consider the timing sequence shown in the Comedi manual. For output,
43 all the same timings apply, but data is flowing the other way.
44
45 Here is a translation table between NI's terminology and Comedi's (NI
46 references from STC manual):
47
48 <table>
49   <tr><th>Comedi AI</th> <th>NI AO</th>    <th>Reference</th></tr>
50   <tr><td>seq_start</td> <td>AO_START1</td><td>Fig 3-10, p3-12 (174)</td></tr>
51   <tr><td>scan_begin</td><td>UPDATE</td>   <td>Fig 3-2,  p3-6  (168)</td></tr>
52   <tr><td>convert</td>   <td>TMRDACWR</td> <td>Fig 3-2,  p3-6  (168)</td></tr>
53 </table>
54
55 There are references to an `AO_START` as distinct from `AO_START1`,
56 but it appears to be unsupported:
57
58 * It does not show up in the manual's AO feature list (section 3.2,
59   p3-2 (164), compare to the AI feature list, section 2.2, p2-2 (31))
60 * It shows up in some contexts as unsupported (e.g. section 3.6.5,
61   p3-36 (198))
62
63 [submit]: http://groups.google.com/group/comedi_list/browse_thread/thread/cc2141e7cf23e7ca/
64 [manual]: http://digital.ni.com/manuals.nsf/websearch/E929838D7D0EE50986256728007FEADF
65
66 [[!tag tags/linux]]
67 [[!tag tags/programming]]
68 [[!tag tags/hardware]]