|
1 | 1 | # Synchronising DAQ operations across devices |
2 | 2 |
|
3 | 3 | The examples in this folder relate to synchronising tasks. |
4 | | -It's assumed you're already familiar with the information in vidrio.mixed |
5 | | -Also see ContinuousAI.c in the DAQmx_ANSI_C_examples directory |
| 4 | +It's assumed you're already familiar with the information in `vidrio.mixed`. |
| 5 | +Also see `ContinuousAI.c` in the DAQmx_ANSI_C_examples directory. |
| 6 | +The following demo uses the class `vidrio.sync.sine_AO_AI`, which just plays a sine wave out of AO0 on the target DAQ device. |
6 | 7 |
|
7 | | -### One |
| 8 | +### 1. Starting two tasks at the same time |
8 | 9 | Let's start two tasks at the same time on different DAQs from the command line. |
9 | 10 | Hook up the AO0 lines of each DAQ to a scope then run: |
10 | 11 |
|
11 | 12 | ``` |
12 | 13 | >> B=vidrio.sync.sine_AO_AI('Dev1'); |
13 | 14 | >> R=vidrio.sync.sine_AO_AI('Dev2'); |
14 | | ->> B.startAcquisition;R.startAcquisition; |
| 15 | +>> B.startAcquisition; R.startAcquisition; |
15 | 16 | ``` |
16 | 17 |
|
17 | | -Where 'Dev1' and 'Dev2' are your DAQ names. |
18 | | -You should see two waveforms with a phase shift. |
19 | | -Trigger off the waveform on channel 1 of the scope and change the time scale to show about one cycle of the waveform. |
20 | | -Watch for a while. What do you notice? |
| 18 | +Where `'Dev1'` and `'Dev2'` are your DAQ names. |
| 19 | +You should see two waveforms with a phase shift, since they didn't start at the same instant. |
| 20 | +Set up the scope to trigger off the waveform on channel 1 and change the time scale to show about one cycle of the waveform. |
| 21 | +Watch for a while. See the phase shift? |
21 | 22 |
|
22 | 23 | Stop the acquisition: |
23 | 24 |
|
24 | 25 | ``` |
25 | 26 | >> B.stopAcquisition;R.stopAcquisition; |
26 | 27 | ``` |
27 | 28 |
|
28 | | -Also see `vidrio.sync.phaseMonitor('Dev1','Dev2');` |
| 29 | +You can also use `vidrio.sync.phaseMonitor('Dev1','Dev2');` to monitor the phase of the two waveforms without a scope. |
| 30 | + |
29 | 31 |
|
30 | | -### Two |
31 | | -Will this problem go away if start the two waveforms at exactly the same time? |
32 | | -vidrio.sync.sine_AO_AI triggers the AO task from the AI task so we need to set this up to wait for a trigger: |
| 32 | +### 2. Triggering the tasks simultaneously |
| 33 | +Will the phase shift problem go away if start the two waveforms at exactly the same time? |
| 34 | +`vidrio.sync.sine_AO_AI` triggers the AO task from the AI task so we need to set this up to wait for a trigger: |
33 | 35 |
|
34 | | -Set up triggers so nothing happens until 5V goes into PFI0 |
| 36 | +Set up triggers so nothing happens until 5V goes into PFI0. |
| 37 | +The tasks need to be stopped (see above) then you can run: |
35 | 38 |
|
36 | 39 | ``` |
37 | | ->> B.hAITask.cfgDigEdgeStartTrig('PFI0','DAQmx_Val_Rising'); R.hAITask.cfgDigEdgeStartTrig('PFI0','DAQmx_Val_Rising'); |
| 40 | +>> B.hAITask.cfgDigEdgeStartTrig('PFI0','DAQmx_Val_Rising'); |
| 41 | +>> R.hAITask.cfgDigEdgeStartTrig('PFI0','DAQmx_Val_Rising'); |
38 | 42 | ``` |
39 | 43 |
|
40 | | -Now wire up the rack so that the two PFI0 ports are connected. If using BNC, attach a T-piece to one. |
| 44 | +Note how we can configure the start trigger properties directlty on the two objects we have already created. |
| 45 | +This is what is nice about object-oriented programming. |
| 46 | +To use the triggers, wire up the rack so that the two PFI0 ports are connected. If using BNC, attach a T-piece to one. |
| 47 | +Then start the tasks: |
41 | 48 |
|
42 | 49 | ``` |
43 | 50 | >> B.startAcquisition;R.startAcquisition; |
44 | 51 | ``` |
45 | 52 |
|
46 | | -Nothing happens on the scope until you hook up PFI0 (e.g. with your T connector) to +5 (the breakout box provides this) |
| 53 | +Nothing happens on the scope until you hook up PFI0 (e.g. with your T connector) to +5 (the breakout box provides this). |
47 | 54 | You can unplug the 5V line right away, it's only needed transiently for the trigger. |
| 55 | +Of course you could also hook up PFI0 to a digital line and trigger it via MAX Test Panels or even set up a separate digital task in MATLAB. |
48 | 56 |
|
49 | 57 | What do you see on the scope? The waveforms should be in phase perfectly. Nice, huh? |
50 | | -Keep watching. Ah..... |
| 58 | +Keep watching. Ah... They drift apart over time. |
51 | 59 |
|
52 | 60 | Stop the acquisition: |
53 | 61 | ``` |
54 | | ->> B.stopAcquisition;R.stopAcquisition; |
| 62 | +>> B.stopAcquisition; R.stopAcquisition; |
55 | 63 | ``` |
56 | 64 |
|
57 | | -### Three |
| 65 | +### 3. Sync the clocks |
58 | 66 | The clocks are drifting! |
59 | 67 | Clearly we need a *shared clock* between the boards. |
60 | 68 | Each class is set up such that the AI task on that device uses the AO clock of the same device. |
61 | 69 | So all we need to do is have the AO clock of the DAQ in one class use the AO clock of the DAQ in the other class. |
62 | 70 |
|
63 | | - |
64 | 71 | If your cards are in a PXI chassis or linked by an RTSI cable then you simply tell DAQmx that one device should use the other's clock: |
65 | 72 |
|
66 | 73 |
|
@@ -89,4 +96,6 @@ Wire up your DAQ remembering to use PF1 not digital port 1 on line 0. |
89 | 96 | >> B.startAcquisition;R.startAcquisition; |
90 | 97 | ``` |
91 | 98 |
|
92 | | -Nice synchronised waveforms! |
| 99 | +Nice synchronised waveforms! |
| 100 | +Note that the above only works when your two (or more) tasks need to run at the same rate. |
| 101 | +For more see the [NI synchronisation white paper](http://www.ni.com/white-paper/11369/en/). |
0 commit comments