Page 1 of 1

Sample time C-function Call

Posted: Thu Sep 10, 2009 2:48 am
by catia
Hi Lubin,

I currently use the C function call blockset as initialization, I would like to know what i have to put for the sample time for this blockset to be called only once. I have tried with 'inf' but it seems to call this blockset at every cycle.

Cathia

Re: Sample time C-function Call

Posted: Thu Sep 10, 2009 10:51 am
by LubinKerhuel
Hi Cathia,

C function call is only working on registred version of the blockset.
Thus, check that you have a registred version (are you working in ASU team that use a registred version ?)
Else, you may be using the blockset build (or copied !) by Microchip.

Anyway, inf time should activate the block only once at initialization. Else, you could use a triggered subsystem and place the c call function block inside this subsystem. (There are few examples like that on the forum).

It may help to get the mdl file. Could you post it ?

Lubin

Re: Sample time C-function Call

Posted: Thu Sep 10, 2009 11:24 pm
by catia
Hi Lubin,

I am working in an ASU laboratory. So i must have the right version. Maybe i made a mistaske somewhere else, that would be why i have the impression to initialize at every cycle.

Cathia

Re: Sample time C-function Call

Posted: Fri Sep 11, 2009 8:23 am
by LubinKerhuel
Hi Cathia,

Could not compile to test (no c files attached).
However, you could try this :

in Simulation ==> Configuration Parameters ==> Optimization (left) ==> Check box Inline parameters.

Tips : You may have a better view of what's happening with : Format ==> Sample Time Display ==> Color
(update then the diagram, with or without the Optimization checked).

This should works fine, however, if you prefere, you might use triggered subsystem with a step or so on... (browse the forum for examples)

Let me know...

another Tip : Simulink has binary shift blocks and you should rather use them instead of the Embedded MATLAB Function (which probably makes theses calculation with double data type ? this should be checked )

If you are working on the ECAN peripheral (as your model's name suggest), it may be very useful to post results provided you have the rights to do so...

Lubin

Re: Sample time C-function Call

Posted: Fri Jan 21, 2011 6:10 pm
by coolj
Hi Lubin,

I had a similar issue with version 3.4b of your blockset. My inf time functions that were supposed to run only once were being called every time step.

Once I enabled Simulation -> Configuration -> Optimization -> Inline parameters, the inf-time initialization C functions were correctly called only once.

Might want to add to the documentation, along with "inf" allowing for "run once".

Re: Sample time C-function Call

Posted: Mon Jan 24, 2011 3:34 am
by coolj
Here is some background for inline parameters needing to be enabled to prevent inf-time functions from being called every time step.

http://www.kxcad.net/cae_MATLAB/toolbox ... -9753.html

inf

The meaning of this sample time depends on whether the active model configuration's inline parameters optimization (see Inline parameters) is enabled.

If the inline parameters optimization is enabled, inf signifies that the block's output can never change (see Constant Sample Time). This speeds up simulation and the generated code by eliminating the need to recompute the block's output at each time step. If the inline parameters optimization is disabled or the block with inf sample time drives an output port of a conditionally executed subsystem, Simulink treats inf as -1, i.e., as inherited sample time. This allows you to tune the block's parameters during simulation.

Re: Sample time C-function Call

Posted: Sat Mar 05, 2011 7:07 am
by jannypan
Anyway, inf time should activate the block only once at initialization. Else, you could use a triggered subsystem and place the c call function block inside this subsystem. (There are few examples like that on the forum).