xPC Target | ![]() ![]() |
Using the Property TriggerSample to Capture Data
xPC Target scopes include the ability to have one scope trigger another, and to delay retrieving data from the second after a trigger event on the first. This feature is most useful when data acquisition for the second scope is triggered after data acquisition for the first scope is complete. In the following explanation, Scope 2 is triggered by Scope 1:
P
sc(2).ScopeId = 2
, sc(2).TriggerMode = 'Scope'
, sc(2).TriggerScope =1
, sc(2).TriggerSample =
range 0
to (N
+
P
- 1
).
In the figures below, TP is the trigger point or sample where a trigger event occurs.
Figure 6-1: Pre-triggering (P<0)
Figure 6-2: Post-triggering (P>0)
In the simplest case, where P = 0
, the first sample will be acquired. If P < 0
(pre-triggering), acquisition will start |P|
samples before TP
, and if P > 0
(post-triggering), acquisition will start P
samples after TP
. It is not possible for Scope 1 to trigger Scope 2 before the trigger event occurs:
sc(2).TriggerSample = 0
means that Scope 2 will be triggered when Scope 1 is triggered. TP
for both scopes will be at the same sample.
sc(2).TriggerSample = n > 0
means that TP
for Scope 2 will be n
samples after TP
for Scope 1. Note that setting sc(2).TriggerSample
to a value larger than (N + P - 1)
does not cause an error; it however implies that Scope 2 will never trigger, since Scope 1 will never acquire more than (N + P - 1)
samples after TP
.
sc(2).TriggerSample = 0 < n < (N + P)
enables you to obtain some of the functionality that is available with pre- or post-triggering. For example, if Scope 1 has sc(1).NumPrePostSamples = 0
(no pre- or post-triggering), and Scope 2 has sc(2).TriggerSample = 10
and sc(2).NumPrePostSample = 0
, the behavior displayed by Scope 2 is equivalent to having sc(2).TriggerSample = 0
and sc(2).NumPrePostSamples = 10
.
Acquiring Gap-Free Data
When sc(1).TriggerSample = -1
and sc(2).TriggerSample = -1
you get new functionality that cannot be achieved with pre- and post-triggering. This new functionality is gap-free acquisition of data.
To do this, you would need to set up two scopes, each triggered by the other, with both scopes having TriggerSample = -1
. This is represented by the following figure.
Both the scopes receive exactly the same signals, i.e. the signals you wish to retrieve.
One of the scopes needs to be software triggered in order for acquisition to start. Otherwise, each scope would be waiting for the other to finish acquiring data, and would never start. In the example, Scope 1 is software triggered to start the acquisition.
The following script is a typical example of how you can use this feature to retrieve data.
% assumes that model is built and loaded on target. tg = xpc; sc = tg.addscope('host', [1 2]); sc.addsignal([0 1]); % [0 1] are the signals of interest; add to both % default value for TriggerSample is 0, need to change it. set(sc, 'NumSamples', 500, 'TriggerSample', -1) sc(1).TriggerScope = 2; sc(2).TriggerScope = 1; start(sc); start(tg); sc(1).trigger; % start things off by triggering scope 1 data = zeros(0, 2); t = []; scNum = 1; % we will look at scope 1 first % Use some appropriate condition instead of an infinite loop while(1) % loop until the scope has finished while ~strcmp(sc(scNum).Status, 'Finished'), end data(end + 1 : end + 500, :) = sc(scNum).Data; t( end + 1 : end + 500) = sc(scNum).Time; start(sc(scNum)); % restart the scope scNum = 2 - scNum; % switch to the next scope end
This example assumes that the communication speed and number of samples is fast enough to acquire the full data set before the next acquisition cycle is due to start. You can also use more than two scopes to implement a triple- or quadruple-buffering scheme instead of the double-buffering one shown here.
![]() | Using the Method Syntax with Scope Objects | addsignal | ![]() |