Generated code with fixed-point variables, Fixed-point data types, Table 2-6. autocode/c data types – National Instruments AutoCode NI MATRIX User Manual

Page 45

Advertising
background image

Chapter 2

C Language Reference

AutoCode Reference

2-28

ni.com

language and replace the supplied macros (or functions) with your
(assembly) functions so that you can take full advantage of the processor’s
arithmetic capabilities.

Generated Code with Fixed-Point Variables

Code generated for models using fixed-point variables—such as the
examples provided in this chapter—will differ from code generated for
models using floating-point, integer, or logical signals in the following
areas:

Signal and variable type declarations will reflect fixed-point types.

Arithmetic operators

+

,

,

*

, and

/

will be replaced by fixed-point

arithmetic macro calls (or function calls based on the interface used).

Relational operators

>

,

>=

,

<

,

<=

,

==

, and

!=

will, when necessary, be

replaced by fixed-point relational macro calls.

Floating-point literals used in SystemBuild models will be replaced by
the scaled integer counterpart.

Macros (or procedures) for converting between various fixed-point
types will be invoked when necessary.

Fixed-Point Data Types

Fixed-point type definitions are provided in the system-specific files

src

directory. Files

sa_types.h

,

sa_defn.h

,

sa_fxscale.h

, and

sa_fxlimit.h

use

typedef

statements to represent fixed-point types

and related constants for 8-bit, 16-bit, and 32-bit data. All fixed-point types
have an associated radix position value and a sign (signed or unsigned).
The radix position value is clearly related to the data type scale factor
scale factor = 2

–(radix position)

. To perform any arithmetic operation, both the

value and the radix position scalar are required. The table below lists the
data types generated by AutoCode/C. For information on ranges and
accuracy of each type, refer to the SystemBuild User Guide.

Table 2-6. AutoCode/C Data Types

Data
Type

Number

of Bits

Signed or

Unsigned

Data Type Name

byte

8

unsigned

RT_UBYTE

(radix 00)

RT_UBYTExx (xx = radix 48 to –16)

signed

RT_SBYTE

(radix 00)

RT_SBYTExx (xx = radix 48 to –16)

Advertising