How to generate a triggered pulse using Simulink

94 次查看(过去 30 天)
I want to generate a pulse using Simulink when triggered. The output signal is initially 0, then becomes 1 when triggered for a specified time, then -1 for the same amount of time, then back to 0 and hold until triggered again. How can I do this using Simulink.

采纳的回答

Richard
Richard 2024-8-28
This is how I ended up doing it. It is not elegant, but it works.There is a minor issue with using 0 as a threshold on the switch since the time values are a little bit off due to numerical accuracy in the integrator. If there is a better way to do this, I would appreciate a comment.

更多回答(1 个)

Shubham
Shubham 2024-8-26
Hi Richard,
To generate a pulse in Simulink that behaves as you described, you can use a combination of blocks to create a state machine that responds to a trigger input. Here’s a step-by-step guide to set this up:
Components Needed
  1. Trigger Block: To receive the trigger signal.
  2. Stateflow Chart: To manage the state transitions and timing.
  3. Pulse Generator or Constant Blocks: To define the output levels (0, 1, -1).
Steps to Implement
  1. Open Simulink and create a new model.
  2. Use a Pulse Generator or a Constant Block to simulate the trigger input. This block will provide the trigger signal to initiate the pulse sequence.
  3. Drag a Stateflow Chart block from the Simulink library into your model. Stateflow is ideal for managing the sequence of states (0, 1, -1, 0) based on the trigger.
  4. Design the Stateflow Chart:
  • Open the Stateflow chart and create four states: Idle, High, Low, and BackToZero.
  • Idle: The default state where the output is 0.
  • High: The state where the output is 1.
  • Low: The state where the output is -1.
  • BackToZero: The state where the output returns to 0.
  • Define transitions:
  • Idle to High: Triggered by the input signal.
  • High to Low: After a specified time duration.
  • Low to BackToZero: After the same duration as High.
  • BackToZero to Idle: Immediately after reaching 0.
5. Use temporal logic in Stateflow, such as after(time, sec), to control the duration of the High and Low states. For example, if you want the pulse to last 1 second in each state, use after(1, sec).
6. In each state, set the output value. For example:
  • Idle: output = 0;
  • High: output = 1;
  • Low: output = -1;
  • BackToZero: output = 0;
7. Connect Blocks:
  • Connect the trigger signal to the Stateflow chart.
  • Connect the output of the Stateflow chart to a Scope or any other block to observe the output signal.
8. Run the simulation to ensure that the model behaves as expected. When the trigger is activated, the output should follow the sequence 0 → 1 → -1 → 0.
  1 个评论
Richard
Richard 2024-8-26
Thank you for the response. Is there a way to do this without State Machines. I don't have Stateflow.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by