This user's guide describes the General Functions Library (GFLIB) for the family of
ARM Cortex M7F core-based microcontrollers. This library contains optimized
functions.
1.1.2
GFLIB supports several data types: (un)signed integer, fractional, and accumulator, and
floating point. The integer data types are useful for general-purpose computation; they
are familiar to the MPU and MCU programmers. The fractional data types enable
powerful numeric and digital-signal-processing algorithms to be implemented. The
accumulator data type is a combination of both; that means it has the integer and
fractional portions.The floating-point data types are capable of storing real numbers in
wide dynamic ranges. The type is represented by binary digits and an exponent. The
exponent allows scaling the numbers from extremely small to extremely big numbers.
Because the exponent takes part of the type, the overall resolution of the number is
reduced when compared to the fixed-point type of the same size.
The following list shows the integer types defined in the libraries:
• Unsigned 16-bit integer —<0 ; 65535> with the minimum resolution of 1
• Signed 16-bit integer —<-32768 ; 32767> with the minimum resolution of 1
• Unsigned 32-bit integer —<0 ; 4294967295> with the minimum resolution of 1
• Signed 32-bit integer —<-2147483648 ; 2147483647> with the minimum resolution
Data types
of 1
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors5
Introduction
• Unsigned 64-bit integer —<0 ; 18446744073709551615> with the minimum
resolution of 1
• Signed 64-bit integer —<-9223372036854775808 ; 9223372036854775807> with
the minimum resolution of 1
The following list shows the fractional types defined in the libraries:
• Fixed-point 16-bit fractional —<-1 ; 1 - 2
• Fixed-point 32-bit fractional —<-1 ; 1 - 2
-15
> with the minimum resolution of 2
-31
> with the minimum resolution of 2
-15
-31
The following list shows the accumulator types defined in the libraries:
• Fixed-point 16-bit accumulator —<-256.0 ; 256.0 - 2-7> with the minimum
resolution of 2
The following list shows the floating-point types defined in the libraries:
• Floating point 32-bit single precision —<-3.40282 · 1038 ; 3.40282 · 1038> with the
minimum resolution of 2
1.1.3
API definition
-23
GFLIB uses the types mentioned in the previous section. To enable simple usage of the
algorithms, their names use set prefixes and postfixes to distinguish the functions'
versions. See the following example:
• lss—the types of the function inputs; if all the inputs have the same type as the
output, the inputs are not marked
The input and output types are described in the following table:
Table 1-1. Input/output types
TypeOutputInput
frac16_tF16s
Table continues on the next page...
GFLIB User's Guide, Rev. 4, 12/2020
6NXP Semiconductors
Chapter 1 Library
Table 1-1. Input/output types (continued)
TypeOutputInput
frac32_tF32l
acc32_tA32a
float_tFLTf
1.1.4Supported compilers
GFLIB for the ARM Cortex M7F core is written in C language or assembly language
with C-callable interface depending on the specific function. The library is built and
tested using the following compilers:
• MCUXpresso IDE
• IAR Embedded Workbench
• Keil µVision
For the MCUXpresso IDE, the library is delivered in the gflib.a file.
For the Kinetis Design Studio, the library is delivered in the gflib.a file.
For the IAR Embedded Workbench, the library is delivered in the gflib.a file.
For the Keil µVision, the library is delivered in the gflib.lib file.
The interfaces to the algorithms included in this library are combined into a single public
interface include file, gflib.h. This is done to lower the number of files required to be
included in your application.
1.1.5
Library configuration
GFLIB for the ARM Cortex M7F core is written in C language or assembly language
with C-callable interface depending on the specific function. Some functions from this
library are inline type, which are compiled together with project using this library. The
optimization level for inline function is usually defined by the specific compiler setting. It
can cause an issue especially when high optimization level is set. Therefore the
optimization level for all inline assembly written functions is defined by compiler
pragmas using macros. The configuration header file RTCESL_cfg.h is located in:
specific library folder\MLIB\Include. The optimization level can be changed by
modifying the macro value for specific compiler. In case of any change the library
functionality is not guaranteed.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors7
Library integration into project (MCUXpresso IDE)
Similarly as optimization level the High-speed functions execution suppport can be
enable by defined symbol RAM_OPTIM_LOW (RAM_OPTIM_MEDIUM or
RAM_OPTIM_HIGH) or disable by not defining any of these macrors. symbol
RTCESL_MMDVSQ_OFF in project setting described in the High-speed functions
execution suppport cheaper for specific compiler.
1.1.6Special issues
1. The equations describing the algorithms are symbolic. If there is positive 1, the
number is the closest number to 1 that the resolution of the used fractional type
allows. If there are maximum or minimum values mentioned, check the range
allowed by the type of the particular function version.
2. The library functions that round the result (the API contains Rnd) round to nearest
(half up).
1.2
Library integration into project (MCUXpresso IDE)
This section provides a step-by-step guide on how to quickly and easily include GFLIB
into any MCUXpresso SDK example or demo application projects using MCUXpresso
IDE. This example uses the default installation path (C:\NXP\RTCESL
\CM7F_RTCESL_4.6_MCUX). If you have a different installation path, use that path
instead.
1.2.1
High-speed functions execution suppport
Some RT (or other) platforms contain high-speed functions execution support by
relocating all functions from the default Flash memory location to the RAM location for
much faster code access. The feature is important especially for devices with a slow Flash
interface. This section shows how to turn the RAM optimization feature support on and
off.
1. In the MCUXpresso SDK project name node or on the left-hand side, click Properties
or select Project > Properties from the menu. A project properties dialog appears.
2. Expand the C/C++ Build node and select Settings. See Figure 1-1.
3. On the right-hand side, under the MCU C Compiler node, click the Preprocessor
node. See Figure 1-1.
GFLIB User's Guide, Rev. 4, 12/2020
8NXP Semiconductors
Chapter 1 Library
Figure 1-1. Defined symbols
4. On the right-hand side of the dialog, click the Add... icon located next to the Defined
symbols (-D) title.
5. In the dialog that appears (see Figure 1-2), type the following:
• RAM_RELOCATION — to turn the RAM optimization feature support on
If the define is defined, all RTCEL functions are put to the RAM.
Figure 1-2. Symbol definition
6. Click OK in the dialog.
7. Click OK in the main dialog.
The device reference manual shows how the__RAMFUNC(RAM) atribute works in connection
with your device.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors9
Library integration into project (MCUXpresso IDE)
1.2.2Library path variable
To make the library integration easier, create a variable that holds the information about
the library path.
1. Right-click the MCUXpresso SDK project name node in the left-hand part and click
Properties, or select Project > Properties from the menu. A project properties dialog
appears.
2. Expand the Resource node and click Linked Resources. See Figure 1-3.
Figure 1-3. Project properties
3. Click the New… button in the right-hand side.
4. In the dialog that appears (see Figure 1-4), type this variable name into the Name
box: RTCESL_LOC.
5. Select the library parent folder by clicking Folder…, or just type the following path
into the Location box: C:\NXP\RTCESL\CM7F_RTCESL_4.6_MCUX. Click OK.
GFLIB User's Guide, Rev. 4, 12/2020
10NXP Semiconductors
Chapter 1 Library
Figure 1-4. New variable
6. Create such variable for the environment. Expand the C/C++ Build node and click
Environment.
7. Click the Add… button in the right-hand side.
8. In the dialog that appears (see Figure 1-5), type this variable name into the Name
box: RTCESL_LOC.
9. Type the library parent folder path into the Value box: C:\NXP\RTCESL
\CM7F_RTCESL_4.6_MCUX.
10. Tick the Add to all configurations box to use this variable in all configurations. See
Figure 1-5.
11. Click OK.
12. In the previous dialog, click OK.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors11
Library integration into project (MCUXpresso IDE)
Figure 1-5. Environment variable
1.2.3
Library folder addition
To use the library, add it into the Project tree dialog.
1. Right-click the MCUXpresso SDK project name node in the left-hand part and click
New > Folder, or select File > New > Folder from the menu. A dialog appears.
2. Click Advanced to show the advanced options.
3. To link the library source, select the Link to alternate location (Linked Folder)
option.
4. Click Variables..., select the RTCESL_LOC variable in the dialog, click OK, and/or
type the variable name into the box. See Figure 1-6.
5. Click Finish, and the library folder is linked in the project. See Figure 1-7.
GFLIB User's Guide, Rev. 4, 12/2020
12NXP Semiconductors
Chapter 1 Library
Figure 1-6. Folder link
Figure 1-7. Projects libraries paths
1.2.4
Library path setup
GFLIB requires MLIB to be included too. These steps show how to include all dependent
modules:
1. Right-click the MCUXpresso SDK project name node in the left-hand part and click
Properties, or select Project > Properties from the menu. The project properties
dialog appears.
2. Expand the C/C++ General node, and click Paths and Symbols.
3. In the right-hand dialog, select the Library Paths tab. See Figure 1-9.
4. Click the Add… button on the right, and a dialog appears.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors13
Library integration into project (MCUXpresso IDE)
5. Look for the RTCESL_LOC variable by clicking Variables…, and then finish the
path in the box by adding the following (see Figure 1-8): ${RTCESL_LOC}\MLIB.
6. Click OK, and then click the Add… button.
7. Look for the RTCESL_LOC variable by clicking Variables…, and then finish the
path in the box by adding the following: ${RTCESL_LOC}\GFLIB.
8. Click OK, you will see the paths added into the list. See Figure 1-9.
Figure 1-8. Library path inclusion
Figure 1-9. Library paths
9. After adding the library paths, add the library files. Click the Libraries tab. See
Figure 1-11.
10. Click the Add… button on the right, and a dialog appears.
11. Type the following into the File text box (see Figure 1-10): :mlib.a
12. Click OK, and then click the Add… button.
13. Type the following into the File text box: :gflib.a
14. Click OK, and you will see the libraries added in the list. See Figure 1-11.
GFLIB User's Guide, Rev. 4, 12/2020
14NXP Semiconductors
Chapter 1 Library
Figure 1-10. Library file inclusion
Figure 1-11. Libraries
15. In the right-hand dialog, select the Includes tab, and click GNU C in the Languages
list. See Figure 1-13.
16. Click the Add… button on the right, and a dialog appears. See Figure 1-12.
17. Look for the RTCESL_LOC variable by clicking Variables…, and then finish the
path in the box to be: ${RTCESL_LOC}\MLIB\Include
18. Click OK, and then click the Add… button.
19. Look for the RTCESL_LOC variable by clicking Variables…, and then finish the
path in the box to be: ${RTCESL_LOC}\GFLIB\Include
20. Click OK, and you will see the paths added in the list. See Figure 1-13. Click OK.
Figure 1-12. Library include path addition
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors15
Library integration into project (Keil µVision)
Figure 1-13. Compiler setting
Type the #include syntax into the code where you want to call the library functions. In
the left-hand dialog, open the required .c file. After the file opens, include the following
lines into the #include section:
#include "mlib_FP.h"
#include "gflib_FP.h"
When you click the Build icon (hammer), the project is compiled without errors.
1.3
Library integration into project (Keil µVision)
This section provides a step-by-step guide on how to quickly and easily include GFLIB
into an empty project or any MCUXpresso SDK example or demo application projects
using Keil µVision. This example uses the default installation path (C:\NXP\RTCESL
\CM7F_RTCESL_4.6_KEIL). If you have a different installation path, use that path
instead. If any MCUXpresso SDK project is intended to use (for example hello_world
project) go to Linking the files into the project chapter otherwise read next chapter.
GFLIB User's Guide, Rev. 4, 12/2020
16NXP Semiconductors
Chapter 1 Library
1.3.1NXP pack installation for new project (without MCUXpresso
SDK)
This example uses the NXP MKV58F1M0xxx22 part, and the default installation path
(C:\NXP\RTCESL\CM7F_RTCESL_4.6_KEIL) is supposed. If the compiler has never
been used to create any NXP MCU-based projects before, check whether the NXP MCU
pack for the particular device is installed. Follow these steps:
1. Launch Keil µVision.
2. In the main menu, go to Project > Manage > Pack Installer….
3. In the left-hand dialog (under the Devices tab), expand the All Devices > Freescale
(NXP) node.
4. Look for a line called "KVxx Series" and click it.
5. In the right-hand dialog (under the Packs tab), expand the Device Specific node.
6. Look for a node called "Keil::Kinetis_KVxx_DFP." If there are the Install or Update
options, click the button to install/update the package. See Figure 1-14.
7. When installed, the button has the "Up to date" title. Now close the Pack Installer.
Figure 1-14. Pack Installer
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors17
Library integration into project (Keil µVision)
1.3.2New project (without MCUXpresso SDK)
To start working on an application, create a new project. If the project already exists and
is opened, skip to the next section. Follow these steps to create a new project:
1. Launch Keil µVision.
2. In the main menu, select Project > New µVision Project…, and the Create New
Project dialog appears.
3. Navigate to the folder where you want to create the project, for example C:
\KeilProjects\MyProject01. Type the name of the project, for example MyProject01.
Click Save. See Figure 1-15.
Figure 1-15. Create New Project dialog
4. In the next dialog, select the Software Packs in the very first box.
5. Type '' into the Search box, so that the device list is reduced to the devices.
6. Expand the node.
7. Click the MKV58F1M0xxx22 node, and then click OK. See Figure 1-16.
Figure 1-16. Select Device dialog
8. In the next dialog, expand the Device node, and tick the box next to the Startup node.
See Figure 1-17.
GFLIB User's Guide, Rev. 4, 12/2020
18NXP Semiconductors
9. Expand the CMSIS node, and tick the box next to the CORE node.
Chapter 1 Library
Figure 1-17. Manage Run-Time Environment dialog
10. Click OK, and a new project is created. The new project is now visible in the lefthand part of Keil µVision. See Figure 1-18.
Figure 1-18. Project
11. In the main menu, go to Project > Options for Target 'Target1'…, and a dialog
appears.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors19
Library integration into project (Keil µVision)
12. Select the Target tab.
13. Select Use Single Precision in the Floating Point Hardware option. See Figure 1-18.
Figure 1-19. FPU
1.3.3
High-speed functions execution support
Some RT (or other) platforms contain high-speed functions execution support by
relocating all functions from the default Flash memory location to the RAM location for
much faster code access. The feature is important especially for devices with a slow Flash
interface. This section shows how to turn the RAM optimization feature support on and
off.
1. In the main menu, go to Project > Options for Target 'Target1'…, and a dialog
appears.
2. Select the C/C++ tab. See .
3. In the Include Preprocessor Symbols text box, type the following:
• RAM_RELOCATION — to turn the RAM optimization feature support on
If the define is defined, all RTCEL functions are put to the RAM.
GFLIB User's Guide, Rev. 4, 12/2020
20NXP Semiconductors
Figure 1-20. Preprocessor symbols
4. Click OK in the main dialog.
Chapter 1 Library
The device reference manual shows how the__attribute__ ((section ("ram"))) atribute
works in connection with your device.
1.3.4
Linking the files into the project
GFLIB requires MLIB to be included too. The following steps show how to include all
dependent modules.
To include the library files in the project, create groups and add them.
1. Right-click the Target 1 node in the left-hand part of the Project tree, and select Add
Group… from the menu. A new group with the name New Group is added.
2. Click the newly created group, and press F2 to rename it to RTCESL.
3. Right-click the RTCESL node, and select Add Existing Files to Group 'RTCESL'…
from the menu.
4. Navigate into the library installation folder C:\NXP\RTCESL
\CM7F_RTCESL_4.6_KEIL\MLIB\Include, and select the mlib_FP.h file. If the file
does not appear, set the Files of type filter to Text file. Click Add. See Figure 1-21.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors21
Library integration into project (Keil µVision)
Figure 1-21. Adding .h files dialog
5. Navigate to the parent folder C:\NXP\RTCESL\CM7F_RTCESL_4.6_KEIL\MLIB,
and select the mlib.lib file. If the file does not appear, set the Files of type filter to
Library file. Click Add. See Figure 1-22.
Figure 1-22. Adding .lib files dialog
6. Navigate into the library installation folder C:\NXP\RTCESL
\CM7F_RTCESL_4.6_KEIL\GFLIB\Include, and select the gflib_FP.h file. If the
file does not appear, set the Files of type filter to Text file. Click Add.
7. Navigate to the parent folder C:\NXP\RTCESL\CM7F_RTCESL_4.6_KEIL\GFLIB,
and select the gflib.lib file. If the file does not appear, set the Files of type filter to
Library file. Click Add.
8. Now, all necessary files are in the project tree; see Figure 1-23. Click Close.
GFLIB User's Guide, Rev. 4, 12/2020
22NXP Semiconductors
Figure 1-23. Project workspace
Chapter 1 Library
1.3.5
Library path setup
The following steps show the inclusion of all dependent modules.
1. In the main menu, go to Project > Options for Target 'Target1'…, and a dialog
appears.
2. Select the C/C++ tab. See Figure 1-24.
3. In the Include Paths text box, type the following paths (if there are more paths, they
must be separated by ';') or add them by clicking the … button next to the text box:
Type the #include syntax into the code. Include the library into a source file. In the new
project, it is necessary to create a source file:
1. Right-click the Source Group 1 node, and Add New Item to Group 'Source Group
1'… from the menu.
2.
Select the C File (.c) option, and type a name of the file into the Name box, for
example 'main.c'. See Figure 1-25.
GFLIB User's Guide, Rev. 4, 12/2020
24NXP Semiconductors
Chapter 1 Library
Figure 1-25. Adding new source file dialog
3. Click Add, and a new source file is created and opened up.
4. In the opened source file, include the following lines into the #include section, and
create a main function:
#include "mlib_FP.h"
#include "gflib_FP.h"
int main(void)
{
while(1);
}
When you click the Build (F7) icon, the project will be compiled without errors.
1.4
Library integration into project (IAR Embedded
Workbench)
This section provides a step-by-step guide on how to quickly and easily include the
GFLIB into an empty project or any MCUXpresso SDK example or demo application
projects using IAR Embedded Workbench. This example uses the default installation
path (C:\NXP\RTCESL\CM7F_RTCESL_4.6_IAR). If you have a different installation
path, use that path instead. If any MCUXpresso SDK project is intended to use (for
example hello_world project) go to Linking the files into the project chapter otherwise
read next chapter.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors25
Library integration into project (IAR Embedded Workbench)
1.4.1New project (without MCUXpresso SDK)
This example uses the NXP MKV58F1M0xxx22 part, and the default installation path
(C:\NXP\RTCESL\CM7F_RTCESL_4.6_IAR) is supposed. To start working on an
application, create a new project. If the project already exists and is opened, skip to the
next section. Perform these steps to create a new project:
1. Launch IAR Embedded Workbench.
2. In the main menu, select Project > Create New Project… so that the "Create New
Project" dialog appears. See Figure 1-26.
Figure 1-26. Create New Project dialog
3. Expand the C node in the tree, and select the "main" node. Click OK.
4. Navigate to the folder where you want to create the project, for example, C:
\IARProjects\MyProject01. Type the name of the project, for example, MyProject01.
Click Save, and a new project is created. The new project is now visible in the lefthand part of IAR Embedded Workbench. See Figure 1-27.
GFLIB User's Guide, Rev. 4, 12/2020
26NXP Semiconductors
Chapter 1 Library
Figure 1-27. New project
5. In the main menu, go to Project > Options…, and a dialog appears.
6. In the Target tab, select the Device option, and click the button next to the dialog to
select the MCU. In this example, select NXP > KV5x > NXP MKV58F1M0xxx22.
Select VFPv5 single precision in the FPU option. Click OK. See Figure 1-28.
Figure 1-28. Options dialog
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors27
Library integration into project (IAR Embedded Workbench)
1.4.2High-speed functions execution suppport
Some RT (or other) platforms contain high-speed functions execution support by
relocating all functions from the default Flash memory location to the RAM location for
much faster code access. The feature is important especially for devices with a slow Flash
interface. This section shows how to turn the RAM optimization feature support on and
off.
1. In the main menu, go to Project > Options…, and a dialog appears.
2. In the left-hand side column, select C/C++ Compiler.
3. In the right-hand side of the dialog, click the Preprocessor tab (it can be hidden on
the right; use the arrow icons for navigation).
4. In the text box (in Defined symbols: (one per line)), type the following (See Figure
1-29):
• RAM_RELOCATION — to turn the RAM optimization feature support on
If the define is defined, all RTCEL functions are put to the RAM.
Figure 1-29. Defined symbols
5. Click OK in the main dialog.
The device reference manual shows how the __ramfunc atribute works in connection with
your device.
GFLIB User's Guide, Rev. 4, 12/2020
28NXP Semiconductors
Chapter 1 Library
1.4.3Library path variable
To make the library integration easier, create a variable that will hold the information
about the library path.
1. In the main menu, go to Tools > Configure Custom Argument Variables…, and a
dialog appears.
2. Click the New Group button, and another dialog appears. In this dialog, type the
name of the group PATH, and click OK. See Figure 1-30.
Figure 1-30. New Group
3. Click on the newly created group, and click the Add Variable button. A dialog
appears.
4. Type this name: RTCESL_LOC
5. To set up the value, look for the library by clicking the '…' button, or just type the
installation path into the box: C:\NXP\RTCESL\CM7F_RTCESL_4.6_IAR. Click
OK.
6. In the main dialog, click OK. See Figure 1-31.
Figure 1-31. New variable
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors29
Library integration into project (IAR Embedded Workbench)
1.4.4Linking the files into the project
GFLIB requires MLIB to be included too. The following steps show the inclusion of all
dependent modules.
To include the library files into the project, create groups and add them.
1. Go to the main menu Project > Add Group…
2. Type RTCESL, and click OK.
3. Click on the newly created node RTCESL, go to Project > Add Group…, and create
a MLIB subgroup.
4. Click on the newly created node MLIB, and go to the main menu Project > Add
Files… See Figure 1-33.
5. Navigate into the library installation folder C:\NXP\RTCESL
\CM7F_RTCESL_4.6_IAR\MLIB\Include, and select the mlib_FP.h file. (If the file
does not appear, set the file-type filter to Source Files.) Click Open. See Figure 1-32.
6. Navigate into the library installation folder C:\NXP\RTCESL
\CM7F_RTCESL_4.6_IAR\MLIB, and select the mlib.a file. If the file does not
appear, set the file-type filter to Library / Object files. Click Open.
Figure 1-32. Add Files dialog
7. Click on the RTCESL node, go to Project > Add Group…, and create a GFLIB
subgroup.
8. Click on the newly created node GFLIB, and go to the main menu Project > Add
Files….
9. Navigate into the library installation folder C:\NXP\RTCESL
\CM7F_RTCESL_4.6_IAR\GFLIB\Include, and select the gflib_FP.h file. (If the file
does not appear, set the file-type filter to Source Files.) Click Open.
10. Navigate into the library installation folder C:\NXP\RTCESL
\CM7F_RTCESL_4.6_IAR\GFLIB, and select the gflib.a file. If the file does not
appear, set the file-type filter to Library / Object files. Click Open.
11. Now you will see the files added in the workspace. See Figure 1-33.
GFLIB User's Guide, Rev. 4, 12/2020
30NXP Semiconductors
Figure 1-33. Project workspace
Chapter 1 Library
1.4.5
Library path setup
The following steps show the inclusion of all dependent modules:
1. In the main menu, go to Project > Options…, and a dialog appears.
2. In the left-hand column, select C/C++ Compiler.
3. In the right-hand part of the dialog, click on the Preprocessor tab (it can be hidden in
the right; use the arrow icons for navigation).
4. In the text box (at the Additional include directories title), type the following folder
(using the created variable):
• $RTCESL_LOC$\MLIB\Include
• $RTCESL_LOC$\GFLIB\Include
5. Click OK in the main dialog. See Figure 1-34.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors31
Library integration into project (IAR Embedded Workbench)
Figure 1-34. Library path adition
Type the #include syntax into the code. Include the library included into the main.c file.
In the workspace tree, double-click the main.c file. After the main.c file opens up, include
the following lines into the #include section:
#include "mlib_FP.h"
#include "gflib_FP.h"
When you click the Make icon, the project will be compiled without errors.
GFLIB User's Guide, Rev. 4, 12/2020
32NXP Semiconductors
Chapter 2
Algorithms in detail
2.1GFLIB_Sin
The
GFLIB_Sin function implements the polynomial approximation of the sine function.
It provides a computational method for the calculation of a standard trigonometric sine
function sin(x), using the 9th order Taylor polynomial approximation. The Taylor
polynomial approximation of a sine function is expressed as follows:
Equation 1.
Equation 2.
where the constants are:
The fractional arithmetic is limited to the range <-1 ; 1), so the input argument can only
be within this range. The input argument is the multiplier of π: sin(π · x), where the user
passes the x argument. Example: if the input is -0.5, it corresponds to -0.5π.
The fractional function sin(π · x) is expressed using the 9th order Taylor polynomial as
follows:
Equation 3.
where:
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors33
GFLIB_Sin
2.1.1Available versions
The function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
• Floating-point output - the output is the floating-point result within the range <-1.0 ;
1.0>.
• Floating-point output with accumulator input - the output is the floating-point result
within the range <-1.0 ; 1.0>. The input is the accumulator angle in radians divided
by π.
The available versions of the GFLIB_Sin function are shown in the following table:
Table 2-1. Function versions
Function nameInput typeResult typeDescription
GFLIB_Sin_F16frac16_tfrac16_tCalculation of the sin(π · x), where the input argument is a 16-bit fractional
value normalized to the range <-1 ; 1) that represents an angle in radians
within the range <-π; π). The output is a 16-bit fractional value within the
range <-1 ; 1).
GFLIB_Sin_FLTfloat_tfloat_tCalculation of the sin(x), where the input argument is a 32-bit single
precision floating-point value in radians within the range <-π; π). The output
is a 32-bit single precision floating-point value within the range <-1.0 ; 1.0>.
GFLIB_Sin_FLTaacc32_tfloat_tCalculation of the sin(π · x), where the input argument is a 32-bit
accumulator value where the fractional part <-1 ; 1) represents the angle
within the range <-π; π). The output is a 32-bit single precision floatingpoint value within the range <-1.0 ; 1.0>.
2.1.2Declaration
The available GFLIB_Sin functions have the following declarations:
The GFLIB_Cos function implements the polynomial approximation of the cosine
function. This function computes the cos(x) using the ninth-order Taylor polynomial
approximation of the sine function, and its equation is as follows:
Equation 4.
Because the fractional arithmetic is limited to the range <-1 ; 1), the input argument can
only be within this range. The input argument is the multiplier of π: cos(π · x), where the
user passes the x argument. For example, if the input is -0.5, it corresponds to -0.5π.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors35
GFLIB_Cos
2.2.1Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
• Floating-point output - the output is the floating-point result within the range <-1.0 ;
1.0>.
• Floating-point output with accumulator input - the output is the floating-point result
within the range <-1.0 ; 1.0>. The input is the accumulator angle in radians divided
by π.
The available versions of the GFLIB_Cos function are shown in the following table:
Table 2-2. Function versions
Function nameInput typeResult typeDescription
GFLIB_Cos_F16frac16_tfrac16_tCalculation of cos(π · x), where the input argument is a 16-bit fractional
value, normalized to the range <-1 ; 1) that represents an angle in radians
within the range <- π; π). The output is a 16-bit fractional value within the
range <-1 ; 1).
GFLIB_Cos_FLTfloat_tfloat_tCalculation of cos(x), where the input argument is a 32-bit single precision
floating-point value in radians within the range <-π; π). The output is a 32bit single precision floating-point value within the range <-1.0 ; 1.0>.
GFLIB_Cos_FLTaacc32_tfloat_tCalculation of the cos(π · x), where the input argument is a 32-bit
accumulator value where the fractional part <-1 ; 1) represents the angle
within the range <-π; π). The output is a 32-bit single precision floatingpoint value within the range <-1.0 ; 1.0>.
2.2.2Declaration
The available GFLIB_Cos functions have the following declarations:
The GFLIB_Tan function provides a computational method for calculation of a standard
trigonometric tangent function tan(x), using the piece-wise polynomial approximation.
Function tan(x) takes an angle and returns the ratio of two sides of a right-angled triangle.
The ratio is the length of the side opposite the angle divided by the length of the side
adjacent to the angle.
Equation 5.
Because both sin(x) and cos(x) are defined in interval <-π ; π>, the function tan(x) is
equal to zero when sin(x)=0 and is equal to infinity when cos(x)=0. The graph of tan(x) is
shown in the following figure:
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors37
GFLIB_Tan
Figure 2-1. Course of the function GFLIB_Tan
The fractional arithmetic is limited to the range <-1 ; 1) so the input argument can only be
within this range. The input argument is the multiplier of π: tan(π · x) where you pass the
x argument. Example: if the input is -0.5, it corresponds to -0.5π. The output of the
function is limited to the range <-1 ; 1) for the fractional arithmetic. For the points where
the function is not defined, the output is fractional -1.
2.3.1
Available versions
The function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
• Floating-point output - the output is the floating-point result.
• Floating-point output with accumulator input - the output is the floating-point result.
The input is the accumulator angle in radians divided by π.
The available versions of the GFLIB_Tan function are shown in the following table:
Table 2-3. Function versions
Function nameInput typeResult typeDescription
GFLIB_Tan_F16frac16_tfrac16_tCalculation of the tan(π · x) where the input argument is a 16-bit fractional
value normalized to the range <-1 ; 1) that represents an angle in radians
within the range <-π ; π). The output is a 16-bit fractional value within the
range <-1 ; 1).
Table continues on the next page...
GFLIB User's Guide, Rev. 4, 12/2020
38NXP Semiconductors
Chapter 2 Algorithms in detail
Table 2-3. Function versions (continued)
Function nameInput typeResult typeDescription
GFLIB_Tan_FLTfloat_tfloat_tCalculation of the tan(x) where the input argument is a 32-bit single
precision floating-point value in radians within the range <-π ; π). The
output is a 32-bit single precision floating-point value within the full range.
GFLIB_Tan_FLTaacc32_tfloat_tCalculation of the tan(π · x), where the input argument is a 32-bit
accumulator value where the fractional part <-1 ; 1) represents the angle
within the range <-π ; π). The output is a 32-bit single precision floatingpoint value within the full range.
2.3.2Declaration
The available GFLIB_Tan functions have the following declarations:
The GFLIB_Asin function provides a computational method for calculation of a standard
inverse trigonometric arcsine function arcsin(x), using the piece-wise polynomial
approximation. Function arcsin(x) takes the ratio of the length of the opposite side to the
length of the hypotenuse and returns the angle.
Figure 2-2. Course of the function GFLIB_Asin
The fractional arithmetic is limited by the range <-1;1) so the output can only be within
this range. This range corresponds to the angle <-1;1). Example: if the output is -0.5 it
corresponds to -0.5π.
2.4.1
Available versions
The function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1;1). The result may saturate.
• Floating point output - the output is the floating point result within the range <-π;π>.
GFLIB User's Guide, Rev. 4, 12/2020
40NXP Semiconductors
Chapter 2 Algorithms in detail
The available versions of the GFLIB_Asin function are shown in the following table:
Table 2-4. Function versions
Function nameInput typeResult typeDescription
GFLIB_Asin_F16frac16_tfrac16_tCalculation of the arcsin(x) / π where the input argument is a 16-bit
fractional within the range <-1;1). The output is a 16-bit fractional value
within the range <-1;1) that represents an angle in radians within the range
<-π;π).
GFLIB_Asin_FLTfloat_tfloat_tCalculation of the arcsin(x) where the input argument is a 32-bit single
precision floating point value within the range <-1;1>. The output is a 32-bit
single precision floating point value within the range <-π;π>.
2.4.2Declaration
The available GFLIB_Asin functions have the following declarations:
The GFLIB_Acos function provides a computational method for calculation of a standard
inverse trigonometric arccosine function arccos(x), using the piece-wise polynomial
approximation. Function arccos(x) takes the ratio of the length of the adjacent side to the
length of the hypotenuse and returns the angle.
Figure 2-3. Course of the function GFLIB_Acos
The fractional arithmetic is limited by the range <-1;1) so the output can only be within
this range. This range corresponds to the angle <-1;1). Example: if the output is -0.5 it
corresponds to -0.5π.
2.5.1
Available versions
The function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1;1). The result may saturate.
• Floating point output - the output is the floating point result within the range <-π;π>.
GFLIB User's Guide, Rev. 4, 12/2020
42NXP Semiconductors
Chapter 2 Algorithms in detail
The available versions of the GFLIB_Acos function are shown in the following table:
Table 2-5. Function versions
Function nameInput typeResult typeDescription
GFLIB_Acos_F16frac16_tfrac16_tCalculation of the arccos(x) / π where the input argument is a 16-bit
fractional within the range <-1;1). The output is a 16-bit fractional value
within the range <-1;1) that represents an angle in radians within the range
<-π;π).
GFLIB_Acos_FLTfloat_tfloat_tCalculation of the arccos(x) where the input argument is a 32-bit single
precision floating point value within the range <-1;1>. The output is a 32-bit
single precision floating point value within the range <-π;π>.
2.5.2Declaration
The available GFLIB_Acos functions have the following declarations:
The GFLIB_Atan function implements the polynomial approximation of the arctangent
function. It provides a computational method for calculating the standard trigonometric
arctangent function arctan(x), using the piece-wise minimax polynomial approximation.
Function arctan(x) takes a ratio, and returns the angle of two sides of a right-angled
triangle. The ratio is the length of the side opposite to the angle divided by the length of
the side adjacent to the angle. The graph of the arctan(x) is shown in the following figure:
Figure 2-4. Course of the GFLIB_Atan function
The fractional arithmetic version of the GFLIB_Atan function is limited to a certain
range of inputs <-1 ; 1). Because the arctangent values are the same, with just an opposite
sign for the input ranges <-1 ; 0) and <0 ; 1), the approximation of the arctangent function
over the entire defined range of input ratios can be simplified to the approximation for a
ratio in the range <0 ; 1). After that, the result will be negated, depending on the input
ratio.
GFLIB User's Guide, Rev. 4, 12/2020
44NXP Semiconductors
Chapter 2 Algorithms in detail
2.6.1Available versions
The function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-0.25 ; 0.25), which corresponds to the angle <-π / 4 ; π / 4).
• Floating-point output - the output is the floating-point result within the range <-π /
2 ;π / 2>.
• Accumulator output with floating-point input - the output is the accumulator angle
within the range (-0.5 ; 0.5), which corresponds to the angle (-π / 2 ; π / 2). The input
is the floating-point value.
The available versions of the GFLIB_Atan function are shown in the following table:
Table 2-6. Function versions
Function nameInput typeResult typeDescription
GFLIB_Atan_F16frac16_tfrac16_tInput argument is a 16-bit fractional value within the range <-1 ; 1). The
output is the arctangent of the input as a 16-bit fractional value, normalized
within the range <-0.25 ; 0.25), which represents an angle (in radians) in
the range <-π / 4 ; π / 4) <-45° ; 45°).
GFLIB_Atan_FLTfloat_tfloat_tInput argument is a 32-bit single precision floating-point value within the
full type's range. The output is the arctangent of the input as a 32-bit single
precision floating-point value in radians.
GFLIB_Atan_A32ffloat_tacc32_tInput argument is a 32-bit single precision floating-point value within the
full type's range. The output is the arctangent of the input as a 32-bit
accumulator value, normalized within the range (-0.5 ; 0.5), which
represents an angle (in radians) in the range (-π / 2 ; π / 2) (-90° ; 90°).
2.6.2Declaration
The available GFLIB_Atan functions have the following declarations:
The GFLIB_AtanYX function computes the angle, where its tangent is y / x (see the
figure below). This calculation is based on the input argument division (y divided by x),
and the piece-wise polynomial approximation.
GFLIB User's Guide, Rev. 4, 12/2020
46NXP Semiconductors
Chapter 2 Algorithms in detail
Figure 2-5. Course of the GFLIB_AtanYX function
The first parameter Y is the ordinate (the x coordinate), and the second parameter X is the
abscissa (the x coordinate). The counter-clockwise direction is assumed to be positive,
and thus a positive angle is computed if the provided ordinate (Y) is positive. Similarly, a
negative angle is computed for the negative ordinate. The calculations are performed in
several steps. In the first step, the angle is positioned within the correct half-quarter of the
circumference of a circle by dividing the angle into two parts: the integral multiple of 45
(half-quarter), and the remaining offset within the 45o range. Simple geometric properties
of the Cartesian coordinate system are used to calculate the coordinates of the vector with
the calculated angle offset. In the second step, the vector ordinate is divided by the vector
abscissa (y / x) to obtain the tangent value of the angle offset. The angle offset is
computed by applying the GFLIB_Atan function. The sum of the integral multiple of
half-quarters and the angle offset within a single halfquarter form the angle is computed.
o
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors47
GFLIB_AtanYX
The function returns 0 if both input arguments equal 0, and sets the output error flag; in
other cases, the output flag is cleared. When compared to the GFLIB_Atan function, the
GFLIB_AtanYX function places the calculated angle correctly within the fractional range
<-π ; π>.
In the fractional arithmetic, both input parameters are assumed to be in the fractional
range <-1 ; 1). The output is within the range <-1 ; 1), which corresponds to the real
range <-π ; π).
2.7.1Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1), which corresponds to the angle <-π ; π).
• Floating-point output - the output is the floating-point result within the range <- π;
π>.
• Accumulator output with floating-point input - the output is the accumulator angle
within the range <-1 ; 1>, which corresponds to the angle <-π ; π>. The input is the
floating-point value.
The available versions of the GFLIB_AtanYX function are shown in the following table:
Table 2-7. Function versions
Function nameInput typeOutput typeResult type
YXError flag
GFLIB_AtanYX_F16frac16_tfrac16_tbool_t *frac16_t
The first input argument is a 16-bit fractional value that contains the ordinate of the input vector (y
coordinate). The second input argument is a 16-bit fractional value that contains the abscissa of the
input vector (x coordinate). The result is the arctangent of the input arguments as a 16-bit fractional
value within the range <-1 ; 1), which corresponds to the real angle range <- π; π). The function sets
the boolean error flag pointed to by the output parameter if both inputs are zero; in other cases, the
output flag is cleared.
GFLIB_AtanYX_FLTfloat_tfloat_tbool_t *float_t
The first input argument is a 32-bit single precision floating-point value, which contains the ordinate
of the input vector (y coordinate). The second input argument is a 32-bit single precision floatingpoint value, which contains the abscissa of the input vector (x coordinate). The result is the
arctangent of the input arguments as a 32-bit single precision floating-point value within the range
<- π; π>. The function sets the boolean error flag pointed to by the output parameter if both inputs
are zero; in other cases, the output flag is cleared.
GFLIB_AtanYX_A32fffloat_tfloat_tbool_t *acc32_t
The first input argument is a 32-bit single precision floating-point value, which contains the ordinate
of the input vector (y coordinate). The second input argument is a 32-bit single precision floatingpoint value, which contains the abscissa of the input vector (x coordinate). The result is the
arctangent of the input arguments as a 32-bit accumulator value within the range <-1 ; 1>, which
corresponds to the real angle range <- π; π>. The function sets the boolean error flag pointed to by
the output parameter if both inputs are zero; in other cases, the output flag is cleared.
GFLIB User's Guide, Rev. 4, 12/2020
48NXP Semiconductors
Chapter 2 Algorithms in detail
2.7.2Declaration
The available GFLIB_AtanYX functions have the following declarations:
The GFLIB_Sqrt function returns the square root of the input value. The input must be a
non-negative number, otherwise the function returns undefined results. See the following
equation:
Equation 6. Algorithm formula
2.8.1Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <0 ; 1). The function is only defined for non-negative inputs. The
function returns undefined results out of this condition.
• Floating-point output - the output is the floating-point non-negative result. The
function is only defined for non-negative inputs. The function returns undefined
results out of this condition.
The available versions of the GFLIB_Sqrt function are shown in the following table:
Table 2-8. Function versions
Function nameInput
type
GFLIB_Sqrt_F16frac16_tfrac16_tThe input value is a 16-bit fractional value, limited to the range <0 ; 1). The
GFLIB_Sqrt_F16lfrac32_tfrac16_tThe input value is a 32-bit fractional value, limited to the range <0 ; 1). The
GFLIB_Sqrt_FLTfloat_tfloat_tThe input value is a 32-bit single precision floating-point non-negative value.
Result
type
Description
function is not defined out of this range. The output is a 16-bit fractional value
within the range <0 ; 1).
function is not defined out of this range. The output is a 16-bit fractional value
within the range <0 ; 1).
The function is not defined for the negative inputs. The output is a 32-bit single
precision floating-point non-negative value.
2.8.2Declaration
The available GFLIB_Sqrt functions have the following declarations:
The GFLIB_VectorLimit function returns the limited vector by an amplitude. This
limitation is calculated to achieve the zero angle error.
GFLIB User's Guide, Rev. 4, 12/2020
56NXP Semiconductors
Chapter 2 Algorithms in detail
Figure 2-6. Input and releated output
The GFLIB_VectorLimit function limits the amplitude of the input vector. The input
vector a, b components, are passed into the function as the input arguments. The resulting
limited vector is transformed back into the a, b components. The limitation is performed
according to the following equations:
Equation 10. Algorithm formulas
Equation 11
where:
• a, b are the vector coordinates
• a*, b* are the vector coordinates after limitation
• lim is the maximum amplitude
The relationship between the input and limited output vectors is obvious from Figure 2-6.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors57
GFLIB_VectorLimit
If the amplitude of the input vector is greater than the input Lim value, the function
calculates the new coordinates from the Lim value; otherwise the function copies the
input values to the output.
2.12.1Available versions
The function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1;1). The result may saturate.
• Floating point output - the output is the floating point result within the type's full
range.
The available versions of the GFLIB_VectorLimit functions are shown in the following
table:
Limitation of a two-component 16-bit fractional vector within the range <-1;1) with a 16-bit
fractional limitation amplitude. The function returns a two-component 16-bit fractional vector.
Limitation of a two-component 32-bit single precision floating point vector within the full range
with a 32-bit single precision floating point limitation amplitude. The function returns a twocomponent 32-bit single precision floating point vector.
type
2.12.2GFLIB_VECTORLIMIT_T_F16 type description
Variable nameInput typeDescription
f16Afrac16_tA-component; 16-bit fractional type.
f16Bfrac16_tB-component; 16-bit fractional type
2.12.3GFLIB_VECTORLIMIT_T_FLT type description
Variable nameInput typeDescription
fltAfloat_tA-component; 32-bit single precision floating point type.
fltBfloat_tB-component; 32-bit single precision floating point type.
GFLIB User's Guide, Rev. 4, 12/2020
58NXP Semiconductors
Chapter 2 Algorithms in detail
2.12.4Declaration
The available GFLIB_VectorLimit functions have the following declarations:
The GFLIB_VectorLimit1 function returns the limited vector by an amplitude. This
limitation is calculated to achieve that the first component remains unchanged (if the
limitation factor allows).
Figure 2-7. Input and releated output
The GFLIB_VectorLimit1 function limits the amplitude of the input vector. The input
vector a, b components are passed to the function as the input arguments. The resulting
limited vector is transformed back into the a, b components. The limitation is performed
according to the following equations:
Equation 12
Equation 13
GFLIB User's Guide, Rev. 4, 12/2020
60NXP Semiconductors
Chapter 2 Algorithms in detail
where:
• a, b are the vector coordinates
• a*, b* are the vector coordinates after limitation
• lim is the maximum amplitude
The relationship between the input and limited output vectors is shown in Figure 2-7.
If the amplitude of the input vector is greater than the input Lim value, the function
calculates the new coordinates from the Lim value; otherwise the function copies the
input values to the output.
2.13.1
Available versions
The function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
• Floating-point output - the output is the floating-point result within the type's full
range.
The available versions of the GFLIB_VectorLimit1 function are shown in the following
table:
Limitation of a two-component 16-bit fractional vector within the range <-1 ; 1) with a 16-bit
fractional limitation amplitude. The function returns a two-component 16-bit fractional vector.
Limitation of a two-component 32-bit single precision floating-point vector within the full range
with a 32-bit single precision floating-point limitation amplitude. The function returns a twocomponent 32-bit single precision floating-point vector.
GFLIB_Hyst function represents a hysteresis (relay) function. The function switches
the output between two predefined values. When the input is higher than the upper
threshold, the output is high; when the input is lower than the lower threshold, the output
is low. When the input is between the two thresholds, the output retains its value. See the
following figure:
Figure 2-8. GFLIB_Hyst functionality
The four points in the figure are to be set up in the parameters structure of the function.
For a proper functionality, the HystOn point must be greater than the HystOff point.
2.14.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result, and the result is
within the range <-1 ; 1).
• Floating-point output - the output is the floating-point result within the type's full
range.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors63
GFLIB_Hyst
The available versions of the GFLIB_Hyst function are shown in the following table.
Table 2-14. Function versions
Function nameInput
type
GFLIB_Hyst_F16frac16_tGFLIB_HYST_T_F16 *frac16_tThe input is a 16-bit fractional value within
GFLIB_Hyst_FLTfloat_tGFLIB_HYST_T_FLT *float_tThe input is a 32-bit single precision
ParametersResult
type
Description
the range <-1 ; 1). The output is a twostate 16-bit fractional value.
floating-point value within its full range.
The output is a two-state 32-bit single
precision floating-point value.
2.14.2GFLIB_HYST_T_F16
Variable nameInput
type
f16HystOnfrac16_tThe point where the output sets the output to the f16OutValOn value when the input rises.
Set by the user.
f16HystOfffrac16_tThe point where the output sets the output to the f16OutValOff value when the input falls.
Set by the user.
f16OutValOnfrac16_tThe ON value. Set by the user.
f16OutValOfffrac16_tThe OFF value. Set by the user.
f16OutStatefrac16_tThe output state. Set by the algorithm. Must be initialized by the user.
Description
2.14.3GFLIB_HYST_T_FLT
Variable nameInput
type
fltHystOnfloat_tThe point where the output sets the output to the fltOutValOn value when the input rises.
Set by the user.
fltHystOfffloat_tThe point where the output sets the output to the fltOutValOff value when the input falls.
Set by the user.
fltOutValOnfloat_tThe ON value. Set by the user.
fltOutValOfffloat_tThe OFF value. Set by the user.
fltOutStatefloat_tThe output state. Set by the algorithm. Must be initialized by the user.
GFLIB User's Guide, Rev. 4, 12/2020
64NXP Semiconductors
Description
Chapter 2 Algorithms in detail
2.14.4Declaration
The available GFLIB_Hyst functions have the following declarations:
The GFLIB_Lut1D function implements the one-dimensional look-up table.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors65
GFLIB_Lut1D
Equation 14.
where:
• y is the interpolated value
• y1 and y2 are the ordinate values at the beginning and end of the interpolating
interval, respectively
• x1 and x2 are the abscissa values at the beginning and end of the interpolating
interval, respectively
• x is the input value provided to the function in the X input argument
Figure 2-9. Algorithm diagram - fractional version
The GFLIB_Lut1D function fuses a table of the precalculated function points. These
points are selected with a fixed step.
The fractional version of the algorithm has a defined interval of inputs within the range
<-1 ; 1>. The last table point is intended for the real value of 1, not the value of 1 from
the fraction numbers, which is lower than the real value of 1. The calculations are based
on the same intervals among the table points. The number of points must be 2n + 1, where
n can range from 1 through to 15.
The floating-point version of the algorithm has a defined interval of inputs within the
range <min ; max>, where the min and max values are the parameters of the algorithms.
The number of points is within the range <2 ; 65535>, where the first point lies at the min
position, and the last point lies at the max position.
GFLIB User's Guide, Rev. 4, 12/2020
66NXP Semiconductors
Chapter 2 Algorithms in detail
The function finds two nearest precalculated points of the input argument, and calculates
the output value using the linear interpolation between these two points.
2.15.1Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1).
• Floating-point output - the output is the floating-point result within the type's full
range. The input values are defined by the minimum and maximum input parameters
of the GFLIB_Lut1DInit function.
The available versions of the GFLIB_Lut1DInit function are shown in the following
table:
The input arguments are the 32-bit single precision floating-point values that contain the minimum
and maximum x-coordinates of the look-up table. The table size parameter can be in the range <2 ;
65535> and the pointer to the structure that contains the parameters defined in Table 2-16.
type
The available versions of the GFLIB_Lut1D function are shown in the following table:
Table 2-16. Function versions
Function nameInput typeParametersResult type
TableTable size
GFLIB_Lut1D_F16frac16_tfrac16_t *uint16_tfrac16_t
The input arguments are the 16-bit fractional value that contains the abscissa for which the 1-D
interpolation is performed, the pointer to a table which contains the 16-bit fractional values of the
look-up table, and the size of the look-up table. The table size parameter can be in the range <1 ;
15> (that means the parameter is log2 of the number of points + 1). The output is the interpolated 16bit fractional value computed from the look-up table.
GFLIB_Lut1D_F32frac32_tfrac32_t *uint16_tfrac32_t
The input arguments are the 32-bit fractional value that contains the abscissa for which the 1-D
interpolation is performed, the pointer to a table which contains the 32-bit fractional values of the
look-up table, and the size of the look-up table. The table size parameter can be in the range <1 ;
15> (that means the parameter is log2 of the number of points + 1). The output is the interpolated 32bit fractional value computed from the look-up table.
The input arguments are the 32-bit single precision floating-point value that contains the abscissa for
which the 1-D interpolation is performed, the pointer to a table which contains the 32-bit single
precision floating-point values of the look-up table, and the pointer to a structure that contains the
size of the look-up table together with the minimum and maximum borders of the input interval. The
table size parameter can be in the range <2 ; 65535>. The first value of the table is located at the
fltMin position, and the last value of the table is located at the fltMax position. The output is the
interpolated 32-bit single precision floating-point value computed from the look-up table.
2.15.2GFLIB_LUT1D_T_FLT type description
Variable nameInput typeDescription
fltMinfloat_tThe minimum of the look-up table x-coordinate; a 32-bit single precision floating-point type.
Set by the user in GFLIB_Lut1DInit_FLT.
fltMaxfloat_tThe maximum of the look-up table x-coordinate; a 32-bit single precision floating-point
type. Set by the user in GFLIB_Lut1DInit_FLT.
fltIntInvfloat_tInverse interval of the look-up table; a 32-bit single precision floating-point type. Set by the
algoritm in GFLIB_Lut1DInit_FLT.
u16TableSizeuint16_tSize of the table; a 16-bit unsigned integer type within the range <2 ; 65535>. Set by the
user in GFLIB_Lut1DInit_FLT.
2.15.3Declaration
The available GFLIB_Lut1D functions have the following declarations:
/* periodically called function */
void Isr()
{
fltResult = GFLIB_Lut1D_FLT(fltX, fltTable, &sParam);
}
2.16
GFLIB_LutPer1D
The GFLIB_LutPer1D function approximates the one-dimensional arbitrary user function
using the interpolation look-up method. It is periodic.
Equation 15.
where:
• y is the interpolated value
• y1 and y2 are the ordinate values at the beginning and end of the interpolating
interval, respectively
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors69
GFLIB_LutPer1D
• x1 and x2 are the abscissa values at the beginning and end of the interpolating
interval, respectively
• x is the input value provided to the function in the X input argument
Figure 2-10. Algorithm diagram - fractional version
The GFLIB_LutPer1D fuses a table of the pre-calculated function points. These points
are selected with a fixed step.
The fractional version of the algorithm has a defined interval of inputs within the range
<-1 ; 1>. The last table point is intended for the real value of 1 not the value of 1 from the
fraction numbers, which is lower than the real value of 1. The calculations are based on
the same intervals among the table points. The floating-point version of the algorithm has
a defined interval of inputs within the range <min ; max>, where the min and max values
are the parameters of the algorithms. The number of points is within the range <2 ;
65535>, where the first point lies at the min position, and the last point lies at the max
position.
The function finds two nearest precalculated points of the input argument, and calculates
the output value using the linear interpolation between these two points. This algorithm
serves for periodical functions. That means that when the input argument lies behind the
last pre-calculated point of the function, the interpolation is calculated between the last
and first points of the table.
2.16.1
Available versions
This function is available in the following versions:
GFLIB User's Guide, Rev. 4, 12/2020
70NXP Semiconductors
Chapter 2 Algorithms in detail
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1).
• Floating-point output - the output is the floating-point result within the type's full
range. The input values are defined by the minimum and maximum input parameter
of the GFLIB_LutPer1DInit function.
The available versions of the GFLIB_LutPer1DInit function are shown in the following
table:
The input arguments are the 32-bit single precision floating-point values that contain the
minimum and maximum x-coordinates of the periodic look-up table. The table size parameter can
be in the range <2 ; 65535> and the pointer to the structure that contains the parameters defined
in .Table 2-18
type
The available versions of the GFLIB_LutPer1D function are shown in the following
table:
The input arguments are the 16-bit fractional value that contains the abscissa for which the 1-D
interpolation is performed, the pointer to a structure which contains the 16-bit fractional values of
the periodic look-up table, and the size of the look-up table. The table size parameter can be in
the range <1 ; 15> (that means the parameter is log2 of the number of points). The output is the
interpolated 16-bit fractional value computed from the periodic look-up table.
The input arguments are the 32-bit fractional value that contains the abscissa for which the 1-D
interpolation is performed, the pointer to a table which contains the 32-bit fractional values of the
periodic look-up table, and the size of the periodic look-up table. The table size parameter can be
in the range <1 ; 15> (that means the parameter is log2 of the number of points). The output is
the interpolated 32-bit fractional value computed from the periodic look-up table.
The input arguments are the 32-bit single precision floating-point value that contains the abscissa
for which the 1-D interpolation is performed, the pointer to a structure which contains the 32-bit
single precision floating-point values of the periodic look-up table, and the pointer a to structure
that contains the size of the periodic look-up table together with the minimum and maximum
borders of the input interval. The table size parameter can be in the range <2 ; 65535>. The first
value of the table is located at the fltMin position, and the last value of the table is located at the
fltMax position. The output is the interpolated 32-bit single precision floating-point value
computed from the periodic look-up table.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors71
GFLIB_LutPer1D
2.16.2GFLIB_LUTPER1D_T_FLT type description
Variable nameInput typeDescription
fltMinfloat_tThe minimum of the periodic look-up table x-coordinate; a 32-bit single precision floating-
point type. Set by the user in GFLIB_LutPer1DInit_FLT.
fltMaxfloat_tThe maximum of the periodic look-up table x-coordinate; a 32-bit single precision floating-
point type. Set by the user in GFLIB_LutPer1DInit_FLT.
fltIntInvfloat_tInverse interval of the periodic look-up table; a 32-bit single precision floating-point type.
Set by the algorithm in GFLIB_LutPer1DInit_FLT.
u16TableSizeuint16_tSize of the table; a 16-bit unsigned integer type within the range <2 ; 65535>. Set by the
user in GFLIB_LutPer1DInit_FLT.
2.16.3Declaration
The available GFLIB_LutPer1D functions have the following declarations:
/* periodically called function */
void Isr()
{
fltResult = GFLIB_LutPer1D_FLT(fltX, fltTable, &sParam);
}
2.17
GFLIB_Ramp
The GFLIB_Ramp function calculates the up / down ramp with the defined fixed-step
increment / decrement. These two parameters must be set by the user.
For a proper use, it is recommended that the algorithm is initialized by the
GFLIB_RampInit function, before using the GFLIB_Ramp function. The
GFLIB_RampInit function initializes the internal state variable of the GFLIB_Ramp
algorithm with a defined value. You must call the init function when you want the ramp
to be initialized.
The use of the GFLIB_Ramp function is as follows: If the target value is greater than the
ramp state value, the function adds the ramp-up value to the state output value. The
output will not trespass the target value, that means it will stop at the target value. If the
target value is lower than the state value, the function subtracts the ramp-down value
from the state value. The output is limited to the target value, that means it will stop at the
target value. This function returns the actual ramp output value. As time passes, it is
approaching the target value by step increments defined in the algorithm parameters'
structure. The functionality of the implemented ramp algorithm is explained in the next
figure:
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors73
GFLIB_Ramp
Figure 2-11. GFLIB_Ramp functionality
2.17.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
• Floating-point output - the output is the floating-point result within the type's full
range.
The available versions of the GFLIB_RampInit functions are shown in the following
table:
Table 2-19. Init function versions
Function nameInput
type
GFLIB_RampInit_F16frac16_tGFLIB_RAMP_T_F16 *voidInput argument is a 16-bit fractional value that
GFLIB_RampInit_F32frac32_tGFLIB_RAMP_T_F32 *voidInput argument is a 32-bit fractional value that
ParametersResult
type
Description
represents the initialization value. The
parameters' structure is pointed to by a pointer.
The input data value is in the range <-1 ; 1).
represents the initialization value. The
parameters' structure is pointed to by a pointer.
The input data value is in the range <-1 ; 1).
Table continues on the next page...
GFLIB User's Guide, Rev. 4, 12/2020
74NXP Semiconductors
Chapter 2 Algorithms in detail
Table 2-19. Init function versions (continued)
Function nameInput
type
GFLIB_RampInit_FLTfloat_tGFLIB_RAMP_T_FLT *voidInput argument is a 32-bit single precision
ParametersResult
type
Description
floating-point value that represents the
initialization value. The parameters' structure is
pointed to by a pointer. The input value is within
the full 32-bit single-point floating-point range.
The available versions of the GFLIB_Ramp functions are shown in the following table:
Table 2-20. Function versions
Function nameInput
type
GFLIB_Ramp_F16frac16_tGFLIB_RAMP_T_F16 *frac16_tInput argument is a 16-bit fractional value that
GFLIB_Ramp_F32frac32_tGFLIB_RAMP_T_F32 *frac32_tInput argument is a 32-bit fractional value that
GFLIB_Ramp_FLTfloat_tGFLIB_RAMP_T_FLT *float_tInput argument is a 32-bit single precision floating-
ParametersResult
type
Description
represents the target output value. The
parameters' structure is pointed to by a pointer.
The function returns a 16-bit fractional value,
which represents the actual ramp output value.
The input data value is in the range <-1 ; 1), and
the output data value is in the range <-1 ; 1).
represents the target output value. The
parameters' structure is pointed to by a pointer.
The function returns a 32-bit fractional value,
which represents the actual ramp output value.
The input data value is in the range <-1 ; 1), and
the output data value is in the range <-1 ; 1).
point value that represents the target output value.
The parameters' structure is pointed to by a
pointer. The function returns a 32-bit single
precision floating-point value, which represents
the actual ramp output value. The input and output
values are within the full 32-bit single-point
floating-point range.
2.17.2GFLIB_RAMP_T_F16
Variable nameTypeDescription
f16Statefrac16_tActual value - controlled by the algorithm.
f16RampUpfrac16_tValue of the ramp-up increment. The data value is in the range <0 ; 1). Set by the user.
f16RampDownfrac16_tValue of the ramp-down increment. The data value is in the range <0 ; 1). Set by the user.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors75
GFLIB_Ramp
2.17.3GFLIB_RAMP_T_F32
Variable nameTypeDescription
f32Statefrac32_tActual value - controlled by the algorithm.
f32RampUpfrac32_tValue of the ramp-up increment. The data value is in the range <0 ; 1). Set by the user.
f32RampDownfrac32_tValue of the ramp-down increment. The data value is in the range <0 ; 1). Set by the user.
2.17.4GFLIB_RAMP_T_FLT
Variable nameTypeDescription
fltStatefloat_tActual value - controlled by the algorithm.
fltRampUpfloat_tValue of the ramp-up increment. The data value is within the full 32-bit single precision
floating point. Set by the user as non- negative value.
fltRampDownfloat_tValue of the ramp-down increment. The data value is within the full 32-bit single precision
floating point. Set by the user as non- negative value.
2.17.5Declaration
The available GFLIB_RampInit functions have the following declarations:
/* periodically called function */
void Isr()
{
fltResult = GFLIB_Ramp_FLT(fltTarget, &psParam);
}
2.18
GFLIB_DRamp
The GFLIB_DRamp function calculates the up / down ramp with the defined step
increment / decrement. The algorithm approaches the target value when the stop flag is
not set, and/or returns to the instant value when the stop flag is set.
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors77
GFLIB_DRamp
Figure 2-12. GFLIB_DRamp functionality
For a proper use, it is recommended that the algorithm is initialized by the
GFLIB_DRampInit function, before using the GFLIB_DRamp function. This function
initializes the internal state variable of GFLIB_DRamp algorithm with the defined value.
You must call this function when you want the ramp to be initialized.
The GFLIB_DRamp function calculates a ramp with a different set of up / down
parameters, depending on the state of the stop flag. If the stop flag is cleared, the function
calculates the ramp of the actual state value towards the target value, using the up or
down increments contained in the parameters' structure. If the stop flag is set, the
function calculates the ramp towards the instant value, using the up or down saturation
increments.
If the target value is greater than the state value, the function adds the ramp-up value to
the state value. The output cannot be greater than the target value (case of the stop flag
being cleared), nor lower than the instant value (case of the stop flag being set).
If the target value is lower than the state value, the function subtracts the ramp-down
value from the state value. The output cannot be lower than the target value (case of the
stop flag being cleared), nor greater than the instant value (case of the stop flag being
set).
If the actual internal state reaches the target value, the reach flag is set.
GFLIB User's Guide, Rev. 4, 12/2020
78NXP Semiconductors
Chapter 2 Algorithms in detail
2.18.1Available versions
The function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
• Floating-point output - the output is the floating-point result within the type's full
range.
The available versions of the GFLIB_DRampInit function are shown in the following
table:
Table 2-21. Init function versions
Function nameInput
type
GFLIB_DRampInit_F16frac16_tGFLIB_DRAMP_T_F16 *voidInput argument is a 16-bit fractional value
GFLIB_DRampInit_F32frac32_tGFLIB_DRAMP_T_F32 *voidInput argument is a 32-bit fractional value
GFLIB_DRampInit_FLTfloat_tGFLIB_DRAMP_T_FLT *voidInput argument is a 32-bit single precision
ParametersResult
type
Description
that represents the initialization value. The
parameters' structure is pointed to by a
pointer. The input data value is in the range
<-1 ; 1).
that represents the initialization value. The
parameters' structure is pointed to by a
pointer. The input data value is in the range
<-1 ; 1).
floating-point value that represents the
initialization value. The parameters'
structure is pointed to by a pointer. The
input value is within the full 32-bit singlepoint floating-point range.
The available versions of the GFLIB_DRamp function are shown in the following table:
The target and instant arguments are 16-bit fractional values. The parameters' structure is pointed to
by a pointer. The function returns a 16-bit fractional value, which represents the actual ramp output
value. The input data values are in the range of <-1 ; 1), the Stop flag parameter is a pointer to a
boolean value, and the output data value is in the range <-1 ; 1).
The target and instant arguments are 32-bit fractional values. The parameters' structure is pointed to
by a pointer. The function returns a 32-bit fractional value, which represents the actual ramp output
value. The input data values are in the range <-1 ; 1), the Stop flag parameter is a pointer to a boolean
value, and the output data value is in the range <-1 ; 1).
The target and instant arguments are 32-bit single precision floating-point values. The parameters'
structure is pointed to by a pointer. The function returns a 32-bit single precision floating-point value,
which represents the actual ramp output value. The input and output values are within the full 32-bit
single-point floating-point range, the Stop flag parameter is a pointer to a boolean value.
2.18.2GFLIB_DRAMP_T_F16
Variable nameTypeDescription
f16Statefrac16_tActual value - controlled by the algorithm.
f16RampUpfrac16_tValue of non-saturation ramp-up increment. The data value is in the range <0 ; 1). Set by
the user.
f16RampDownfrac16_tValue of non-saturation ramp-down increment. The data value is in the range <0 ; 1). Set
by the user.
f16RampUpSatfrac16_tValue of saturation ramp-up increment. The data value is in the range <0 ; 1). Set by the
user.
f16RampDownSatfrac16_tValue of saturation ramp-down increment. The data value is in the range <0 ; 1). Set by the
user.
bReachFlagbool_tIf the actual state value reaches the target value, this flag is set, otherwise, it is cleared.
Set by the algorithm.
2.18.3GFLIB_DRAMP_T_F32
Variable nameTypeDescription
f32Statefrac32_tActual value - controlled by the algorithm.
f32RampUpfrac32_tValue of non-saturation ramp-up increment. The data value is in the range <0 ; 1). Set by
the user.
f32RampDownfrac32_tValue of non-saturation ramp-down increment. The data value is in the range <0 ; 1). Set
by the user.
f32RampUpSatfrac32_tValue of saturation ramp-up increment. The data value is in the range <0 ; 1). Set by the
user.
f32RampDownSatfrac32_tValue of saturation ramp-down increment. The data value is in the range <0 ; 1). Set by the
user.
Table continues on the next page...
GFLIB User's Guide, Rev. 4, 12/2020
80NXP Semiconductors
Chapter 2 Algorithms in detail
Variable nameTypeDescription
bReachFlagbool_tIf the actual state value reaches the target value, this flag is set, otherwise, it is cleared.
Set by the algorithm.
2.18.4GFLIB_DRAMP_T_FLT
Variable nameTypeDescription
fltStatefloat_tActual value - controlled by the algorithm.
fltRampUpfloat_tValue of non-saturation ramp-up increment. The data value is within the full 32-bit single
precision floating point. Set by the user as non- negative value.
fltRampDownfloat_tValue of non-saturation ramp-down increment. The data value is within the full 32-bit single
precision floating point. Set by the user as non- negative value.
fltRampUpSatfloat_tValue of saturation ramp-up increment. The data value is within the full 32-bit single
precision floating point. Set by the user as non- negative value.
fltRampDownSatfloat_tValue of saturation ramp-down increment. The data value is within the full 32-bit single
precision floating point. Set by the user as non- negative value.
bReachFlagbool_tIf the actual state value reaches the target value, this flag is set, otherwise, it is cleared.
Set by the algorithm.
2.18.5Declaration
The available GFLIB_DRampInit functions have the following declarations:
/* periodically called function */
void Isr()
{
fltResult = GFLIB_DRamp_FLT(fltTarget, fltInstant, &bStopFlag, &psParam);
}
GFLIB User's Guide, Rev. 4, 12/2020
82NXP Semiconductors
Chapter 2 Algorithms in detail
2.19GFLIB_FlexRamp
The GFLIB_FlexRamp function calculates the up/down ramp with a fixed-step increment
that is calculated according to the required speed change per a defined duration. These
parameters must be set by the user.
The GFLIB_FlexRamp algorithm consists of three functions that must be used for a
proper functionality of the algorithm:
• GFLIB_FlexRampInit - this function initializes the state variable with a defined
value and clears the reach flag
• GFLIB_FlexRampCalcIncr - this function calculates the increment and clears the
reach flag
• GFLIB_FlexRamp - this function calculates the ramp in the periodically called loop
For a proper use, it is recommended to initialize the algorithm by the
GFLIB_FlexRampInit function. The GFLIB_FlexRampInit function initializes the
internal state variable of the algorithm with a defined value and clears the reach flag. Call
the init function when you want to initialize the ramp.
To calculate the increment, use the GFLIB_FlexRampCalcIncr function. This function is
called at the point when you want to change the ramp output value. This function's inputs
are the target value and duration. The target value is the destination value that you want
to get to. The duration is the time required to change the ramp output from the actual state
to the target value. To be able to calculate the ramp increment, fill the control structure
with the sample time, that means the period of the loop where the GFLIB_FlexRamp
function is called. The structure also contains a variable which determines the maximum
value of the increment. It is necessary to set it up too. The equation for the increment
calculation is as follows:
Equation 16.
where:
• I is the increment
• Vt is the target value
• Vs is the state (actual) value (in the structure)
• T is the duration of the ramp (to reach the target value starting at the state value)
• Ts is the sample time, that means the period of the loop where the ramp algorithm is
called (set in the structure)
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors83
GFLIB_FlexRamp
If the increment is greater than the maximum increment (set in the structure), the
increment uses the maximum increment value.
As soon as the new increment is calculated, call the GFLIB_FlexRamp algorithm in the
periodical control loop. The function works as follows: The function adds the increment
to the state value (from the previous step), which results in a new state. The new state is
returned by the function. As the time passes, the algorithm is approaching the target
value. If the new state trespasses the target value, that new state is limited to the target
value and the reach flag is set. The functionality of the implemented algorithm is shown
in this figure:
Figure 2-13. GFLIB_FlexRamp functionality
2.19.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The input parameters are the fractional and accumulator
types.
• Floating-point output - the output is the floating-point result within the type's full
range.
GFLIB User's Guide, Rev. 4, 12/2020
84NXP Semiconductors
Chapter 2 Algorithms in detail
The available versions of the GFLIB_FlexRampInit function are shown in the following
table:
Table 2-23. Init function versions
Function nameInput
type
GFLIB_FlexRampInit_F16frac16_tGFLIB_FLEXRAMP_T_F32 *voidThe input argument is a 16-bit
GFLIB_FlexRampInit_FLTfloat_tGFLIB_FLEXRAMP_T_FLT *voidThe input argument is a 32-bit
ParametersResult
type
Description
fractional value that represents the
initialization value. The
parameters' structure is pointed to
by a pointer. The input data value
is in the range <-1 ; 1).
single precision floating-point
value that represents the
initialization value. The
parameters' structure is pointed to
by a pointer. The input value is
within the full 32-bit single-point
floating-point range.
The available versions of the GFLIB_FlexRamp function are shown in the following
table:
Table 2-24. Increment calculation function versions
The input arguments are a 16-bit fractional value in the range <-1 ; 1) that represents
the target output value and a 32-bit accumulator value in the range (0 ; 65536.0) that
represents the duration of the ramp (in seconds) to reach the target value. The
parameters' structure is pointed to by a pointer.
The input arguments are 32-bit single precision floating-point values that represent
the target output value and the duration of the ramp (in seconds, except zero value)
to reach the target value. The parameters' structure is pointed to by a pointer. The
target argument is within the full range; the duration argument is a non-negative
value.
type
Table 2-25. Function versions
Function nameParametersResult
type
GFLIB_FlexRamp_F16GFLIB_FLEXRAMP_T_F32 *frac16_tThe parameters' structure is pointed to by a
pointer. The function returns a 16-bit fractional
value, which represents the actual ramp
output value. The output data value is in the
range <-1 ; 1).
Table continues on the next page...
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors85
Description
GFLIB_FlexRamp
Table 2-25. Function versions (continued)
Function nameParametersResult
type
GFLIB_FlexRamp_FLTGFLIB_FLEXRAMP_T_FLT *float_tThe parameters' structure is pointed to by a
pointer. The function returns a 32-bit single
precision floating-point value, which
represents the actual ramp output value. The
output value is within the full 32-bit singlepoint floating-point range.
Description
2.19.2GFLIB_FLEXRAMP_T_F32
Variable nameTypeDescription
f32Statefrac32_tThe actual value. Controlled by the GFLIB_FlexRampInit_F16 and GFLIB_FlexRamp_F16
algorithms.
f32Incrfrac32_tThe value of the flex ramp increment. Controlled by the GFLIB_FlexRampCalcIncr_F16
algorithm.
f32Targetfrac32_tThe target value of the flex ramp algorithm. Controlled by the
GFLIB_FlexRampCalcIncr_F16 algorithm.
f32Tsfrac32_tThe sample time, that means the period of the loop where the GFLIB_FlexRamp_F16
algorithms are periodically called. The data value (in seconds) is in the range (0 ; 1). Set by
the user.
f32IncrMaxfrac32_tThe maximum value of the flex ramp increment. The data value is in the range (0 ; 1). Set
by the user.
bReachFlagbool_tThe reach flag. This flag is controlled by the GFLIB_FlexRamp_F16 algorithm. It is cleared
by the GFLIB_FlexRampInit_F16 and GFLIB_FlexRampCalcIncr_F16 algorithms.
2.19.3GFLIB_FLEXRAMP_T_FLT
Variable nameTypeDescription
fltStatefloat_tThe actual value. Controlled by the GFLIB_FlexRampInit_FLT and GFLIB_FlexRamp_FLT
algorithms.
fltIncrfloat_tThe value of the flex ramp increment. Controlled by the GFLIB_FlexRampCalcIncr_FLT
algorithm.
fltTargetfloat_tThe target value of the flex ramp algorithm. Controlled by the
GFLIB_FlexRampCalcIncr_FLT algorithm.
fltTsfloat_tThe sample time, that means the period of the loop where the GFLIB_FlexRamp_FLT
algorithm is periodically called. The data value (in seconds, except zero value) is a nonnegative value. Set by the user.
fltIncrMaxfloat_tThe maximum value of the flex ramp increment. The data is a positive value. Set by the
user.
bReachFlagbool_tThe reach flag. This flag is controlled by the GFLIB_FlexRamp_FLT algorithm. It is cleared
by the GFLIB_FlexRampInit_FLT and GFLIB_FlexRampCalcIncr_FLT algorithms.
GFLIB User's Guide, Rev. 4, 12/2020
86NXP Semiconductors
Chapter 2 Algorithms in detail
2.19.4Declaration
The available GFLIB_FlexRampInit functions have the following declarations:
void main(void)
{
/* Control loop period is 0.002 s; maximum increment value is 0.15 */
sFlexRamp.f32Ts = FRAC32(0.002);
sFlexRamp.f32IncrMax = FRAC32(0.15);
/* Initial value to 0 */
f16InitVal = FRAC16(0.0);
/* Flex ramp initialization */
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors87
GFLIB_DFlexRamp
GFLIB_FlexRampInit_F16(f16InitVal, &sFlexRamp);
/* Target value is 0.7 in duration of 5.3 s */
f16Target = FRAC16(0.7);
a32RampDuration = ACC32(5.3);;
/* periodically called control loop */
void Isr()
{
fltRampResult = GFLIB_FlexRamp_FLT(&sFlexRamp);
}
2.20
GFLIB_DFlexRamp
GFLIB User's Guide, Rev. 4, 12/2020
88NXP Semiconductors
Chapter 2 Algorithms in detail
The GFLIB_DFlexRamp function calculates the up/down ramp with a fixed-step
increment that is calculated according to the required speed change per a defined
duration.These parameters must be set by the user. The algorithm has stop flags. If none
of them is set, the ramp behaves normally. If one of them is set, the ramp can run in the
opposite direction.
The GFLIB_DFlexRamp algorithm consists of three functions that must be used for a
proper functionality of the algorithm:
• GFLIB_DFlexRampInit - this function initializes the state variable with a defined
value and clears the reach flag
• GFLIB_DFlexRampCalcIncr - this function calculates the increment and clears the
reach flag
• GFLIB_DFlexRamp - this function calculates the ramp in the periodically called
loop
For a proper use, initialize the algorithm by the GFLIB_DFlexRampInit function. The
GFLIB_DFlexRampInit function initializes the internal state variable of the algorithm
with a defined value and clears the reach flag. Call the init function when you want to
initialize the ramp.
To calculate the increment, use the GFLIB_DFlexRampCalcIncr function. Call this
function when you want to change the ramp output value. This function's inputs are the
target value and duration, and the ramp increments for motoring and generating
saturation modes. The target value is the destination value that you want to get to. The
duration is the time required to change the ramp output from the actual state to the target
value. To calculate the ramp increment, fill the control structure with the sample time,
that means the period of the loop where the GFLIB_DFlexRamp funciton is called. The
structure also contains a variable which determines the maximum value of the increment.
It is necessary to set it up too. The equation for the increment calculation is as follows:
Equation 17.
where:
• I is the increment
• Vt is the target value
• Vs is the state (actual) value (in the structure)
• T is the duration of the ramp (to reach the target value starting at the state value)
• Ts is the sample time, that means the period of the loop where the ramp algorithm is
called (set in the structure)
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors89
GFLIB_DFlexRamp
If the increment is greater than the maximum increment (set in the structure), the
increment uses the maximum increment value.
The state, target, and instant values must have the same sign, otherwise the saturation
modes don't work properly.
As soon as the new increment is calculated, you can call the GFLIB_DFlexRamp
algorithm in the periodical control loop. If none of the stop flags is set, the function
works as follows: The function adds the increment to the state value (from the previous
step), which results in a new state. The new state is returned by the function. As time
passes, the algorithm is approaching the target value. If the new state trespasses the target
value that new state is limited to, the target value and the reach flag are set. The
functionality of the implemented algorithm is shown in the following figure:
Figure 2-14. GFLIB_DFlexRamp functionality
If the motoring mode stop flag is set and the absolute value of the target value is greater
than the absolute value of the state value, the function uses the increment for the
motoring saturation mode to return to the instant value. Use case: when the application is
in the saturation mode and cannot supply more power to increase the speed, then a
saturation (motoring mode) flag is generated. To get out of the saturation, the ramp
output value is being reduced.
GFLIB User's Guide, Rev. 4, 12/2020
90NXP Semiconductors
Chapter 2 Algorithms in detail
If the generating mode stop flag is set and the absolute value of the target value is lower
than the absolute value of the state value, the funcion uses the increment for the
generating saturation mode to return to the instant value. Use case: when the application
is braking a motor and voltage increases on the DC-bus capacitor, then a saturation
(generating mode) flag is generated. To avoid trespassing the DC-bus safe voltage limit,
the speed requirement is increasing to disipate the energy of the capacitor.
2.20.1Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The input parameters are the fractional and accumulator
types.
The available versions of the GFLIB_DFlexRampInit functions are shown in the
following table:
Table 2-26. Init function versions
Function nameInput
type
GFLIB_FlexRampInit_F16frac16_tGFLIB_DFLEXRAMP_T_F32 *voidThe input argument is a 16-bit
GFLIB_FlexRampInit_FLTfloat_tGFLIB_DFLEXRAMP_T_FLT *voidThe input argument is a 32-bit
ParametersResult
type
Description
fractional value that represents
the initialization value. The
parameters' structure is pointed
to by a pointer. The input data
value is in the range <-1 ; 1).
single precision floating-point
value that represents the
initialization value. The
parameters' structure is pointed
to by a pointer. The input value is
within the full 32-bit single-point
floating-point range.
The available versions of the GFLIB_DFlexRamp functions are shown in the following
table:
Table 2-27. Increment calculation function versions
Table 2-27. Increment calculation function versions (continued)
Function nameInput typeParametersResult
TargetDurationIncr. sat-
mot
The input arguments are 16-bit fractional values in the range <-1 ; 1) that represent
the target output value and a 32-bit accumulator value in the range (0 ; 65536.0) that
represents the duration (in seconds) of the ramp to reach the target value. The other
two arguments are increments for the saturation mode when in the motoring and
generating modes. The parameters' structure is pointed to by a pointer.
The input arguments are 32-bit single precision floating-point values that represent
the target output value and the duration of the ramp (in seconds, except zero value)
to reach the target value. The other two arguments are increments for the saturation
mode when in the motoring and generating modes. The parameters' structure is
pointed to by a pointer. The target argument is within the full range; the duration
argument is a non-negative value.
The input argument is a 16-bit fractional value in the range <-1 ; 1) that represents
the measured instant value. The stop flags are pointers to the bool_t types. The
parameters' structure is pointed to by a pointer. The function returns a 16-bit
fractional value, which represents the actual ramp output value. The output data
value is in the range <-1 ; 1).
The input arguments are 32-bit single precision floating-point values that represent
the measured instant value. The stop flags are pointers to bool_t types. The
parameters' structure is pointed to by a pointer. The function returns a 32-bit single
precision floating-point value, which represents the actual ramp output value. The
output value is within the full 32-bit single-point floating-point range.
Stop flag-
gen
type
2.20.2GFLIB_DFLEXRAMP_T_F32
Variable nameTypeDescription
f32Statefrac32_tThe actual value. Controlled by the GFLIB_FlexRampInit_F16 and GFLIB_FlexRamp_F16
algorithms.
f32Incrfrac32_tThe value of the dyn. flex ramp increment. Controlled by the
GFLIB_FlexRampCalcIncr_F16 algorithm.
f32IncrSatMotfrac32_tThe value of the dyn. flex ramp increment when in the motoring saturation mode.
Controlled by the GFLIB_DFlexRampCalcIncr_F16 algorithm.
Table continues on the next page...
GFLIB User's Guide, Rev. 4, 12/2020
92NXP Semiconductors
Chapter 2 Algorithms in detail
Variable nameTypeDescription
f32IncrSatGenfrac32_tThe value of the dyn. flex ramp increment when in the generating saturation mode.
Controlled by the GFLIB_DFlexRampCalcIncr_F16 algorithm.
f32Targetfrac32_tThe target value of the flex ramp algorithm. Controlled by the
GFLIB_DFlexRampCalcIncr_F16 algorithm.
f32Tsfrac32_tThe sample time, that means the period of the loop where the GFLIB_DFlexRamp_F16
algorithm is periodically called. The data value (in seconds) is in the range (0 ; 1). Set by
the user.
f32IncrMaxfrac32_tThe maximum value of the flex ramp increment. The data value is in the range (0 ; 1). Set
by the user.
bReachFlagbool_tReach flag. This flag is controlled by the GFLIB_DFlexRamp_F16 algorithm. It is cleared
by the GFLIB_DFlexRampInit_F16 and GFLIB_DFlexRampCalcIncr_F16 algorithms.
2.20.3GFLIB_DFLEXRAMP_T_FLT
Variable nameTypeDescription
fltStatefloat_tThe actual value. Controlled by the GFLIB_DFlexRampInit_FLT and
GFLIB_DFlexRamp_FLT algorithms.
fltIncrfloat_tThe value of the flex ramp increment. Controlled by the GFLIB_DFlexRampCalcIncr_FLT
algorithm.
fltIncrSatMotfloat_tThe value of the dyn. flex ramp increment when in the motoring saturation mode.
Controlled by the GFLIB_DFlexRampCalcIncr_FLT algorithm.
fltIncrSatGenfloat_tThe value of the dyn. flex ramp increment when in the generating saturation mode.
Controlled by the GFLIB_DFlexRampCalcIncr_FLT algorithm.
fltTargetfloat_tThe target value of the flex ramp algorithm. Controlled by the
GFLIB_DFlexRampCalcIncr_FLT algorithm.
fltTsfloat_tThe sample time, that means the period of the loop where the GFLIB_DFlexRamp_FLT
algorithm is periodically called. The data value (in seconds, except zero value) is a nonnegative value. Set by the user.
fltIncrMaxfloat_tThe maximum value of the flex ramp increment. The data is a positive value. Set by the
user.
bReachFlagbool_tThe reach flag. This flag is controlled by the GFLIB_DFlexRamp_FLT algorithm. It is
cleared by the GFLIB_DFlexRampInit_FLT and GFLIB_DFlexRampCalcIncr_FLT
algorithms.
2.20.4Declaration
The available GFLIB_DFlexRampInit functions have the following declarations:
void main(void)
{
/* Control loop period is 0.002 s; maximum increment value is 0.15 */
sDFlexRamp.f32Ts = FRAC32(0.002);
sDFlexRamp.f32IncrMax = FRAC32(0.15);
/* Initial value to 0 */
f16InitVal = FRAC16(0.0);
/* periodically called control loop with a period of 2 ms */
void Isr()
{
f16RampResult = GFLIB_DFlexRamp_F16(f16Instant, &bSatMot, &bSatGen, &sDFlexRamp);
}
/* periodically called control loop with a period of 2 ms */
void Isr()
{
fltRampResult = GFLIB_DFlexRamp_FLT(fltInstant, &bSatMot, &bSatGen, &sDFlexRamp);
}
2.21
GFLIB_FlexSRamp
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors95
GFLIB_FlexSRamp
The GFLIB_FlexSRamp function calculates the up/down ramp with a variable increment
that is calculated according to the required speed change per a defined duration. These
parameters must be set by the user. The variable increment is profiled to reach the Sprofile of the resulting ramp.
The GFLIB_FlexSRamp algorithm consists of three functions that must be used for a
proper functionality of the algorithm:
• GFLIB_FlexSRampInit - this function initializes the state variable with a defined
value, resets the accelaration increment to zero, sets the acceleration state to zero,
and clears the reach flag
• GFLIB_FlexSRampCalcIncr - this function calculates the desired acceleraion, two
points of the speed where the acceleration changes from a variable to a constant and
vice-versa, acceleration (derivative) increment, resets the increment to zero, sets the
acceleration state to zero, and clears the reach flag
• GFLIB_FlexSRamp - this function calculates the ramp in the periodically called loop
For a proper use, initialize the algorithm by the GFLIB_FlexSRampInit function. The
GFLIB_FlexSRampInit function initializes the internal state variable of the algorithm
with a defined value, resets the acceleration increment to zero, sets the acceleration state
to zero, and clears the reach flag. This function does not affect the other parameters of the
ramp. Call the init function to initialize the ramp.
To calculate the profile of the ramp, use the GFLIB_FlexSRampCalcIncr function. This
function is called when you want to change the ramp output value. This function's inputs
are the target value and duration. The target value is the destination value that you want
to get to. The duration is the time required to change the ramp output from the actual state
to the target value. To calculate the ramp increment, fill the control structure with the
sample time, that means the period of the loop where the GFLIB_FlexSRamp function is
called. Set up the desirable acceleration derivative that is necessary for the acceleration
and decceleration states. The structure also contains a variable that determines the
maximum value of the increment (acceleration). It is necessary to set it up too. The
equations for the ramp calculation are derived from the following figure:
GFLIB User's Guide, Rev. 4, 12/2020
96NXP Semiconductors
Chapter 2 Algorithms in detail
Figure 2-15. GFLIB_FlexSRamp profile
For the ramp output change in each state, these equations apply:
Equation 18.
Equation 19.
Equation 20.
where:
• x is the ramp output
• Δx1 is the ramp change in state 0
• Δx2 is the ramp change in state 1
• Δx3 is the ramp change in state 2
• T1 is the instant when the desired acceleration is reached and becomes constant
• T2 is the instant when the desired acceleration starts to decrease
To get the full ramp change between the actual state value and the target value, this
equation applies:
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors97
GFLIB_FlexSRamp
Equation 21.
The value of the desired accelelarion that is reached by the integration of the acceleration
derivative along the time within state 0 is:
Equation 22.
where:
• a
is the desired acceleration
des
• dA is the derivative of the acceleration
Similarly, the Δx1 and Δx2 values are given by integrating the acceleration in time:
Equation 23.
Equation 24.
Because the ramp is symetrical, time T2 is expressed as:
Equation 25.
where:
• T is the duration of the ramp
Using the equations for a
and T2, Equation 24 on page 98 is rewritten as:
des
Equation 26.
Putting Equation 26 on page 98 and Equation 26 on page 98 into Equation 21 on page 98,
the following equation is reached:
Equation 27.
GFLIB User's Guide, Rev. 4, 12/2020
98NXP Semiconductors
Chapter 2 Algorithms in detail
Having normalized the previous equation, a quadrature equation is reached:
Equation 28.
One root of this quadrature equation is T1:
Equation 29.
Using Equation 22 on page 98, the desired acceleration is expressed as:
Equation 30.
This equation has a solution within the range of real numbers only if the square root
argument is not negative, so this condition must be met:
Equation 31.
If this condition is met and the desired acceleration is not greater than the maximum
increment (set in the structure), the ramp is achievable within the defined duration and
the function's output flag is TRUE. If the acceleration is greater than the maximum
increment, the function uses the maximum increment value and then the ramp is not
achieved on time, the output flag is FALSE.
If the condition given by Equation 31 on page 99 is not met, the ramp is not achievable
within the defined duration and the function returns the flag FALSE. In such case, the
ramp skips state 1 (where the acceleration is constant) and goes directly from state 0 to
state 2. The following figure shows the ramp profile:
GFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors99
GFLIB_FlexSRamp
Figure 2-16. GFLIB_FlexSRamp delayed profile
This ramp takes longer time than desirable duration. In this case, Δx1 is exactly a half of
the full ramp change output. The T1 instant is derived from Equation 23 on page 98 as:
Equation 32.
The desired acceleration is given by Equation 22 on page 98 as:
Equation 33.
Similarly to the previous case (when the ramp is achievable within the desired time), the
desired acceleration cannot be greater than the maximum increment, otherwise the
function uses the maximum increment value. If the desired acceleration is trimmed, the
ramp is in state 1 with a constant acceleration.
In both cases, the desired acceleration could have been reduced to the maximum
increment value, therefore it is necessary to adjust the T1 value using Equation 22 on
page 98 :
GFLIB User's Guide, Rev. 4, 12/2020
100NXP Semiconductors
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.