Hello,
When I tried to run some testing models, I saw that the 'while loop' in the main function is always empty.
Later I found that the code is executed(generated) through 'Interrupt based routine.'
1. What is the reason that the NXP toolbox follows the Interrupt based routine as a default setting for code generation rather than a polling-based routine?
2. If I want to use a polling-based routine, how should I change my settings or model?
- I used a simple testing model as I attached below to check the code generation process.
Thank you
解決済! 解決策の投稿を見る。
Hello @p_a_u_darshana ,
In order to generate code from a Simulink model, you have to use a fixed-step solver which maintains a constant step size for the model. This means that you "execute" the model at regular time intervals as long as you run the simulation.
When you translate this to a microcontroller the simulation will never stop, so the "Simulation" total time is going to run to infinity (of course, or until a reset appears
Let's assume that the step time is 1 second, and the model takes an average of 0.25 seconds to be executed. So by triggering the step function every second, we can guarantee that the model is resolved at each second. But 0.25 is an average. This means that one time it can take 0.2, other time 0.3 or 0.245. And if you are using FreeMaster as well in polling mode, it becomes very difficult to count the time.
If the step time is 1 second, and the model takes 1.5 seconds to execute then you end up in a totally different scenario which I have explained here https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/S32k144-Simulation-Time/m-p/1193243#M54...
So this is why everything is triggered by an interrupt: using a fixed-step solver, requires executing the model at fixed time size intervals.
Unfortunately, you cannot execute the entire algorithm in a while loop in our toolbox, because of the reason above.
But you can do two things here:
1. to profile the model execution time, and to set the fixed step size according to your measurements results, basically to minimize the lost time
2. to generate the code only for the model and to include it inside an S32DS studio project and call the generated code according to the application requirements.
Hope this helps,
Marius
Hello @p_a_u_darshana ,
In order to generate code from a Simulink model, you have to use a fixed-step solver which maintains a constant step size for the model. This means that you "execute" the model at regular time intervals as long as you run the simulation.
When you translate this to a microcontroller the simulation will never stop, so the "Simulation" total time is going to run to infinity (of course, or until a reset appears
Let's assume that the step time is 1 second, and the model takes an average of 0.25 seconds to be executed. So by triggering the step function every second, we can guarantee that the model is resolved at each second. But 0.25 is an average. This means that one time it can take 0.2, other time 0.3 or 0.245. And if you are using FreeMaster as well in polling mode, it becomes very difficult to count the time.
If the step time is 1 second, and the model takes 1.5 seconds to execute then you end up in a totally different scenario which I have explained here https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/S32k144-Simulation-Time/m-p/1193243#M54...
So this is why everything is triggered by an interrupt: using a fixed-step solver, requires executing the model at fixed time size intervals.
Unfortunately, you cannot execute the entire algorithm in a while loop in our toolbox, because of the reason above.
But you can do two things here:
1. to profile the model execution time, and to set the fixed step size according to your measurements results, basically to minimize the lost time
2. to generate the code only for the model and to include it inside an S32DS studio project and call the generated code according to the application requirements.
Hope this helps,
Marius