AN5016. Trigonometry approximations. Document information

Similar documents
AN5021. Calculation of Orientation Matrices from Sensor Data. Document information

i.mx 7 Dual/Solo Product Lifetime Usage

i.mxrt1050 Product Lifetime Usage Estimates

i.mx 6ULL Product Usage Lifetime Estimates

i.mx 6UltraLite Product Usage Lifetime Estimates

Aerospace Android and Windows Coordinate Systems

FRDM-K64F Board Errata

Kinetis USB-KW41Z Wireless Protocol Sniffer Quick Start Guide

MCUXpresso SDK USB Power Delivery

Processor Expert Software for i.mx Processors Version 1.0

MQX RTOS Release Notes for Kinetis SDK v1.2.0 for KL33Z64 for FRDM-KL43Z Freescale Freedom Development Platform

Building U-Boot in CodeWarrior ARMv8

Freedom FRDM-MC-LVBLDC Development Platform User s Guide

Smart Plug Software Design Reference Manual

How to use FlexMemory as D-Flash and EEPROM in KE1xF

Getting Started with the MCU Flashloader

MQX RTOS Release Notes for Kinetis SDK FRDM- KV10Z Freescale Freedom Development Platform

Getting Started with MCUXpresso SDK CMSIS Packs

Offline Flash Programmer for Kinetis K- and L-series MCUs

Getting Started with Freescale MQX RTOS for Kinetis SDK and MDK-ARM Keil

Quick Start Guide for FRDM-FXS-MULTI-B

How to setup pre-build steps in CodeWarrior for Microcontrollers v10.x

i.mx 6Solo/6DualLite Product Lifetime Usage Estimates

Configure QSPI Bus Width and Frequency in Pre-Boot Loader Stage on QorIQ LS Series Processors

Adding a run control interface into an existing CodeWarrior for MCU v10.x project

DDR Validation Tool Getting Started Guide

Configuring DDR in U-Boot using QCVS

MF1 MOA4 S50. Contactless Chip Card Module Specification. This document gives specifications for the product MF1 MOA4 S50.

Emulating Dual SPI Using FlexIO

Using FCCU on MPC5744P

Collecting Linux Trace without using CodeWarrior

Power Consumption and Measurement of i.mx RT1020

AN Automatic RS-485 address detection. Document information

Kinetis KE1xF512 MCUs

Collect Linux Hardware Trace for ARMv8 User Space and Kernel Space Applications

How to Enable Boot from QSPI Flash

Working around ERR7026 according to application needs

Getting Started with Freescale MQX RTOS for Kinetis SDK and ARM GCC

KW41Z IEEE and BLE Coexistence Performance

Kinetis SDK Release Notes for the TWR-K24F120M Tower System Module

General C Functions for the etpu Covers the MCF523x, MPC5500, MPC5600, MPC5700, MPX40 and all etpu-equipped Devices

Measuring Interrupt Latency

i.mxrt1060 Product Lifetime Usage Estimates

Load Position-Independent Code (PIC) on a Kinetis Platform Using the IAR EWARM Compiler

Three-Phase Power Meter Hardware Design Reference Manual

AN Sleep programming for NXP bridge ICs. Document information

SPI topics: watchdog, serial output and parity check

Intelligent Sensing Framework 2.1 for Kinetis Errata Sheet

How to Implement USB Suspend/Resume Feature with MCUXpresso SDK USB Stack

Kinetis Bootloader v1.2.0 Release Notes

Controller Continuum. for Microcontrollers V6.3. Quick Start

QN9080 QN908x RF Certification Guide

TWR-LS1021A Getting Started

Emulating I2S bus on KE06

for Freescale MPC55xx/MPC56xx Microcontrollers V2.10 Quick Start

NOVPEK NetLeap User Guide

Single Chip Module (SCM) Package-on- Package (PoP) Assembly Guide

Using an External GCC Toolchain with CodeWarrior for Power Architecture

CAUTION This device is sensitive to ElectroStatic Discharge (ESD). Therefore care should be taken during transport and handling.

for ColdFire Architectures V7.2 Quick Start

Reference Design KL25-AGMP01 User Guide 10-Axis Data Logger Tool Kit

IoT Sensing SDK. Getting started with IoT Sensing SDK (ISSDK) v1.7 middleware. Document information. IoT Sensing SDK, ISSDK, MCUXpresso, middleware

PICO-i.MX6UL Development Platform for Android Things Quick Start Guide

2005: 0.5 PQ-MDS-PCIEXP

Freescale Kinetis Software Development Kit Release Notes

Getting Started with Freescale MQX RTOS for Kinetis SDK and Kinetis Design Studio IDE

Kinetis SDK Freescale Freedom FRDM-KL03Z Platform User s Guide

Quick Start Guide for FRDM-KL05Z

CodeWarrior Kernel-Aware Debug API

Integrate TWR-EPD Software with MQX RTOS Based on the TWR-K21F120M Platform

Installation Manual Installation Manual for the MicroWave Office design kit version v1.0

S12Z MagniV LIN Bootloader

Using an FFT on the Sigma-Delta ADCs

Quick Start Guide for the Freescale Freedom Development Platform FRDM-KL43Z

TWR-LS1021A Getting Started

Kinetis Motor Suite v1.2.0 Release Notes

CodeWarrior Development Studio Processor Expert RTOS Adapter User Guide

Kinetis Bootloader to Update Multiple Devices in a Field Bus Network

i.mx 6 Android JB 4.3_1.1.1 Patch Release Notes

WCT1011A/WCT1013A Automotive MP-A9 V4.0 Run-Time Debugging

HVP-KV10Z32 User s Guide

In data sheets and application notes which still contain NXP or Philips Semiconductors references, use the references to Nexperia, as shown below.

Quick Start Guide for FRDM-KL46Z Rev 1

i.mx 6ULL Migration Guide

Generating a Quick and Controlled Waveform With the DAC

Getting Started with MQX RTOS for Kinetis SDK

Installing Service Pack Updater Archive for CodeWarrior Tools (Windows and Linux) Quick Start

PCB Layout Guidelines for the MC1321x

Quick Start Guide for FRDM-KL46Z Rev 1

How to Reduce SoC Power when Running M4 with A53 on i.mx8m

Raspberry Pi shield board

How to use the NTAG I²C plus for bidirectional communication. Rev June

Kinetis SDK v Release Notes for KV5x Derivatives

AIOP Task Aware Debug

Using DMA for Pulse Counting on S32K

KIT34901EFEVB Evaluation Board

Migrating Applications from MC9S12VR64 to MC9S12VR32 by: Manuel Rodríguez

MAG3110 Frequently Asked Questions

WPR1500-LDO MP Receiver V2.1 Reference Design User s Guide

AN NTAG I²C plus memory configuration options. Application note COMPANY PUBLIC. Rev June Document information

Transcription:

Rev. 2.0 21 June 2016 Application note Document information Info Content Abstract This application note documents mathematical approximations to inverse trigonometric functions used in the NXP Sensor Fusion Library and contained in the file approximations.c.

Revision history Document ID Release date Supercedes v2.0 20160621 v1.0 Modifications: Minor changes The format of this document has been redesigned to comply with the new identity guidelines of NXP Semiconductors. Legal texts have been adapted to the new company name where appropriate. v1.0 2015 September Contact information For more information, please visit: http://www.nxp.com All information provided in this document is subject to legal disclaimers. NXP B.V. 2016. All rights reserved. Application note Rev. 2.0 21 June 2016 2 of 7

1. Introduction This application note documents mathematical approximations to inverse trigonometric functions used in the NXP Sensor Fusion Library and contained in the file approximations.c. The approximations are more efficient than the standard C floating point library when implemented on an integer microcontroller but are still highly accurate. The results are also computed directly in degrees rather than radians saving the additional floating point multiplication required to convert from radians to degrees. The mathematics underlying these approximations first transforms inverse sine and inverse cosine calls to an inverse tangent with modified argument. The argument of the inverse tangent is then transformed again allowing a call to a Pade[3,2] rational approximation to the inverse tangent in the limited range 0 to 15. The benchmarks in the following table were measured on the NXP FRDM-KL25Z board which uses a 32-bit ARM M0+ integer core running at 48 MHz (48 million clock ticks per second). A floating addition or multiply, by comparison, typically take just 120 to 150 clock ticks when emulated on an integer 32 bit core. Inverse sine, cosine and tangent calls are extremely expensive. C99 library function float asinf(float x) 4000 6000 clock ticks float acosf(float x) 4000 6000 clock ticks float atanf(float x) 3800 4800 clock ticks approximations.c float fasin_deg(float x) 3000 4000 clock ticks float facos_deg(float x) 3000 4000 clock ticks float fatan_deg(float x) 1900 3500 clock ticks 1.1 Software Functions The following is a list of NXP Sensor Fusion Library software functions found in the file approximations.c. Table 1. Sensor Fusion software functions Functions Description Reference float fasin_deg Inverse sine function (deg) range 90 to 90. 2.1 Worst case error is 10.29 x 10 6 deg. float facos_deg Inverse cosine function (deg) range 0 to 180. 2.2 Worst case error is 14.67 x 10 6 deg. float fatan_deg Inverse arctangent (deg) range 90 to 90. 2.3 Worst case error is 9.84 x 10 6 deg. float fatan2_deg Inverse arctangent (deg) range 180 to 180. 2.3 (float y, float x); Worst case error is 9.84 x 10 6 deg. float fatan_15deg Inverse arctangent (deg) in range 15 to +15 only 2.4 All information provided in this document is subject to legal disclaimers. NXP B.V. 2016. All rights reserved. Application note Rev. 2.0 21 June 2016 3 of 7

2. Mathematics 2.1 Approximation to Inverse Sine ( 90 to +90 ) The function fasin_deg computes the inverse sine of as the inverse tangent of the new argument 1 2. The overhead of the square root and division is still less than the overhead of the standard C inverse sine function. Putting = ssssssss into the definition of the tangent gives: tttttttt = ssssssss cccccccc = 1 θθ = 2 ssssss 1 = tttttt 1 1 2 (1) Since cccccccc is non-negative in the range 90 to +90, the positive square root can be taken in equation (1). 2.2 Approximation to Inverse Cosine (0 to +180 ) The function facos_deg allows the inverse cosine of to be determined as the inverse tangent of the new argument 1 2. Putting = cccccccc into the definition of the tangent gives: tttttttt = ssssssss 1 2 = θθ = cccccc 1 = tttttt 1 1 2 (2) cccccccc Since ssssssss is non-negative in the range 0 to +180, the positive square root can be taken in equation (2). The inverse tangent returns an angle in the range 90 to +90 but has additional valid solutions at multiples of 180. Since the inverse cosine is normally returned in the range 0 to 180, 180 is added if the argument is negative. 2.3 Approximation to Inverse Tangent ( 90 to +90 ) The inverse tangent for angles in the range 90 to +90 is computed in function fatan_deg which successively maps its argument to the inverse tangent of an angle in the range from 0 to +15. Negative arguments are mapped to positive arguments using the identity: tttttt 1 ( ) = tttttt 1 () (3) An argument greater than 1 (implying an angle above +45 ) is mapped to argument less than 1 (implying an angle below +45 ) using the identity: tttttt ππ 2 θθ = ssssss ππ 2 θθ cccccc ππ 2 θθ = cccccccc ssssssss = 1 tttttttt (4) The new argument is then compared with tttttt(15 ). If the angle is above 15 (in the range 15 to 45 ) then it is mapped to the range 15 to 15 using the identity: All information provided in this document is subject to legal disclaimers. NXP B.V. 2016. All rights reserved. Application note Rev. 2.0 21 June 2016 4 of 7

tttttt(θθ + φφ) = tttttttt + tttttttt 1 tttttttttttttttt (5) Substituting φφ = ππ (equal to 30 ) gives: 6 tttttt θθ ππ 6 = tttttttt tttttt ππ 6 1 + tttttttttttttt ππ 6 = tttttttt 1 3 1 + tttttttt 1 = 3tttttttt 1 3 tttttttt + 3 (6) With the substitution = tttttttt: tttttt θθ ππ 3 1 = 6 + 3 θθ = ππ 6 + tttttt 1 3 1 + 3 (7) The mappings used to restrict the argument range to 15 to 15 are then inverted to give θθ in the range 90 to +90. 2.4 Pade[3, 2] Approximation to Inverse Tangent ( 15 to +15 ) The standard Pade[3,2] rational approximation to the inverse tangent expanded about = 0 is: = 180 ππ tttttt 1 () 4 + 180 ππ 15 2 1 + 3 dddddd = 5 2 4 + 3 1 + 4 15 1 + 3 = 15 2 5 2 1 + 3 rrrrrr (8) 5 2 180 ππ 5 + 180 3 ππ 4 9 2 5 dddddd (9) 3 + 2 = (95.492965855 + 25.4647908942 ) 1.666666666 + 2 dddddd (10) This rational expression is used in function fatan_15deg with slightly modified Pade parameters selected to minimize the maximum error in the range 0 to +15. tttttt 1 () (96.644395816 + 25.0869416122 ) 1.6867633134 + 2 dddddd (11) Equation (11) is anti-symmetric about the origin as required since the inverse tangent is anti-symmetric. All information provided in this document is subject to legal disclaimers. NXP B.V. 2016. All rights reserved. Application note Rev. 2.0 21 June 2016 5 of 7

3. Legal information 3.1 Definitions Draft The document is a draft version only. The content is still under internal review and subject to formal approval, which may result in modifications or additions. NXP Semiconductors does not give any representations or warranties as to the accuracy or completeness of information included herein and shall have no liability for the consequences of use of such information. 3.2 Disclaimers Information in this document is provided solely to enable system and software implementers to use NXP products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits based on the information in this document. NXP reserves the right to make changes without further notice to any products herein. NXP makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does NXP assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. Typical parameters that may be provided in NXP data sheets and/ or specifications can and do vary in different applications, and actual performance may vary over time. All operating parameters, including typicals, must be validated for each customer application by customer's technical experts. NXP does not convey any license under its patent rights nor the rights of others. NXP sells products pursuant to standard terms and conditions of sale, which can be found at the following address: nxp.com/salestermsandconditions. 3.3 Trademarks Notice: All referenced brands, product names, service names and trademarks are property of their respective owners. NXP, the NXP logo, Freescale, and the Freescale logo are trademarks of NXP B.V. ARM and Cortex are registered trademarks of ARM Limited (or its subsidiaries) in the EU and/or elsewhere. All information provided in this document is subject to legal disclaimers. NXP B.V. 20164. All rights reserved. Application note Rev. 2.0 21 June 2016 6 of 7

4. Contents 1. Introduction... 3 1.1 Software Functions... 3 2. Mathematics... 4 2.1 2.2 Approximation to Inverse Sine ( 90 to +90 )... 4 Approximation to Inverse Cosine (0 to +180 ).. 4 2.3 Approximation to Inverse Tangent ( 90 to +90 )... 4 2.4 Pade[3, 2] Approximation to Inverse Tangent ( 15 to +15 )... 5 3. Legal information... 6 3.1 Definitions... 6 3.2 Disclaimers... 6 3.3 Trademarks... 6 4. Contents... 7 Please be aware that important notices concerning this document and the product(s) described herein, have been included in the section 'Legal information'. NXP B.V. 2016. All rights reserved. For more information, visit: http://www.nxp.com Date of release: 21 June 2016 Document identifier: