Post on 26-Oct-2014
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
1
IQ-Math Virtual Floating-Point Engine
Introduction & Application- 2nd Year Technical Competence -
06/23/2011Advanced Motion Control Team
2011/06/23, Advanced Motion Control TeamCopyright 2011 by Ajinextek Co., Ltd., All rights reserved.ⓒ
AJINEXTEK
1. Introduction
2. IQ-Math vs. Floating Math and Fixed Math (ANSI C)
3. Implementation
4. Summary
Introduction
2011/06/23, Advanced Motion Control TeamCopyright 2011 by Ajinextek Co., Ltd., All rights reserved.ⓒ
AJINEXTEK
3
1. Introduction
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
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-PointAlgorithm(C or C++)
Natural development starts with simulation in floating-
point
SimulationPlatform
(i.e. MatLab)
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
5
1. IQMath Introduction
Floating-point Processor Fixed-point Processor
- Hardware core unit support floating point operation which fol-lows IEEE 754 standarde.g: Intal’s Pentium Series, TI TMS320C6000, …
- Efficient when operation with floating-point data
- Not efficient in control task (bit manipulation, input/output con-trol, interrupt response)
- Expensive
- Internal hardware support inte-ger datae.g: all microcontroller families (Motorola HC68x, Infineon C166, …), TI TMS 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 TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
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 devel-
opment 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 dur-
ing 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 val-
ues- 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 TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
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 tablesIQmath.lib
3) Linker Command FileIQmath.cmd
4) IQmath GEL file for debuggingIQmath.gel
5) Example programs
1. IQMath Introduction
2011/06/23, Advanced Motion Control TeamCopyright 2011 by Ajinextek Co., Ltd., All rights reserved.ⓒ
AJINEXTEK
8
2. IQ-math vs. Floating Pointand Fixed Point (ANSI C)
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
9
2.1 IQMath vs. Floating Math
Z = -2I + 2I-1 + … + 21 + 20 . 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 fffffffffffffffffffffff031 30 23 22
23 bit mantissa (fraction)8 bit exponent1 bit sign
Advantage Disadvantage
Floating Math
Large dynamic rangePrecision depends on exponent term
IQ Math Same precision for same IQ format
Limited dynamic range
1 . .2S E OffsetZ M
23
1
1 2 ii
i
M f
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
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.00000000010.000000238 - can’t 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 TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
I8 . Q24
I16 . Q48
M
X
B
Y
>> 24 Align DecimalPoint Of Multiply
I8 . Q24
I8 . Q24
sssssssssssssssssI16 . Q24
I8 . Q24I8 . Q24
11
2.2 IQMath vs. Fixed-Point Math (QMath)
Execute floating-point data or implement floating point algorithm on a fixed-point processor:
<< 24Align DecimalPoint for Add
I8 . Q24 M
X
B
Y
I8 . Q24
I8 . Q24
I16 . Q48
ssssssssssssssssssI8 . Q24
ssssI8 . Q48
I16 . Q48
sssssssssssssssssI16 . Q24 I8 . Q24
>> 24Align DecimalPoint 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 xANSI C IQ-Math
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
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;
TraditionalFix-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 TeamCopyright 2011 by Ajinextek Co., Ltd., All rights reserved.ⓒ
AJINEXTEK
13
3. IQ-math Implementation
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
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 TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
15
3. Implementation
IQ-Math range and resolution
Q range Stability Range
Q31 - Q27Unstable (not enough
Dynamic range)
Q26 - Q19 Stable
Q18 – Q1Unstable (low resolu-
tion, quantization problem)
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
16
3. Implementation
IQ-Math supported functions: supports most of common floating-point func-tions
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
17
Compile & Runusing floating-point math on
C3x, C67x,C28x (RTS), PC,..
Compile & Runusing “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 TeamCopyright 2011 by Ajinextek Co., Ltd., All rights reserved.ⓒ
AJINEXTEK
18
4. Summary
2011/06/23, Advanced Motion Control TeamCopyright 2011 Ajinextek Co., Ltd.ⓒ
AJINEXTEK
19
Seamless portability of code between fixed and floating-point
devicesUser 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
requirementSet 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 ConfidentialThis 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 client’s 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.
AJINEXTEK
http://www.ajinextek.com
Thank you!