Clear Filters
Clear Filters

How can I generate an output pulse in Simulink every time a function-call trigger occurs?

9 views (last 30 days)
I have an existing Simulink model from a customer that uses function-call semantics as event triggers on Stateflow charts, amongst other things.
For our current purposes, I need to be able to generate a simple output pulse when a function-call trigger occurs, such that:
-> At the function call trigger, we set the output to value 1
-> After a fixed period of time (e.g. 1ms), the output value is set to 0.
And this then repeats whenever the function call trigger next occurs.
I tried setting up a stateflow chart as follows:
And although this does generate a pulse, the transition from High to Low state only occurs when the E event occurs, rather than 1ms after when the initial E event occurred. That is, it is obvious that the chart is going to sleep in between the E function-call events.
The E events are around 200ms apart, and each pulse of 'y' is also the same width - when I want it to only be 1ms wide when y=1.
Is there a way to change the chart settings so that it stays awake until the transition from High back to Low has occurred?
Or could I acheive the same behaviour using a Function-call subsytem instead of a Stateflow chart? Either is fine for me.
(The overall model uses a Variable solver, as the block generating the function-call pulses requires it.)

Answers (1)

Danny S
Danny S on 4 Mar 2022
So after some experimentation, here's a solution that seems to be working for me.
The chart:
This lives inside the following subsystem:
The FunctionCall input comes from the customer block that generates occasional function calls. The 1ms function call has a sample time of 0.001. These are muxed to the input events of the chart as E and M1 respectively.
Within the chart, the function call E will transition from Low state to High state and set y=1; Then, after 2 instances of the M1 event, we transition back to low and set y=0.
It does seem odd that I need to wait for 2 instances of M1, rather than just having the transition as M1 - but given that E and M1 will both occur at the same time (generally, E is at a microsecond boundary), without the after(2, M1) transition, I could see the state transitions happening by using debug breakpoints and stepping, but they were both occurring at the same time step thus the pulses were 0 time in width.
With the above chart, I can see (via a Scope of the value of y) that I'm getting y pulses with width 1ms, and they start at the same time as E.
If someone has any better solutions, please feel free to submit them too!

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!