Block Orderring fails for Blocks with infinite sample time

malife
Expert
Posts: 56
Joined: Tue Apr 17, 2007 7:24 am
Location: Santa Cruz, CA
Contact:

Block Orderring fails for Blocks with infinite sample time

Postby malife » Wed Jan 21, 2009 9:06 pm

Hello Lubin
I have several "init" C- function blocks that I need to execute at a specified order upon booting the dsPIC, if I use the Block ordering option only the last block in the sequence order gets included. Right now I guess I can work around this by doing just one C-block that calls all in the specified order, so this is not a show stopper, just something for you to consider for the next version.

Here are a couple of screenshots of the model and the generated code:

Thanks!

Mariano
Attachments
Code.png
Generated Code
Code.png (40.86 KiB) Viewed 1921 times
Model-1.png
Simulink Model
Model-1.png (19.17 KiB) Viewed 1920 times

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: Block Orderring fails for Blocks with infinite sample time

Postby LubinKerhuel » Thu Jan 22, 2009 2:18 am

Hello Mariano,

Thanks for your clear explanation. You find an interesting problem I would never find such a bug by myself ;-)

My explanation is the following:

You checked the Inline parameters (Simulation==>Configuration Parameters==>Optimization) to reduced the RAM memory of the dsPIC.

When a block with infinite sample time (thus, for initialization here) has an input, Simulink try to optimize the code (Inlines parameters). Thus, it computes the scalar (or vector) result for this entry at time 0 because that block will be executed only once at time 0, and directly inject the result to last block with infinite sample time… This is why the blocks attached to a block with infinite time are not executed and thus implemented in the C code!

Therefore, The method I usually use to force the block ordering will cause trouble in such a case. I am not sure there is a solution to make it works differently.

However, there is another way to constrain the ordering of the blocks: using the simulink built in mechanism.
Each block has Priority parameters (right click on the block ==> Block Properties. The lower the priority value, the sooner the block executes. If blocks are not inside a loop, this will work 100%. Otherwise, be aware that this added constraint may not be satisfied by simulink…
Simulink_BlockProperty_Priority.png
Simulink_BlockProperty_Priority.png (18.02 KiB) Viewed 1914 times



You can see the execution ordering on the model: Format==>Block Displays ==> Sorted Order
The number value at the top-right corner is the ordering of the blocks.
SimulinkModel_CFunctionCall_Ordering.png
SimulinkModel_CFunctionCall_Ordering.png (19.56 KiB) Viewed 1912 times


I hope the explanation is correct ! I do not have full knowlege about simulink omtimization process yet...

Lubin

malife
Expert
Posts: 56
Joined: Tue Apr 17, 2007 7:24 am
Location: Santa Cruz, CA
Contact:

Re: Block Orderring fails for Blocks with infinite sample time

Postby malife » Thu Jan 22, 2009 2:58 am

Hello Lubin,
Thanks for such a quick response. This solution works like a charm.

Thanks!


Return to “Advanced Simulink & RTW Questions”

Who is online

Users browsing this forum: No registered users and 1 guest