Triggered subsystems at time t=0

5 views (last 30 days)
Ubaldo Tiberi
Ubaldo Tiberi on 14 Apr 2011
Hi all,
I'm dealing with a simulink model, in which I have several blocks that are triggered on their rising edge by a pulse generator block. Everything works fine, except for the first pulse. The subsystem is not triggered at the very beginning of the simulation, but I want it to be triggered. The only way to solve this problem is to slightly delay the pulse generator of some ms, but I cannot do that, since there are several S-Functions with aperiodic NextVarHitTime, for which I cannot add an offset. How can I solve such problem?

Answers (3)

Jonathan on 23 Apr 2013
The answer is to use an enabled subsystem. Use a detect increase block going to the enable, and then set the initial output as 1.

Fangjun Jiang
Fangjun Jiang on 15 Apr 2011
Would a function-call generator block solve your problem?
If you have a pulse generator with a periodic time of 4s and your subsystem is triggered by the rising edge, you can achieve the same by using a function-call generator block with sample time as 4s. Change the trigger type of your subsystem to be function-call.
The subsystem will be triggered every 4s and it is first triggered at t=0.

MarkB on 21 Apr 2011
Unfortunately, this sort of behavior is definitely impossible using only a triggered subsystem. Since the "edge" that triggers the subsystem is, by definition, two samples (either a high followed by a low, or a low followed by a high), it really can't execute on the first simulation step.
I would second Fangjun's recommendation that you use a function-call subsystem with a minor modification: Instead of just having a function-call generator drive the block, you could have a Stateflow chart that outputs function calls drive the block instead. The Stateflow chart allows much more complicated outputs that could allow you to always call the subsystem on the first step, and then have subsequent function calls occur based on more complicated criteria.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!