Implementation of custom block in Modeling Toolkit

Hello everyone,

As an exercise to learn how to use Modeling Toolkit, I set out to ‘translate’ some of the models I had implemented in Simulink. So far, I’ve managed to implement everything perfectly, but there’s one function I haven’t been able to replicate in Modeling Toolkit. This function is the following:

If input == 1output = 1

If input changes to 0, then:

  • output = 2 for 𝜏 seconds (𝜏 is a parameter),
  • then output = 0.

It would be a great help if someone could provide suggestions on how to implement this model using the @mtkmodel macro. I’ve attached a diagram of the system’s operation for clarity. Thanks in advance!"

What did you try?

If you don’t try yourself the chance is low that other people write code for you. You could also ask an AI tool like perplexity.ai first.