필터 지우기
필터 지우기

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

조회 수: 9 (최근 30일)
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.)

답변 (1개)

Danny S
Danny S 2022년 3월 4일
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!

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by