Documentation

initialevent

Initialize event variables

Syntax

events 
  when initialevent 
    AssignmentList 
  end 
end

Description

initialevent lets you specify initial values of event variables at the start of simulation. The return data type of initialevent is event, as described in Event Data Type and edge Operator. It returns true once during simulation, right after initialization of continuous variables is finished.

The initialevent keyword is valid only inside a when clause predicate.

Examples

The Asynchronous Sample & Hold block in the Simscape™ Foundation library initializes the event variable y_held, which holds the sampled signal, by using a block parameter.

This example implements an asynchronous sample and hold block where the y_held event variable is initialized based on the value of the input physical signal IC at the start of simulation. Note that there is no need to specify initialization prioriy for the y_held variable because event variables always have high priority.

component ASHold
% Asynchronous Sample and Hold

inputs
   IC = {0.0, '1'}; % :left
    U = {0.0, '1'}; % :left
    T = {0.0, '1'}; % :left
end;

outputs 
    Y = {0.0, '1'}; % :right
end;

variables (Event = true, Access = private)
     y_held = 0.0;    
end

equations
    Y == y_held;
end

events
    when initialevent
       y_held = IC;
    elsewhen edge(T > 0)
       y_held = U; 
    end
end

end

Introduced in R2017b

Was this topic helpful?