Designing Your Model: Model-Code Correspondence : Fixed-Point Variable Support : Evaluating the wordSize and shift

Evaluating the wordSize and shift

The wordSize and shift of an object are defined by its design attributes (specified in the element properties). The MicroC Code Generator determines the wordSize and shift of expressions made of objects and operators by using the formulas listed in the macro definition table below.

The conventions used in the table are as follows:

WSThe wordSize of the object
SHThe shift of the object
RGThe range (wordSize shift)
MAX(A, B)A>B:A:B
SUM(A, B)A+B
SUB(A, B)AB:
 
wordSize and shift of the left operand
wordSize and shift of the left function
All other parameters WS = SUM(MAX(RG1, RG2), MAX(SH1,SH2)), SH=MAX(SH1, SH2)

If the evaluated wordSize is greater than 32 bits, MicroC displays the following messages:

generated code - /* Warning - Fixed- Point Overflow in Expression.*

This message is located right after the expression.

When you use fixed-point variables in integer arithmetic, the special functions (or C macros) provided in the FXP package are used to perform the calculations. The following table lists these macros

.
Converts a fixed-point number with shift=FPshift to an integer.
LS_FXP2FXP8 (FPvalue, fromFPshift, toFPshift) ((sint8(FPvalue)) <<((toFPshift) - (fromFPshift)))
Converts a fixed-point number with shift=fromFPshift to an 8-bit fixed-point number with shift=toFPshift using left shifting.
RS_FXP2FXP8 (FPvalue, fromFPshift,toFPshift) ((sint8(FPvalue)) >>((fromFPshift) - (toFPshift)))
Converts a fixed-point number with shift=fromFPshift to an 8-bit fixed-point number with shift=toFPshift using right shifting.
LS_FXP2FXP16 (FPvalue, fromFPshift,toFPshift) ((sint16(FPvalue)) <<((toFPshift) - (fromFPshift)))
Converts a fixed-point number with shift=fromFPshift to a 16-bit fixed-point number with shift=toFPshift by using left shifting.
RS_FXP2FXP16 (FPvalue, fromFPshift,toFPshift) ((sint16(FPvalue)) >>((fromFPshift) - (toFPshift)))
Converts a fixed-point number with shift=fromFPshift to a 16-bit fixed-point number with shift=toFPshift using right shifting.
LS_FXP2FXP32 (FPvalue, fromFPshift,toFPshift) ((sint32(FPvalue)) <<((toFPshift) - (fromFPshift)))
Converts a fixed-point number with shift=fromFPshift to a 32-bit fixed-point number with shift=toFPshift using left shifting.
RS_FXP2FXP32 (FPvalue, fromFPshift,toFPshift) ((sint32(FPvalue)) >>
((fromFPshift) - (toFPshift)))
Converts a fixed-point number with shift=fromFPshift to a 32-bit fixed-point number with shift=toFPshift using right shifting.