Example: Mixed Physical Implementation

The following screenshot shows a simple block diagram with three elements of type cont.

The Mixed_Physical_Implementation is created for the component, and the implementation data type sint16 is assigned to element c.

Code is generated for the PC target and the physical experiment, and displayed via the View Generated Code menu option in the Build menu. The following code extract shows the effects of the Mixed_Physical_Implementation.

...

/*----Local variables object structure----------------------------------------*/

struct M_BDE_Obj  {

ASDObjectHeader objectHeader;

real64_Obj *a;

real64_Obj *b;

sint16_Obj *c;

};

...

/******************************************************************************

* BEGIN: Generation Information

*-----------------------------------------------------------------------------

* Component:................Module

* Name:....................."M_bde"

* Implementation:..........."Mixed_Physical_Implementation"

* Dataset:.................."Data"

* Specification:............Block Diagram

...

* END: Generation Information

******************************************************************************/

/******************************************************************************

* BEGIN: Project Options "Build"/"Code"

*-----------------------------------------------------------------------------

*    Build

*-----------------------------------------------------------------------------

* Code Generator:...........Physical Experiment

* Target:...................PC

...

*-----------------------------------------------------------------------------

*    Code.FixedPoint

*-----------------------------------------------------------------------------

* Arithmetic Service Set [<None>]:.......................................<None>

* Generate Float Limiter on Assignment (may be changed locally) [false]: false

* Generate Round Operation on float to integer Assignment [true]:........true

* Maximum bit Length (int) [32]:.........................................32

* New Behaviour for Discrete Types [true]:...............................true

* Temp Vars always 32 bit (integer) [false]:.............................false

* Use power of 2 approximations of literals [false]:.....................false

* Use SHIFT Operation on Signed Values instead of DIV Operation [false]: false

...

* END: Project Options "Build"/"Code"

******************************************************************************/

...

/******************************************************************************

* BEGIN: Function definitions - Algorithms

*----------------------------------------------------------------------------*/

/* public process [] */

void M_BDE_process(void)

{

real64 _t1real64;

/* process: sequence call #5 */

_t1real64 = M_BDEinstance->a->val + M_BDEinstance->b->val;

_t1real64 = (_t1real64 < 0.0) ? (_t1real64 – 0.5) : (_t1real64 + 0.5);

/* assignment to c: min=-32768, max=32767, hex=phys, limit=(maxBitLength: true, assign: true), zero incl.=true */

M_BDEinstance->c->val = (_t1real64 >= -32768.0) ? ((_t1real64 <= 32767.0) ? (sint16)_t1real64 : 32767) : -32768;

}

...

/*-----------------------------------------------------------------------------

* Initialization with dataset "Data"

*----------------------------------------------------------------------------*/

struct M_BDE_Obj *initInstance_M_BDE_Data (void)

{

   if (M_BDEinstance == NULL) {

      CREATE_OBJECT (M_BDEinstance, M_BDE);

      M_BDEinstance->a = v3_initInstance_real64 (0.0, ASD_VARIABLE);

      M_BDEinstance->b = v3_initInstance_real64 (0.0, ASD_VARIABLE);

      M_BDEinstance->c = v3_initInstance_sint16 (0, ASD_VARIABLE);

   }

   return (M_BDEinstance);

}

...