MATLAB Answers

Rate Transition with adjustable sampling rate

3 views (last 30 days)
Boru Wang
Boru Wang on 27 Jun 2019
Answered: MarkB on 9 Jul 2019
I am thinking about building a Simulink Model for embeded code generation with multiple task rate. I plan to vary one of the task rate during execution . I am under the impression that Simulink rate transition block only takes fixed task rate. I was wondering if there is a way to introduce rate transition with variable task rate?

  0 Comments

Sign in to comment.

Answers (1)

MarkB
MarkB on 9 Jul 2019
Dear Boru,
Unfortunately, Simulink doesn't support changing sample times in the generated code. The underlying issue is that the generated code for rate transition blocks varies (among other things) depending on whether it is a "faster-to-slower" or "slower-to-faster transition". However, if you changed a sample time in the generated code, you could accelerate or decelerate one part of the code independently of the other sample times in the model. Changing the sample time in the generated code could cause a rate transition that was originally "slower-to-faster" to become "faster-to-slower" (or vice versa). However, the code for the rate transition can't handle this sort of change, so this approach isn't supported.
One alternative approach is to have asynchronous function-called subsystems in an "Export Functions" modeling style (https://www.mathworks.com/help/ecoder/examples/exporting-functions.html). One options is to have function-called subsystems with asynchronous sample times. In this context, the function-called subsystem has no sample time at all. This allows you to call it at irregular rates, but this limits blocks that are allowed in the subsystem, since nothing inside is allowed to demand a sample time.
Overall, this "Export Functions" style of modeling provides some control over the generated function prototypes as well. With this in mind, if you adopt an "Export Functions" modeling style, you probably don't need to use Function Prototype Control, which I recommended in your other post (https://www.mathworks.com/matlabcentral/answers/470164-how-to-customize-the-code-interface-of-a-function-generated-of-a-reference-model).
Regards,
Mark Biesiada

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!