Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
arm_pid_init_q15.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_pid_init_q15.c 00004 * Description: Q15 PID Control initialization function 00005 * 00006 * $Date: 27. January 2017 00007 * $Revision: V.1.5.1 00008 * 00009 * Target Processor: Cortex-M cores 00010 * -------------------------------------------------------------------- */ 00011 /* 00012 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 00013 * 00014 * SPDX-License-Identifier: Apache-2.0 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the License); you may 00017 * not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * www.apache.org/licenses/LICENSE-2.0 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00024 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 */ 00028 00029 #include "arm_math.h" 00030 00031 /** 00032 * @addtogroup PID 00033 * @{ 00034 */ 00035 00036 /** 00037 * @details 00038 * @param[in,out] *S points to an instance of the Q15 PID structure. 00039 * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. 00040 * @return none. 00041 * \par Description: 00042 * \par 00043 * The <code>resetStateFlag</code> specifies whether to set state to zero or not. \n 00044 * The function computes the structure fields: <code>A0</code>, <code>A1</code> <code>A2</code> 00045 * using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd) 00046 * also sets the state variables to all zeros. 00047 */ 00048 00049 void arm_pid_init_q15( 00050 arm_pid_instance_q15 * S, 00051 int32_t resetStateFlag) 00052 { 00053 00054 #if defined (ARM_MATH_DSP) 00055 00056 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00057 00058 /* Derived coefficient A0 */ 00059 S->A0 = __QADD16(__QADD16(S->Kp, S->Ki), S->Kd); 00060 00061 /* Derived coefficients and pack into A1 */ 00062 00063 #ifndef ARM_MATH_BIG_ENDIAN 00064 00065 S->A1 = __PKHBT(-__QADD16(__QADD16(S->Kd, S->Kd), S->Kp), S->Kd, 16); 00066 00067 #else 00068 00069 S->A1 = __PKHBT(S->Kd, -__QADD16(__QADD16(S->Kd, S->Kd), S->Kp), 16); 00070 00071 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ 00072 00073 /* Check whether state needs reset or not */ 00074 if (resetStateFlag) 00075 { 00076 /* Clear the state buffer. The size will be always 3 samples */ 00077 memset(S->state, 0, 3U * sizeof(q15_t)); 00078 } 00079 00080 #else 00081 00082 /* Run the below code for Cortex-M0 */ 00083 00084 q31_t temp; /*to store the sum */ 00085 00086 /* Derived coefficient A0 */ 00087 temp = S->Kp + S->Ki + S->Kd; 00088 S->A0 = (q15_t) __SSAT(temp, 16); 00089 00090 /* Derived coefficients and pack into A1 */ 00091 temp = -(S->Kd + S->Kd + S->Kp); 00092 S->A1 = (q15_t) __SSAT(temp, 16); 00093 S->A2 = S->Kd; 00094 00095 00096 00097 /* Check whether state needs reset or not */ 00098 if (resetStateFlag) 00099 { 00100 /* Clear the state buffer. The size will be always 3 samples */ 00101 memset(S->state, 0, 3U * sizeof(q15_t)); 00102 } 00103 00104 #endif /* #if defined (ARM_MATH_DSP) */ 00105 00106 } 00107 00108 /** 00109 * @} end of PID group 00110 */ 00111
Generated on Tue Jul 12 2022 16:47:27 by
1.7.2