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