SetGlobalCounter
SetGlobalCounter()
Description
Sets the threshold and monitored event for one of the 5 global counters.
Global counters can count instances of events, and handle when the count exceeds a threshold from any state (by triggering a state change).
For more on global counters, see Using State Matrices.
Syntax
NewStateMatrix = SetGlobalCounter(StateMachineStruct, CounterNumber, TargetEventName, Threshold)
Parameters
StateMachineStruct: The state matrix whose global timer you are setting.
CounterNumber: The number of the counter you are setting (an integer, 1-5).
TargetEventName: The name of the event to count (a string; see Input Event Codes)
Threshold: The number of event instances to count. (an integer).
Returns
A state machine struct, updated with the new global counter setting.
Example
% This code generates a state machine that sets a global counter to count 5 BNC1High events, resets the count to 0 in the second state, and handles it in the third and fourth states.
sma = NewStateMatrix();
sma = SetGlobalCounter(sma, 1, 'BNC1High', 5);
sma = AddState(sma, 'Name', 'State1', ... % BNC1High Events in this state are not counted because the count will be reset.
'Timer', 1,...
'StateChangeConditions', {'Tup', 'State2'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'State2', ... % This state resets the global counter.
'Timer', 0,...
'StateChangeConditions', {'Tup', 'State3'},...
'OutputActions', {'GlobalCounterReset', 1});
sma = AddState(sma, 'Name', 'State3', ...
'Timer', 0,...
'StateChangeConditions', {'Port1In', 'State4', 'GlobalCounter1_End', 'exit'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'State4', ...
'Timer', 0,...
'StateChangeConditions', {'Port1Out', 'State3', 'GlobalCounter1_End', 'exit'},...
'OutputActions', {});