Sie sind auf Seite 1von 20

2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd.

1
IQ-Math Virtual Floating-Point Engine
Introduction & Application
- 2
nd
Year Technical Competence -
06/23/2011
Advanced Motion Control Team
2011/06/23, Advanced Motion Control Team Copyright 2011 by Ajinextek Co., Ltd., All rights reserved.
1. Introduction

2. IQ-Math vs. Floating Math and Fixed Math (ANSI C)

3. Implementation

4. Summary
Introduction
2011/06/23, Advanced Motion Control Team Copyright 2011 by Ajinextek Co., Ltd., All rights reserved. 3
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 4
Floating implementation in embedded application
1. IQMath Introduction
Takes many days/weeks
to convert (one way
process)
Fixed-Point
Algorithm
(ASM, C, C++)
Fixed-Point DSP
Can be easily ported
to floating-point
device
Floating-Point DSP
Floating-Point
Algorithm
(C or C++)
Natural development
starts with simulation in
floating-point
Simulation
Platform
(i.e. MatLab)
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 5
1. IQMath Introduction
Floating-point Processor Fixed-point Processor
- Hardware core unit support floating
point operation which follows IEEE 75
4 standard
e.g: Intals Pentium Series, TI TMS32
0C6000,

- Efficient when operation with floating
-point data

- Not efficient in control task (bit manip
ulation, input/output control, interrupt r
esponse)

- Expensive
- Internal hardware support integer da
ta
e.g: all microcontroller families (Motor
ola HC68x, Infineon C166, ), TI TM
S 430, TMS320C5000, C2000,

- Arithmetic unit and hardware multiply
unit (DSP) expect data to be in one of
fixed-point type

- Inexpensive
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 6
1. IQMath Introduction
IQ-Math format IQxxx() or IQNxxx(): virtual floating-point engine
+ Based on lookup tables available in BOOTROM of F281x devices
+ Variable range and resolution (present later)
+ Achieve higher speed and precision, shorten DSP application development
time when porting floating point algorithm into fixed point code
Fixed-Point format (Q Math)
- A value of a fixed-point data type is essentially an integer that is scaled by a specific factor determined
by the type.
- The scaling factor is the same for all values of the same type, and does not change during the entire
computation.
- The scaling factor: 10^x, 2^x, 1/3600, .
- Notation:
Qf : f is number of fraction digits
Qm.f : m is number of integer digits
Precision loss and overflow (e.g. multiplying (x) and dividing())



Floating-Point format
- Describes a system for representing real numbers which supports a wide range of values
- Numbers are in general represented approximately to a fixed number of significant digits and scaled
using an exponent
- The base for the scaling is normally 2, 10 or 16
Significant digits base
exponent

-The most common used format is IEEE standard 754 (discuss later)
More storage to encode the position of the radix but larger precision


2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 7
The TI IQmath library offers usage in C/CPP
program and it consists of 5 parts:

1) IQmath header file:
IQmathLib.h

2) IQmath object library containing all function & look-up
tables
IQmath.lib

3) Linker Command File
IQmath.cmd

4) IQmath GEL file for debugging
IQmath.gel

5) Example programs
1. IQMath Introduction
2011/06/23, Advanced Motion Control Team Copyright 2011 by Ajinextek Co., Ltd., All rights reserved. 8
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 9
2.1 IQMath vs. Floating Math
Z = -2
I
+ 2
I-1
+ + 2
1
+ 2
0
. 2
-1
+ 2
-2
+ + 2
-Q
IQ Format (or Fractional Format)
I INTEGER Fraction
Q QUOTIENT Fraction
IEEE Standard 754 Single Precision Floating Format
s eeeeeeee
fffffffffffffffffffffff
0 31 30 23 22
23 bit mantissa (fraction) 8 bit exponent 1 bit sign
Advantage Disadvantage
Floating Math Large dynamic range Precision depends on exponent term
IQ Math Same precision for same IQ format Limited dynamic range
( )
1 . .2
S
E Offset
Z M

=
23
1
1 2
i
i
i
M f

=
= +

2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 10
2.1 IQMath vs. Floating Math
Limitation of single precision floating format
Improve by IQ-math format
Example: x = 10.0 (0x41200000)
+ y = 0.000000238 (0x347F8CF1)
z = 10.000000238
0x412000000 = 10.000000000
10.000000238 : cant represent!
0x412000001 = 10.000000950
I8Q24 Example: x = 10.0 (0x0A000000)
y = 0.000000238 (0x00000004)
z = 10.000000238 (0x0A000004)
The gap between two identified numbers in single floating-point format is about ten
million times smaller than the numbers
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd.
I8 . Q24
I16 . Q48
M
X
B
Y
>> 24
Align Decimal
Point Of Multiply
I8 . Q24
I8 . Q24
sssssssssssssssssI16 . Q24
I8 . Q24 I8 . Q24
11
2.2 IQMath vs. Fixed-Point Math (QMath)
Execute floating-point data or implement floating point algorithm on a fixed-point
processor:
<< 24
Align Decimal
Point for Add
I8 . Q24
M
X
B
Y
I8 . Q24
I8 . Q24
I16 . Q48
ssssssssssssssssssI8 . Q24
ssssI8 . Q48
I16 . Q48
sssssssssssssssssI16 . Q24 I8 . Q24
>> 24
Align Decimal
Point for Store
Y = ((i64) M * (i64) X + (i64) B << Q) >> Q; in C:
Y = ((i64) M * (i64) X) >> Q + B; in C:
* Y M X B = +
+
+
x
x
ANSI C
IQ-Math
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 12
float Y, M, X, B;

Y = M * X + B;
Floating-Point
long Y, M, X, B;

Y = ((i64) M * (i64) X + (i64) B << Q)) >> Q;
Traditional
Fix-Point Q
_iq Y, M, X, B;

Y = _IQmpy(M, X) + B;
IQmath
In C
iq Y, M, X, B;

Y = M * X + B;
IQmath
In C++
2.3 Programming Scope
Comparison of floating format implementation
2011/06/23, Advanced Motion Control Team Copyright 2011 by Ajinextek Co., Ltd., All rights reserved. 13
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 14
3. Implementation
#define GLOBAL_Q 18 // define in IQmathLib.h
file
_iq Y, M, X, B;
Y = _IQmpy(M,X) + B; // all values are in Q = 18
User selects Global Q value for the whole application
based on the required dynamic range or resolution, for example:
The user can also explicitly specify the Q value to use:
_iq20 Y, M, X, B;
Y = _IQ20mpy(M,X) + B; // all values are in Q = 20
IQ-Math application
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 15
3. Implementation
IQ-Math range and resolution
Q range Stability Range
Q31 - Q27
Unstable (not enough
Dynamic range)
Q26 - Q19 Stable
Q18 Q1
Unstable (low resolution,
quantization problem)
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 16
3. Implementation
IQ-Math supported functions: supports most of common floating-point functions
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 17
Compile & Run
using floating-point math on
C3x, C67x,C28x (RTS), PC,..
Compile & Run
using IQ-math on
C28x
User selects target math type
(in IQmathLib.h file)
Y = _IQmpy(M, X) + B;
#if MATH_TYPE == IQ_MATH #if MATH_TYPE == FLOAT_MATH
Y = (float)M * (float)X + (float)B;
3. Implementation
Flexible portability between Fixed-point and Floating-point with IQ-Math
2011/06/23, Advanced Motion Control Team Copyright 2011 by Ajinextek Co., Ltd., All rights reserved. 18
2011/06/23, Advanced Motion Control Team Copyright 2011 Ajinextek Co., Ltd. 19
Seamless portability of code between fixed and floating-point devices
User selects target math type in IQmathLib.h file
#if MATH_TYPE == IQ_MATH
#if MATH_TYPE == FLOAT_MATH
One source code set for simulation vs. target device
Numerical resolution adjustability based on application requirement
Set in IQmathLib.h file
#define GLOBAL_Q 18
Explicitly specify Q value
_iq20 X, Y, Z;
Numerical accuracy without sacrificing time and cycles
Rapid conversion/porting and implementation of algorithms
IQ-math + 32-bit fixed-point processor
4. Summary
NOTICE: Proprietary and Confidential
This material is proprietary to Ajinextek Co., Ltd..
It contains trade secret and confidential information which is solely the property of Ajinextek Co., Ltd.
This material is for clients internal use only. This material shall not be used, reproduced, copied,
disclosed, transmitted, in whole or in part, without the express consent of Ajinextek Co., Ltd.
Copyright 2011 by Ajinextek Co., Ltd. All rights reserved.
http://www.ajinextek.com
Thank you!

Das könnte Ihnen auch gefallen