diff options
author | rihab kouki <rihab.kouki@st.com> | 2020-07-28 11:24:49 +0100 |
---|---|---|
committer | rihab kouki <rihab.kouki@st.com> | 2020-07-28 11:24:49 +0100 |
commit | 96d6da4e252b06dcfdc041e7df23e86161c33007 (patch) | |
tree | a262f59bb1db7ec7819acae435f5049cbe5e2354 /DSP/Source/ControllerFunctions | |
parent | 9f95ff5b6ba01db09552b84a0ab79607060a2666 (diff) | |
download | st-cmsis-core-lowfat-master.tar.gz st-cmsis-core-lowfat-master.tar.bz2 st-cmsis-core-lowfat-master.zip |
Diffstat (limited to 'DSP/Source/ControllerFunctions')
-rw-r--r-- | DSP/Source/ControllerFunctions/CMakeLists.txt | 37 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/ControllerFunctions.c | 37 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/arm_pid_init_f32.c | 39 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/arm_pid_init_q15.c | 61 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/arm_pid_init_q31.c | 45 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/arm_pid_reset_f32.c | 31 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/arm_pid_reset_q15.c | 28 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/arm_pid_reset_q31.c | 31 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/arm_sin_cos_f32.c | 172 | ||||
-rw-r--r-- | DSP/Source/ControllerFunctions/arm_sin_cos_q31.c | 76 |
10 files changed, 310 insertions, 247 deletions
diff --git a/DSP/Source/ControllerFunctions/CMakeLists.txt b/DSP/Source/ControllerFunctions/CMakeLists.txt new file mode 100644 index 0000000..705f5b8 --- /dev/null +++ b/DSP/Source/ControllerFunctions/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required (VERSION 3.6) + +project(CMSISDSPController) + +add_library(CMSISDSPController STATIC) + +configdsp(CMSISDSPController ..) + +include(interpol) +interpol(CMSISDSPController) + +if (CONFIGTABLE AND ALLFAST) + target_compile_definitions(CMSISDSPController PUBLIC ARM_ALL_FAST_TABLES) +endif() + +target_sources(CMSISDSPController PRIVATE arm_pid_init_f32.c) +target_sources(CMSISDSPController PRIVATE arm_pid_init_q15.c) +target_sources(CMSISDSPController PRIVATE arm_pid_init_q31.c) +target_sources(CMSISDSPController PRIVATE arm_pid_reset_f32.c) +target_sources(CMSISDSPController PRIVATE arm_pid_reset_q15.c) +target_sources(CMSISDSPController PRIVATE arm_pid_reset_q31.c) + +if (NOT CONFIGTABLE OR ALLFAST OR ARM_SIN_COS_F32) +target_sources(CMSISDSPController PRIVATE arm_sin_cos_f32.c) +endif() + +if (NOT CONFIGTABLE OR ALLFAST OR ARM_SIN_COS_Q31) +target_sources(CMSISDSPController PRIVATE arm_sin_cos_q31.c) +endif() + + + +### Includes +target_include_directories(CMSISDSPController PUBLIC "${DSP}/../../Include") + + + diff --git a/DSP/Source/ControllerFunctions/ControllerFunctions.c b/DSP/Source/ControllerFunctions/ControllerFunctions.c new file mode 100644 index 0000000..51720bc --- /dev/null +++ b/DSP/Source/ControllerFunctions/ControllerFunctions.c @@ -0,0 +1,37 @@ +/* ---------------------------------------------------------------------- + * Project: CMSIS DSP Library + * Title: ControllerFunctions.c + * Description: Combination of all controller function source files. + * + * $Date: 18. March 2019 + * $Revision: V1.0.0 + * + * Target Processor: Cortex-M cores + * -------------------------------------------------------------------- */ +/* + * Copyright (C) 2019 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "arm_pid_init_f32.c" +#include "arm_pid_init_q15.c" +#include "arm_pid_init_q31.c" +#include "arm_pid_reset_f32.c" +#include "arm_pid_reset_q15.c" +#include "arm_pid_reset_q31.c" +#include "arm_sin_cos_f32.c" +#include "arm_sin_cos_q31.c" + diff --git a/DSP/Source/ControllerFunctions/arm_pid_init_f32.c b/DSP/Source/ControllerFunctions/arm_pid_init_f32.c index f75d61f..433a65a 100644 --- a/DSP/Source/ControllerFunctions/arm_pid_init_f32.c +++ b/DSP/Source/ControllerFunctions/arm_pid_init_f32.c @@ -3,13 +3,13 @@ * Title: arm_pid_init_f32.c * Description: Floating-point PID Control initialization function * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,29 +28,30 @@ #include "arm_math.h" - /** - * @addtogroup PID - * @{ +/** + @addtogroup PID + @{ */ /** - * @brief Initialization function for the floating-point PID Control. - * @param[in,out] *S points to an instance of the PID structure. - * @param[in] resetStateFlag flag to reset the state. 0 = no change in state & 1 = reset the state. - * @return none. - * \par Description: - * \par - * The <code>resetStateFlag</code> specifies whether to set state to zero or not. \n - * The function computes the structure fields: <code>A0</code>, <code>A1</code> <code>A2</code> - * using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd) - * also sets the state variables to all zeros. + @brief Initialization function for the floating-point PID Control. + @param[in,out] S points to an instance of the PID structure + @param[in] resetStateFlag + - value = 0: no change in state + - value = 1: reset state + @return none + + @par Details + The <code>resetStateFlag</code> specifies whether to set state to zero or not. \n + The function computes the structure fields: <code>A0</code>, <code>A1</code> <code>A2</code> + using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd) + also sets the state variables to all zeros. */ void arm_pid_init_f32( arm_pid_instance_f32 * S, int32_t resetStateFlag) { - /* Derived coefficient A0 */ S->A0 = S->Kp + S->Ki + S->Kd; @@ -63,12 +64,12 @@ void arm_pid_init_f32( /* Check whether state needs reset or not */ if (resetStateFlag) { - /* Clear the state buffer. The size will be always 3 samples */ + /* Reset state to zero, The size will be always 3 samples */ memset(S->state, 0, 3U * sizeof(float32_t)); } } /** - * @} end of PID group + @} end of PID group */ diff --git a/DSP/Source/ControllerFunctions/arm_pid_init_q15.c b/DSP/Source/ControllerFunctions/arm_pid_init_q15.c index 61049cf..c88a3d9 100644 --- a/DSP/Source/ControllerFunctions/arm_pid_init_q15.c +++ b/DSP/Source/ControllerFunctions/arm_pid_init_q15.c @@ -3,13 +3,13 @@ * Title: arm_pid_init_q15.c * Description: Q15 PID Control initialization function * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,22 +28,24 @@ #include "arm_math.h" - /** - * @addtogroup PID - * @{ +/** + @addtogroup PID + @{ */ /** - * @details - * @param[in,out] *S points to an instance of the Q15 PID structure. - * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. - * @return none. - * \par Description: - * \par - * The <code>resetStateFlag</code> specifies whether to set state to zero or not. \n - * The function computes the structure fields: <code>A0</code>, <code>A1</code> <code>A2</code> - * using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd) - * also sets the state variables to all zeros. + @brief Initialization function for the Q15 PID Control. + @param[in,out] S points to an instance of the Q15 PID structure + @param[in] resetStateFlag + - value = 0: no change in state + - value = 1: reset state + @return none + + @par Details + The <code>resetStateFlag</code> specifies whether to set state to zero or not. \n + The function computes the structure fields: <code>A0</code>, <code>A1</code> <code>A2</code> + using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd) + also sets the state variables to all zeros. */ void arm_pid_init_q15( @@ -53,35 +55,20 @@ void arm_pid_init_q15( #if defined (ARM_MATH_DSP) - /* Run the below code for Cortex-M4 and Cortex-M3 */ - /* Derived coefficient A0 */ S->A0 = __QADD16(__QADD16(S->Kp, S->Ki), S->Kd); /* Derived coefficients and pack into A1 */ #ifndef ARM_MATH_BIG_ENDIAN - S->A1 = __PKHBT(-__QADD16(__QADD16(S->Kd, S->Kd), S->Kp), S->Kd, 16); - #else - S->A1 = __PKHBT(S->Kd, -__QADD16(__QADD16(S->Kd, S->Kd), S->Kp), 16); - -#endif /* #ifndef ARM_MATH_BIG_ENDIAN */ - - /* Check whether state needs reset or not */ - if (resetStateFlag) - { - /* Clear the state buffer. The size will be always 3 samples */ - memset(S->state, 0, 3U * sizeof(q15_t)); - } +#endif #else - /* Run the below code for Cortex-M0 */ - - q31_t temp; /*to store the sum */ + q31_t temp; /* to store the sum */ /* Derived coefficient A0 */ temp = S->Kp + S->Ki + S->Kd; @@ -92,19 +79,17 @@ void arm_pid_init_q15( S->A1 = (q15_t) __SSAT(temp, 16); S->A2 = S->Kd; - +#endif /* #if defined (ARM_MATH_DSP) */ /* Check whether state needs reset or not */ if (resetStateFlag) { - /* Clear the state buffer. The size will be always 3 samples */ + /* Reset state to zero, The size will be always 3 samples */ memset(S->state, 0, 3U * sizeof(q15_t)); } -#endif /* #if defined (ARM_MATH_DSP) */ - } /** - * @} end of PID group + @} end of PID group */ diff --git a/DSP/Source/ControllerFunctions/arm_pid_init_q31.c b/DSP/Source/ControllerFunctions/arm_pid_init_q31.c index 17b3b09..1625a5f 100644 --- a/DSP/Source/ControllerFunctions/arm_pid_init_q31.c +++ b/DSP/Source/ControllerFunctions/arm_pid_init_q31.c @@ -3,13 +3,13 @@ * Title: arm_pid_init_q31.c * Description: Q31 PID Control initialization function * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,22 +28,24 @@ #include "arm_math.h" - /** - * @addtogroup PID - * @{ +/** + @addtogroup PID + @{ */ /** - * @brief Initialization function for the Q31 PID Control. - * @param[in,out] *S points to an instance of the Q31 PID structure. - * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. - * @return none. - * \par Description: - * \par - * The <code>resetStateFlag</code> specifies whether to set state to zero or not. \n - * The function computes the structure fields: <code>A0</code>, <code>A1</code> <code>A2</code> - * using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd) - * also sets the state variables to all zeros. + @brief Initialization function for the Q31 PID Control. + @param[in,out] S points to an instance of the Q31 PID structure + @param[in] resetStateFlag + - value = 0: no change in state + - value = 1: reset state + @return none + + @par Details + The <code>resetStateFlag</code> specifies whether to set state to zero or not. \n + The function computes the structure fields: <code>A0</code>, <code>A1</code> <code>A2</code> + using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd) + also sets the state variables to all zeros. */ void arm_pid_init_q31( @@ -53,20 +55,15 @@ void arm_pid_init_q31( #if defined (ARM_MATH_DSP) - /* Run the below code for Cortex-M4 and Cortex-M3 */ - /* Derived coefficient A0 */ S->A0 = __QADD(__QADD(S->Kp, S->Ki), S->Kd); /* Derived coefficient A1 */ S->A1 = -__QADD(__QADD(S->Kd, S->Kd), S->Kp); - #else - /* Run the below code for Cortex-M0 */ - - q31_t temp; + q31_t temp; /* to store the sum */ /* Derived coefficient A0 */ temp = clip_q63_to_q31((q63_t) S->Kp + S->Ki); @@ -84,12 +81,12 @@ void arm_pid_init_q31( /* Check whether state needs reset or not */ if (resetStateFlag) { - /* Clear the state buffer. The size will be always 3 samples */ + /* Reset state to zero, The size will be always 3 samples */ memset(S->state, 0, 3U * sizeof(q31_t)); } } /** - * @} end of PID group + @} end of PID group */ diff --git a/DSP/Source/ControllerFunctions/arm_pid_reset_f32.c b/DSP/Source/ControllerFunctions/arm_pid_reset_f32.c index 318ec89..d839e55 100644 --- a/DSP/Source/ControllerFunctions/arm_pid_reset_f32.c +++ b/DSP/Source/ControllerFunctions/arm_pid_reset_f32.c @@ -3,13 +3,13 @@ * Title: arm_pid_reset_f32.c * Description: Floating-point PID Control reset function * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,26 +28,27 @@ #include "arm_math.h" - /** - * @addtogroup PID - * @{ +/** + @addtogroup PID + @{ */ /** -* @brief Reset function for the floating-point PID Control. -* @param[in] *S Instance pointer of PID control data structure. -* @return none. -* \par Description: -* The function resets the state buffer to zeros. -*/ + @brief Reset function for the floating-point PID Control. + @param[in,out] S points to an instance of the floating-point PID structure + @return none + + @par Details + The function resets the state buffer to zeros. + */ + void arm_pid_reset_f32( arm_pid_instance_f32 * S) { - - /* Clear the state buffer. The size will be always 3 samples */ + /* Reset state to zero, The size will be always 3 samples */ memset(S->state, 0, 3U * sizeof(float32_t)); } /** - * @} end of PID group + @} end of PID group */ diff --git a/DSP/Source/ControllerFunctions/arm_pid_reset_q15.c b/DSP/Source/ControllerFunctions/arm_pid_reset_q15.c index 93c0e7c..256fd8c 100644 --- a/DSP/Source/ControllerFunctions/arm_pid_reset_q15.c +++ b/DSP/Source/ControllerFunctions/arm_pid_reset_q15.c @@ -3,13 +3,13 @@ * Title: arm_pid_reset_q15.c * Description: Q15 PID Control reset function * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,18 +28,20 @@ #include "arm_math.h" - /** - * @addtogroup PID - * @{ +/** + @addtogroup PID + @{ */ /** -* @brief Reset function for the Q15 PID Control. -* @param[in] *S Instance pointer of PID control data structure. -* @return none. -* \par Description: -* The function resets the state buffer to zeros. -*/ + @brief Reset function for the Q15 PID Control. + @param[in,out] S points to an instance of the Q15 PID structure + @return none + + @par Details + The function resets the state buffer to zeros. + */ + void arm_pid_reset_q15( arm_pid_instance_q15 * S) { @@ -48,5 +50,5 @@ void arm_pid_reset_q15( } /** - * @} end of PID group + @} end of PID group */ diff --git a/DSP/Source/ControllerFunctions/arm_pid_reset_q31.c b/DSP/Source/ControllerFunctions/arm_pid_reset_q31.c index 4c5b14e..2aa391c 100644 --- a/DSP/Source/ControllerFunctions/arm_pid_reset_q31.c +++ b/DSP/Source/ControllerFunctions/arm_pid_reset_q31.c @@ -3,13 +3,13 @@ * Title: arm_pid_reset_q31.c * Description: Q31 PID Control reset function * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,26 +28,27 @@ #include "arm_math.h" - /** - * @addtogroup PID - * @{ +/** + @addtogroup PID + @{ */ /** -* @brief Reset function for the Q31 PID Control. -* @param[in] *S Instance pointer of PID control data structure. -* @return none. -* \par Description: -* The function resets the state buffer to zeros. -*/ + @brief Reset function for the Q31 PID Control. + @param[in,out] S points to an instance of the Q31 PID structure + @return none + + @par Details + The function resets the state buffer to zeros. + */ + void arm_pid_reset_q31( arm_pid_instance_q31 * S) { - - /* Clear the state buffer. The size will be always 3 samples */ + /* Reset state to zero, The size will be always 3 samples */ memset(S->state, 0, 3U * sizeof(q31_t)); } /** - * @} end of PID group + @} end of PID group */ diff --git a/DSP/Source/ControllerFunctions/arm_sin_cos_f32.c b/DSP/Source/ControllerFunctions/arm_sin_cos_f32.c index 7ec1b53..12a1c83 100644 --- a/DSP/Source/ControllerFunctions/arm_sin_cos_f32.c +++ b/DSP/Source/ControllerFunctions/arm_sin_cos_f32.c @@ -3,13 +3,13 @@ * Title: arm_sin_cos_f32.c * Description: Sine and Cosine calculation for floating-point values * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -30,115 +30,117 @@ #include "arm_common_tables.h" /** - * @ingroup groupController + @ingroup groupController */ /** - * @defgroup SinCos Sine Cosine - * - * Computes the trigonometric sine and cosine values using a combination of table lookup - * and linear interpolation. - * There are separate functions for Q31 and floating-point data types. - * The input to the floating-point version is in degrees while the - * fixed-point Q31 have a scaled input with the range - * [-1 0.9999] mapping to [-180 +180] degrees. - * - * The floating point function also allows values that are out of the usual range. When this happens, the function will - * take extra time to adjust the input value to the range of [-180 180]. - * - * The result is accurate to 5 digits after the decimal point. - * - * The implementation is based on table lookup using 360 values together with linear interpolation. - * The steps used are: - * -# Calculation of the nearest integer table index. - * -# Compute the fractional portion (fract) of the input. - * -# Fetch the value corresponding to \c index from sine table to \c y0 and also value from \c index+1 to \c y1. - * -# Sine value is computed as <code> *psinVal = y0 + (fract * (y1 - y0))</code>. - * -# Fetch the value corresponding to \c index from cosine table to \c y0 and also value from \c index+1 to \c y1. - * -# Cosine value is computed as <code> *pcosVal = y0 + (fract * (y1 - y0))</code>. + @defgroup SinCos Sine Cosine + + Computes the trigonometric sine and cosine values using a combination of table lookup + and linear interpolation. + There are separate functions for Q31 and floating-point data types. + The input to the floating-point version is in degrees while the + fixed-point Q31 have a scaled input with the range + [-1 0.9999] mapping to [-180 +180] degrees. + + The floating point function also allows values that are out of the usual range. When this happens, the function will + take extra time to adjust the input value to the range of [-180 180]. + + The result is accurate to 5 digits after the decimal point. + + The implementation is based on table lookup using 360 values together with linear interpolation. + The steps used are: + -# Calculation of the nearest integer table index. + -# Compute the fractional portion (fract) of the input. + -# Fetch the value corresponding to \c index from sine table to \c y0 and also value from \c index+1 to \c y1. + -# Sine value is computed as <code> *psinVal = y0 + (fract * (y1 - y0))</code>. + -# Fetch the value corresponding to \c index from cosine table to \c y0 and also value from \c index+1 to \c y1. + -# Cosine value is computed as <code> *pcosVal = y0 + (fract * (y1 - y0))</code>. */ - /** - * @addtogroup SinCos - * @{ +/** + @addtogroup SinCos + @{ */ /** - * @brief Floating-point sin_cos function. - * @param[in] theta input value in degrees - * @param[out] *pSinVal points to the processed sine output. - * @param[out] *pCosVal points to the processed cos output. - * @return none. + @brief Floating-point sin_cos function. + @param[in] theta input value in degrees + @param[out] pSinVal points to processed sine output + @param[out] pCosVal points to processed cosine output + @return none */ void arm_sin_cos_f32( - float32_t theta, - float32_t * pSinVal, - float32_t * pCosVal) + float32_t theta, + float32_t * pSinVal, + float32_t * pCosVal) { - float32_t fract, in; /* Temporary variables for input, output */ - uint16_t indexS, indexC; /* Index variable */ - float32_t f1, f2, d1, d2; /* Two nearest output values */ - float32_t findex, Dn, Df, temp; + float32_t fract, in; /* Temporary input, output variables */ + uint16_t indexS, indexC; /* Index variable */ + float32_t f1, f2, d1, d2; /* Two nearest output values */ + float32_t Dn, Df; + float32_t temp, findex; - /* input x is in degrees */ - /* Scale the input, divide input by 360, for cosine add 0.25 (pi/2) to read sine table */ - in = theta * 0.00277777777778f; + /* input x is in degrees */ + /* Scale input, divide input by 360, for cosine add 0.25 (pi/2) to read sine table */ + in = theta * 0.00277777777778f; - if (in < 0.0f) - { - in = -in; - } + if (in < 0.0f) + { + in = -in; + } - in = in - (int32_t)in; + in = in - (int32_t)in; - /* Calculation of index of the table */ - findex = (float32_t) FAST_MATH_TABLE_SIZE * in; - indexS = ((uint16_t)findex) & 0x1ff; - indexC = (indexS + (FAST_MATH_TABLE_SIZE / 4)) & 0x1ff; + /* Calculate the nearest index */ + findex = (float32_t)FAST_MATH_TABLE_SIZE * in; + indexS = ((uint16_t)findex) & 0x1ff; + indexC = (indexS + (FAST_MATH_TABLE_SIZE / 4)) & 0x1ff; - /* fractional value calculation */ - fract = findex - (float32_t) indexS; + /* Calculation of fractional value */ + fract = findex - (float32_t) indexS; - /* Read two nearest values of input value from the cos & sin tables */ - f1 = sinTable_f32[indexC+0]; - f2 = sinTable_f32[indexC+1]; - d1 = -sinTable_f32[indexS+0]; - d2 = -sinTable_f32[indexS+1]; + /* Read two nearest values of input value from the cos & sin tables */ + f1 = sinTable_f32[indexC ]; + f2 = sinTable_f32[indexC+1]; + d1 = -sinTable_f32[indexS ]; + d2 = -sinTable_f32[indexS+1]; - temp = (1.0f - fract) * f1 + fract * f2; + temp = (1.0f - fract) * f1 + fract * f2; - Dn = 0.0122718463030f; // delta between the two points (fixed), in this case 2*pi/FAST_MATH_TABLE_SIZE - Df = f2 - f1; // delta between the values of the functions + Dn = 0.0122718463030f; /* delta between the two points (fixed), in this case 2*pi/FAST_MATH_TABLE_SIZE */ + Df = f2 - f1; /* delta between the values of the functions */ - temp = Dn *(d1 + d2) - 2 * Df; - temp = fract * temp + (3 * Df - (d2 + 2 * d1) * Dn); - temp = fract * temp + d1 * Dn; + temp = Dn * (d1 + d2) - 2 * Df; + temp = fract * temp + (3 * Df - (d2 + 2 * d1) * Dn); + temp = fract * temp + d1 * Dn; - /* Calculation of cosine value */ - *pCosVal = fract * temp + f1; + /* Calculation of cosine value */ + *pCosVal = fract * temp + f1; - /* Read two nearest values of input value from the cos & sin tables */ - f1 = sinTable_f32[indexS+0]; - f2 = sinTable_f32[indexS+1]; - d1 = sinTable_f32[indexC+0]; - d2 = sinTable_f32[indexC+1]; + /* Read two nearest values of input value from the cos & sin tables */ + f1 = sinTable_f32[indexS ]; + f2 = sinTable_f32[indexS+1]; + d1 = sinTable_f32[indexC ]; + d2 = sinTable_f32[indexC+1]; - temp = (1.0f - fract) * f1 + fract * f2; + temp = (1.0f - fract) * f1 + fract * f2; - Df = f2 - f1; // delta between the values of the functions - temp = Dn*(d1 + d2) - 2*Df; - temp = fract*temp + (3*Df - (d2 + 2*d1)*Dn); - temp = fract*temp + d1*Dn; + Df = f2 - f1; // delta between the values of the functions + temp = Dn * (d1 + d2) - 2 * Df; + temp = fract * temp + (3 * Df - (d2 + 2 * d1) * Dn); + temp = fract * temp + d1 * Dn; - /* Calculation of sine value */ - *pSinVal = fract*temp + f1; + /* Calculation of sine value */ + *pSinVal = fract * temp + f1; - if (theta < 0.0f) - { - *pSinVal = -*pSinVal; - } + if (theta < 0.0f) + { + *pSinVal = -*pSinVal; + } } + /** - * @} end of SinCos group + @} end of SinCos group */ diff --git a/DSP/Source/ControllerFunctions/arm_sin_cos_q31.c b/DSP/Source/ControllerFunctions/arm_sin_cos_q31.c index d661830..84ee3d2 100644 --- a/DSP/Source/ControllerFunctions/arm_sin_cos_q31.c +++ b/DSP/Source/ControllerFunctions/arm_sin_cos_q31.c @@ -3,13 +3,13 @@ * Title: arm_sin_cos_q31.c * Description: Cosine & Sine calculation for Q31 values * - * $Date: 27. January 2017 - * $Revision: V.1.5.1 + * $Date: 18. March 2019 + * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* - * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. + * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -30,23 +30,22 @@ #include "arm_common_tables.h" /** - * @ingroup groupController + @ingroup groupController */ - /** - * @addtogroup SinCos - * @{ +/** + @addtogroup SinCos + @{ */ /** - * @brief Q31 sin_cos function. - * @param[in] theta scaled input value in degrees - * @param[out] *pSinVal points to the processed sine output. - * @param[out] *pCosVal points to the processed cosine output. - * @return none. - * - * The Q31 input value is in the range [-1 0.999999] and is mapped to a degree value in the range [-180 179]. - * + @brief Q31 sin_cos function. + @param[in] theta scaled input value in degrees + @param[out] pSinVal points to processed sine output + @param[out] pCosVal points to processed cosine output + @return none + + The Q31 input value is in the range [-1 0.999999] and is mapped to a degree value in the range [-180 179]. */ void arm_sin_cos_q31( @@ -54,9 +53,9 @@ void arm_sin_cos_q31( q31_t * pSinVal, q31_t * pCosVal) { - q31_t fract; /* Temporary variables for input, output */ - uint16_t indexS, indexC; /* Index variable */ - q31_t f1, f2, d1, d2; /* Two nearest output values */ + q31_t fract; /* Temporary input, output variables */ + uint16_t indexS, indexC; /* Index variable */ + q31_t f1, f2, d1, d2; /* Two nearest output values */ q31_t Dn, Df; q63_t temp; @@ -68,43 +67,44 @@ void arm_sin_cos_q31( fract = (theta - (indexS << CONTROLLER_Q31_SHIFT)) << 8; /* Read two nearest values of input value from the cos & sin tables */ - f1 = sinTable_q31[indexC+0]; - f2 = sinTable_q31[indexC+1]; - d1 = -sinTable_q31[indexS+0]; + f1 = sinTable_q31[indexC ]; + f2 = sinTable_q31[indexC+1]; + d1 = -sinTable_q31[indexS ]; d2 = -sinTable_q31[indexS+1]; - Dn = 0x1921FB5; // delta between the two points (fixed), in this case 2*pi/FAST_MATH_TABLE_SIZE - Df = f2 - f1; // delta between the values of the functions - temp = Dn*((q63_t)d1 + d2); + Dn = 0x1921FB5; /* delta between the two points (fixed), in this case 2*pi/FAST_MATH_TABLE_SIZE */ + Df = f2 - f1; /* delta between the values of the functions */ + + temp = Dn * ((q63_t)d1 + d2); temp = temp - ((q63_t)Df << 32); - temp = (q63_t)fract*(temp >> 31); - temp = temp + ((3*(q63_t)Df << 31) - (d2 + ((q63_t)d1 << 1))*Dn); - temp = (q63_t)fract*(temp >> 31); - temp = temp + (q63_t)d1*Dn; - temp = (q63_t)fract*(temp >> 31); + temp = (q63_t)fract * (temp >> 31); + temp = temp + ((3 * (q63_t)Df << 31) - (d2 + ((q63_t)d1 << 1)) * Dn); + temp = (q63_t)fract * (temp >> 31); + temp = temp + (q63_t)d1 * Dn; + temp = (q63_t)fract * (temp >> 31); /* Calculation of cosine value */ *pCosVal = clip_q63_to_q31((temp >> 31) + (q63_t)f1); /* Read two nearest values of input value from the cos & sin tables */ - f1 = sinTable_q31[indexS+0]; + f1 = sinTable_q31[indexS ]; f2 = sinTable_q31[indexS+1]; - d1 = sinTable_q31[indexC+0]; + d1 = sinTable_q31[indexC ]; d2 = sinTable_q31[indexC+1]; Df = f2 - f1; // delta between the values of the functions - temp = Dn*((q63_t)d1 + d2); + temp = Dn * ((q63_t)d1 + d2); temp = temp - ((q63_t)Df << 32); - temp = (q63_t)fract*(temp >> 31); - temp = temp + ((3*(q63_t)Df << 31) - (d2 + ((q63_t)d1 << 1))*Dn); - temp = (q63_t)fract*(temp >> 31); - temp = temp + (q63_t)d1*Dn; - temp = (q63_t)fract*(temp >> 31); + temp = (q63_t)fract * (temp >> 31); + temp = temp + ((3 * (q63_t)Df << 31) - (d2 + ((q63_t)d1 << 1)) * Dn); + temp = (q63_t)fract * (temp >> 31); + temp = temp + (q63_t)d1 * Dn; + temp = (q63_t)fract * (temp >> 31); /* Calculation of sine value */ *pSinVal = clip_q63_to_q31((temp >> 31) + (q63_t)f1); } /** - * @} end of SinCos group + @} end of SinCos group */ |