CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details

Dependents:   K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more

Committer:
simon
Date:
Thu Mar 10 15:07:50 2011 +0000
Revision:
0:1014af42efd9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:1014af42efd9 1 /* ----------------------------------------------------------------------
simon 0:1014af42efd9 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
simon 0:1014af42efd9 3 *
simon 0:1014af42efd9 4 * $Date: 29. November 2010
simon 0:1014af42efd9 5 * $Revision: V1.0.3
simon 0:1014af42efd9 6 *
simon 0:1014af42efd9 7 * Project: CMSIS DSP Library
simon 0:1014af42efd9 8 * Title: arm_pid_init_q15.c
simon 0:1014af42efd9 9 *
simon 0:1014af42efd9 10 * Description: Q15 PID Control initialization function
simon 0:1014af42efd9 11 *
simon 0:1014af42efd9 12 * Target Processor: Cortex-M4/Cortex-M3
simon 0:1014af42efd9 13 *
simon 0:1014af42efd9 14 * Version 1.0.3 2010/11/29
simon 0:1014af42efd9 15 * Re-organized the CMSIS folders and updated documentation.
simon 0:1014af42efd9 16 *
simon 0:1014af42efd9 17 * Version 1.0.2 2010/11/11
simon 0:1014af42efd9 18 * Documentation updated.
simon 0:1014af42efd9 19 *
simon 0:1014af42efd9 20 * Version 1.0.1 2010/10/05
simon 0:1014af42efd9 21 * Production release and review comments incorporated.
simon 0:1014af42efd9 22 *
simon 0:1014af42efd9 23 * Version 1.0.0 2010/09/20
simon 0:1014af42efd9 24 * Production release and review comments incorporated.
simon 0:1014af42efd9 25 * -------------------------------------------------------------------- */
simon 0:1014af42efd9 26
simon 0:1014af42efd9 27 #include "arm_math.h"
simon 0:1014af42efd9 28
simon 0:1014af42efd9 29 /**
simon 0:1014af42efd9 30 * @addtogroup PID
simon 0:1014af42efd9 31 * @{
simon 0:1014af42efd9 32 */
simon 0:1014af42efd9 33
simon 0:1014af42efd9 34 /**
simon 0:1014af42efd9 35 * @details
simon 0:1014af42efd9 36 * @param[in,out] *S points to an instance of the Q15 PID structure.
simon 0:1014af42efd9 37 * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state.
simon 0:1014af42efd9 38 * @return none.
simon 0:1014af42efd9 39 * \par Description:
simon 0:1014af42efd9 40 * \par
simon 0:1014af42efd9 41 * The <code>resetStateFlag</code> specifies whether to set state to zero or not. \n
simon 0:1014af42efd9 42 * The function computes the structure fields: <code>A0</code>, <code>A1</code> <code>A2</code>
simon 0:1014af42efd9 43 * using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd)
simon 0:1014af42efd9 44 * also sets the state variables to all zeros.
simon 0:1014af42efd9 45 */
simon 0:1014af42efd9 46
simon 0:1014af42efd9 47 void arm_pid_init_q15(
simon 0:1014af42efd9 48 arm_pid_instance_q15 * S,
simon 0:1014af42efd9 49 int32_t resetStateFlag)
simon 0:1014af42efd9 50 {
simon 0:1014af42efd9 51 /* Derived coefficient A0 */
simon 0:1014af42efd9 52 S->A0 = __QADD16(__QADD16(S->Kp, S->Ki), S->Kd);
simon 0:1014af42efd9 53
simon 0:1014af42efd9 54 /* Derived coefficients and pack into A1 */
simon 0:1014af42efd9 55 S->A1 = __PKHBT(-__QADD16(__QADD16(S->Kd, S->Kd), S->Kp), S->Kd, 16);
simon 0:1014af42efd9 56
simon 0:1014af42efd9 57 /* Check whether state needs reset or not */
simon 0:1014af42efd9 58 if(resetStateFlag)
simon 0:1014af42efd9 59 {
simon 0:1014af42efd9 60 /* Clear the state buffer. The size will be always 3 samples */
simon 0:1014af42efd9 61 memset(S->state, 0, 3u * sizeof(q15_t));
simon 0:1014af42efd9 62 }
simon 0:1014af42efd9 63
simon 0:1014af42efd9 64 }
simon 0:1014af42efd9 65
simon 0:1014af42efd9 66 /**
simon 0:1014af42efd9 67 * @} end of PID group
simon 0:1014af42efd9 68 */