Main Content

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 PS 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.

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 = {value = {0.0, '1'}, priority = priority.high}; 
end

equations
    Y == y_held;
end

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

end

Version History

Introduced in R2017b