Update repo
This commit is contained in:
1 parent
749dab5721
commit
ce65a0f59a
14950 files changed
+4408250
-1
No files matched your search
@@ -0,0 +1,422 @@
|
||||
/* DCL.h - C2000 Digital Control Library
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_H
|
||||
#define _C_DCL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! \file DCL.h
|
||||
//! \brief Contains the public interface to the common
|
||||
//! Digital Controller Library functions
|
||||
|
||||
//! \brief Library version number formatted for numerical comparison
|
||||
//!
|
||||
#define DCL_VERSION 3050000
|
||||
|
||||
#ifndef C2000_IEEE754_TYPES
|
||||
#define C2000_IEEE754_TYPES
|
||||
#ifdef __TI_EABI__
|
||||
typedef float float32_t;
|
||||
typedef double float64_t;
|
||||
#else
|
||||
typedef float float32_t;
|
||||
typedef long double float64_t;
|
||||
#endif // __TI_EABI__
|
||||
#endif // C2000_IEEE754_TYPES
|
||||
|
||||
#ifndef __TMS320C28XX_CLA__
|
||||
|
||||
#include <complex.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//! \brief Local definitions of mathematical constants
|
||||
//!
|
||||
#define CONST_PI_32 3.14159265358979323846f
|
||||
#define CONST_2PI_32 2.0f * CONST_PI_32
|
||||
|
||||
#define CONST_PI_64 3.1415926535897932384626433832795028841971693993751058209749445923078164062L
|
||||
#define CONST_2PI_64 2.0L * CONST_PI_64
|
||||
|
||||
//! \brief Defines 32-bit null address for pointer initialization
|
||||
//!
|
||||
#define NULL_ADDR 0x00000000
|
||||
|
||||
//! \brief Define the acceptable FPU numerical tolerances
|
||||
//!
|
||||
#define DEFAULT_FPU32_TOL 1.0e-06f
|
||||
#define DEFAULT_FPU64_TOL 1.0e-10f
|
||||
|
||||
//! \brief Determines numerical proximity to specified value
|
||||
//!
|
||||
#define F32_IS_VALUE(x,y) (((x < (y + DEFAULT_FPU32_TOL)) && (x > (y - DEFAULT_FPU32_TOL))) ? 1 : 0)
|
||||
#define F64_IS_VALUE(x,y) (((x < (y + DEFAULT_FPU64_TOL)) && (x > (y - DEFAULT_FPU64_TOL))) ? 1 : 0)
|
||||
|
||||
//! \brief Determines numerical proximity to zero
|
||||
//!
|
||||
#define F32_IS_ZERO(x) F32_IS_VALUE(x,0.0f)
|
||||
#define F64_IS_ZERO(x) F64_IS_VALUE(x,0.0L)
|
||||
|
||||
//! \brief Returns a random floating point result between -1.0 and +1.0
|
||||
//! where 'a' is a single or double precision float.
|
||||
//! Useful for initialization of arrays and matrices during test.
|
||||
//! Ensure compiler switch "--fp_mode = relaxed" is set to ensure h/w division.
|
||||
//!
|
||||
//! \code
|
||||
//! float32_t s = DCL_randf(1.0f);
|
||||
//!
|
||||
#define DCL_randf(a) (a * ((float32_t) rand() / (float32_t) (RAND_MAX >> 1) - 1.0f))
|
||||
#define DCL_randf64(a) (a * ((float64_t) rand() / (float64_t) (RAND_MAX >> 1) - 1.0L))
|
||||
|
||||
//! \brief Defines the lower limit on derivative filter coefficient c2
|
||||
//! in order for fc to lie below the Nyquist frequency
|
||||
//!
|
||||
#define DCL_C2_LIMIT_32 ((2.0f - CONST_PI_32) / (2.0f + CONST_PI_32))
|
||||
#define DCL_C2_LIMIT_64 ((2.0L - CONST_PI_64) / (2.0L + CONST_PI_64))
|
||||
|
||||
//! \brief Define the default control period in seconds
|
||||
//!
|
||||
#define DCL_DEFAULT_T_F32 100.0e-06f
|
||||
#define DCL_DEFAULT_T_F64 100.0e-06L
|
||||
|
||||
//! \brief Build the library with controller test points enabled
|
||||
//!
|
||||
#define DCL_TESTPOINTS_ENABLED
|
||||
|
||||
//! \brief Build the library with break points enabled
|
||||
//!
|
||||
#define DCL_BREAK_POINTS_ENABLED
|
||||
|
||||
//! \brief Defines a debug break point
|
||||
//!
|
||||
#ifdef DCL_BREAK_POINTS_ENABLED
|
||||
#define DCL_BREAK_POINT asm(" ESTOP0")
|
||||
#else
|
||||
#define DCL_BREAK_POINT ;
|
||||
#endif
|
||||
|
||||
//! \brief Boundary instructions for atomic code blocks
|
||||
//! Global interrupt mask is set at start of atomic block and
|
||||
//! restored to its' original value at the end
|
||||
//!
|
||||
#ifdef __TMS320C28XX__
|
||||
#define DCL_DISABLE_INTS DCL_disableInts()
|
||||
#define DCL_RESTORE_INTS(v) DCL_restoreInts(v)
|
||||
|
||||
//! \brief Sets global interrupts mask
|
||||
//! \return Original ST1 register value
|
||||
//!
|
||||
static inline int16_t DCL_disableInts(void)
|
||||
{
|
||||
return __disable_interrupts();
|
||||
}
|
||||
|
||||
//! \brief Restores global interrupts if they were previously enabled
|
||||
//! \param[in] v Original ST1 register value
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_restoreInts(int16_t v)
|
||||
{
|
||||
if (0 == (v & 0x1))
|
||||
{
|
||||
__enable_interrupts();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#define DCL_DISABLE_INTS 0
|
||||
#define DCL_RESTORE_INTS(v) ;
|
||||
#warning "CPU not recognized. Parameter updates may not be atomic."
|
||||
#endif
|
||||
|
||||
//--- Controller Common Support Structure ------------------------------------
|
||||
|
||||
//! \brief Defines the controller common support structure
|
||||
//!
|
||||
//! \details The CSS is accessed via a pointer in most of the DCL
|
||||
//! controller structs. It contains data used for testing and
|
||||
//! configuring the controller, as well as for error checking.
|
||||
//!
|
||||
typedef struct dcl_css {
|
||||
float32_t tpt; //!< Test point
|
||||
float32_t T; //!< Controller period in seconds
|
||||
uint32_t sts; //!< Status word
|
||||
uint32_t err; //!< Error code
|
||||
uint32_t loc; //!< Error location
|
||||
} DCL_CSS;
|
||||
|
||||
//! \brief Default values to initialize the CSS structure
|
||||
//!
|
||||
#define DCL_CSS_DEFAULTS { 0.0f, DCL_DEFAULT_T_F32, 0UL, 0UL, 0UL }
|
||||
|
||||
//! \brief Loads the controller period in the CSS
|
||||
//! CSS pointer must be configured first
|
||||
//! \param[in] p Pointer to the controller structure
|
||||
//! \param[in] a Sample period in seconds
|
||||
//! \return None
|
||||
//!
|
||||
#define DCL_SET_CONTROLLER_PERIOD(p,a) ((p)->css->T = a)
|
||||
|
||||
//! \brief Re-definition of legacy controller period call
|
||||
//!
|
||||
#define DCL_SET_SAMPLE_RATE DCL_SET_CONTROLLER_PERIOD
|
||||
|
||||
|
||||
//--- Status word ------------------------------------------------------------
|
||||
|
||||
//! \brief Defines the library enumerated status bits
|
||||
//!
|
||||
//! \details To perform a safe parameter update, the user first loads new
|
||||
//! parameters into the controller shadow parameter set, then sets
|
||||
//! the STS_UPDATE_PENDING bit in the controller status word. The
|
||||
//! next call to the update function performs the "shadow-to-
|
||||
//! active" set copy while global interrupts are disabled.
|
||||
//!
|
||||
enum dcl_status_bits {
|
||||
STS_NONE = 0UL, //!< Status empty
|
||||
STS_UPDATE_PENDING = (1U << 0), //!< Parameter update pending
|
||||
STS_CONTROLLER_RUNNING = (1U << 1), //!< Controller operation in progress
|
||||
STS_ADJUSTMENT_RUNNING = (1U << 2) //!< Parameter adjustment in progress
|
||||
};
|
||||
|
||||
//! \brief Macros to set the update flag in the status word to initiate
|
||||
//! controller parameter update on next DCL_update() call, and to
|
||||
//! clear the flag on completion.
|
||||
//!
|
||||
#define DCL_REQUEST_UPDATE(p) ((p)->css->sts |= STS_UPDATE_PENDING)
|
||||
#define DCL_CLEAR_UPDATE_REQUEST(p) ((p)->css->sts &= ~STS_UPDATE_PENDING)
|
||||
|
||||
//! \brief Macro to determine whether a parameter update is pending
|
||||
//! based on the STS_UPDATE_PENDING bit in the status word.
|
||||
#define DCL_UPDATE_WAITING(p) (0U != ((p)->css->sts & STS_UPDATE_PENDING))
|
||||
|
||||
//! \brief Macros placed at the beginning and end of the controller
|
||||
//! so that other functions know a control operation is in
|
||||
//! progress. Typically only used with complex controllers
|
||||
//! which may not be atomic.
|
||||
//!
|
||||
#define DCL_CONTROLLER_BEGIN(p) ((p)->css->sts |= STS_CONTROLLER_RUNNING)
|
||||
#define DCL_CONTROLLER_END(p) ((p)->css->sts &= ~STS_CONTROLLER_RUNNING)
|
||||
|
||||
//! \brief Macro to determine whether a controller is being executed
|
||||
//! based on the DCL_CONTROLLER_RUNNING bit in the status word.
|
||||
#define DCL_CONTROLLER_IN_PROGRESS(p) (0U != ((p)->css->sts & STS_CONTROLLER_RUNNING))
|
||||
|
||||
//! \brief Macros to set the flag in the status word to denote
|
||||
//! that parameter adjustment is in progress, and to
|
||||
//! clear the flag when the target is reached.
|
||||
//!
|
||||
#define DCL_ADJUSTMENT_RUNNING(p) ((p)->css->sts |= STS_ADJUSTMENT_RUNNING)
|
||||
#define DCL_ADJUSTMENT_COMPLETE(p) ((p)->css->sts &= ~STS_ADJUSTMENT_RUNNING)
|
||||
|
||||
//! \brief Macro to determine whether parameter adjustment is underway
|
||||
//! based on the DCL_ADJUSTMENT_RUNNING bit in the status word.
|
||||
#define DCL_ADJUSTMENT_IN_PROGRESS(p) (0U != ((p)->css->sts & STS_ADJUSTMENT_RUNNING))
|
||||
|
||||
|
||||
//--- Error handling ---------------------------------------------------------
|
||||
|
||||
//! \brief Build the library with error handling enabled
|
||||
//!
|
||||
#define DCL_ERROR_HANDLING_ENABLED
|
||||
|
||||
//! \brief Defines the library enumerated error codes
|
||||
//! These will be applied as bit masks in the error handler
|
||||
//!
|
||||
enum dcl_error_codes {
|
||||
ERR_NONE = 0U, //!< No error
|
||||
ERR_PARAM_RANGE = (1U << 0), //!< Parameter range exceeded
|
||||
ERR_PARAM_INVALID = (1U << 1), //!< Parameter not valid
|
||||
ERR_PARAM_WARN = (1U << 2), //!< Parameter warning
|
||||
ERR_INPUT_RANGE = (1U << 3), //!< Input range exceeded
|
||||
ERR_OVERFLOW = (1U << 4), //!< Numerical overflow
|
||||
ERR_UNDERFLOW = (1U << 5), //!< Numerical underflow
|
||||
ERR_VERSION = (1U << 6), //!< Incorrect DCL version
|
||||
ERR_DEVICE = (1U << 7), //!< Device not supported
|
||||
ERR_CONTROLLER = (1U << 8), //!< Controller operation not completed
|
||||
ERR_TIMING = (1U << 9), //!< Timing error
|
||||
ERR_COMPUTATION = (1U << 10) //!< Computation error
|
||||
};
|
||||
|
||||
//! \brief Macro to clear stored error code in CSS
|
||||
//!
|
||||
#define DCL_CLEAR_ERROR_CODE(p) (p->css->err = ERR_NONE)
|
||||
|
||||
//! \brief Macro to store code location of error in CSS
|
||||
//!
|
||||
#define DCL_GET_ERROR_LOC(n) (n->loc = (ERR_NONE == n->err) ? NULL_ADDR : __LINE__)
|
||||
|
||||
//! \brief Define error handling routine
|
||||
//!
|
||||
#define DCL_RUN_ERROR_HANDLER(n) DCL_runErrorHandler(n)
|
||||
|
||||
//! \brief Prototype for external basic error handler [DCL_error.c]
|
||||
//! \param[in] p Pointer to DCL_CSS structure
|
||||
//! \return None
|
||||
//!
|
||||
extern void DCL_runErrorHandler(DCL_CSS *p);
|
||||
|
||||
|
||||
//--- Polynomial stability functions -----------------------------------------
|
||||
|
||||
//! \brief Determines stability of a first order real polynomial
|
||||
//! P(z) = z + a1
|
||||
//! \param[in] a1 Coefficient a1
|
||||
//! \return 'true' if the root has magnitude less than 1, 'false' otherwise
|
||||
//!
|
||||
static inline bool DCL_isStablePn1(float32_t a1)
|
||||
{
|
||||
return(((a1 * a1) < 1.0f) ? true : false);
|
||||
}
|
||||
|
||||
//! \brief Determines stability of a second order polynomial with real coefficients
|
||||
//! P(z) = a0 z^2 + a1 z + a2
|
||||
//! \param[in] a1 Coefficient a1
|
||||
//! \param[in] a2 Coefficient a2
|
||||
//! \return 'true' if both roots have magnitude less than 1, 'false' otherwise
|
||||
//!
|
||||
static inline bool DCL_isStablePn2(float32_t a0, float32_t a1, float32_t a2)
|
||||
{
|
||||
float32_t b0, b1, c0;
|
||||
|
||||
b0 = a0 - a2 * a2 / a0;
|
||||
b1 = a1 - a1 * a2 / a0;
|
||||
c0 = b0 - b1 * b1 / b0;
|
||||
|
||||
if ((a0 > 0.0f) && (b0 > 0.0f) && (c0 > 0.0f))
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Determines stability of a third order polynomial with real coefficients
|
||||
//! P(z) = a0 z^3 + a1 z^2 + a2 z + a3
|
||||
//! \param[in] a1 Coefficient a1
|
||||
//! \param[in] a2 Coefficient a2
|
||||
//! \param[in] a3 Coefficient a3
|
||||
//! \return 'true' if all roots have magnitude less than 1, 'false' otherwise
|
||||
//!
|
||||
static inline bool DCL_isStablePn3(float32_t a0, float32_t a1, float32_t a2, float32_t a3)
|
||||
{
|
||||
float32_t b0, b1, b2, c0, c1, d0;
|
||||
|
||||
b0 = a0 - a3 * a3 / a0;
|
||||
b1 = a1 - a2 * a3 / a0;
|
||||
b2 = a2 - a1 * a3 / a0;
|
||||
c0 = b0 - b2 * b2 / b0;
|
||||
c1 = b1 - b1 * b2 / b0;
|
||||
d0 = c0 - c1 * c1 / c0;
|
||||
|
||||
if ((a0 > 0.0f) && (b0 > 0.0f) && (c0 > 0.0f) && (d0 > 0.0f))
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--- ZPK3 structure ---------------------------------------------------------
|
||||
|
||||
//! \brief Defines the DCL_ZPK3 controller structure.
|
||||
//!
|
||||
//! \details Allows controllers to be defined in terms of complex pole
|
||||
//! and zero frequencies. The common structure consists of
|
||||
//! three complex zeros, three complex poles, and a real gain.
|
||||
//! All frequencies must be specified in radians/sec.
|
||||
//!
|
||||
typedef struct dcl_zpk3 {
|
||||
float complex z1;
|
||||
float complex z2;
|
||||
float complex z3;
|
||||
float complex p1;
|
||||
float complex p2;
|
||||
float complex p3;
|
||||
float32_t K;
|
||||
} DCL_ZPK3;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_ZPK3 structure
|
||||
//!
|
||||
#define ZPK3_DEFAULTS { 0.0f + 0.0f*I, 0.0f + 0.0f*I, 0.0f + 0.0f*I, \
|
||||
0.0f + 0.0f*I, 0.0f + 0.0f*I, 0.0f + 0.0f*I, \
|
||||
1.0f }
|
||||
|
||||
//! \brief Determines stability of a ZPK3 representation by checking pole magnitude
|
||||
//! \param[in] q Pointer to DCL_ZPK3 structure
|
||||
//! \return 'true' if all poles have magnitude less than 1, 'false' otherwise
|
||||
//!
|
||||
static inline bool DCL_isStableZpk3(DCL_ZPK3 *q)
|
||||
{
|
||||
return(((cabsf(q->p1) < 1.0f) && (cabsf(q->p2) < 1.0f) && (cabsf(q->p3) < 1.0f)) ? true : false);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#endif // __TMS320C28XX_CLA__
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,255 @@
|
||||
/* DCLC28.h - C2000 Digital Control Library header file (32-bit fixed point)
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCLC28_H
|
||||
#define _C_DCLC28_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! \file DCLC28.h
|
||||
//! \brief Contains the public interface to the
|
||||
//! fixed-point Digital Controller Library functions
|
||||
|
||||
#include "DCL.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define Q24_PLUS_1 0x01000000
|
||||
#define Q24_MINUS_1 0xFF000000
|
||||
|
||||
|
||||
//--- Linear PID controller ---------------------------------------------------
|
||||
|
||||
//! \brief Defines the DCL_PID32 shadow parameter set
|
||||
//!
|
||||
typedef struct dcl_pid32_sps {
|
||||
int32_t Kp; //!< Proportional gain
|
||||
int32_t Ki; //!< Integral gain
|
||||
int32_t Kd; //!< Derivative gain
|
||||
int32_t c1; //!< D-term filter coefficient 1
|
||||
int32_t c2; //!< D-term filter coefficient 2
|
||||
int32_t Umax; //!< Upper saturation limit
|
||||
int32_t Umin; //!< Lower saturation limit
|
||||
} DCL_PID32_SPS;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_PID shadow structure
|
||||
//!
|
||||
#define PID32_SPS_DEFAULTS { Q24_PLUS_1, 0L, 0L, Q24_PLUS_1, 0L, \
|
||||
Q24_PLUS_1, Q24_MINUS_1 }
|
||||
|
||||
//! \brief Defines the fixed-point linear PID32 controller structure
|
||||
//!
|
||||
typedef struct dcl_pid32 {
|
||||
int32_t Kp; //!< Proportional gain
|
||||
int32_t Ki; //!< Integral gain
|
||||
int32_t Kd; //!< Derivative gain
|
||||
int32_t c1; //!< D-term filter coefficient 1
|
||||
int32_t c2; //!< D-term filter coefficient 2
|
||||
int32_t d2; //!< D-term filter intermediate storage 1
|
||||
int32_t d3; //!< D-term filter intermediate storage 2
|
||||
int32_t i10; //!< I-term intermediate storage
|
||||
int32_t i14; //!< Intermediate saturation storage
|
||||
int32_t Umax; //!< Upper saturation limit
|
||||
int32_t Umin; //!< Lower saturation limit
|
||||
DCL_PID32_SPS *sps; //!< Pointer to the shadow parameter set
|
||||
DCL_CSS *css; //!< Pointer to the common support structure
|
||||
} DCL_PID32;
|
||||
|
||||
//! \brief Defines default values to initialize the PID structure
|
||||
//!
|
||||
#define DCL_PID32_DEFAULTS { Q24_PLUS_1, 0L, 0L, Q24_PLUS_1, 0L, 0L, 0L, 0L, \
|
||||
Q24_PLUS_1, Q24_PLUS_1, Q24_MINUS_1, \
|
||||
NULL_ADDR, NULL_ADDR }
|
||||
|
||||
//! \brief Resets PID internal storage data
|
||||
//! \param[in] p Pointer to the DCL_PID32 structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_resetPID32(DCL_PID32 *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->d2 = p->d3 = p->i10 = 0L;
|
||||
p->i14 = Q24_PLUS_1;
|
||||
DCL_RESTORE_INTS(v);
|
||||
}
|
||||
|
||||
//! \brief Loads PID tuning parameters
|
||||
//! \param[in] p Pointer to the DCL_PID32 active controller structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_updatePID32(DCL_PID32 *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
if (p->css->sts & STS_UPDATE_PENDING)
|
||||
{
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->Kp = p->sps->Kp;
|
||||
p->Ki = p->sps->Ki;
|
||||
p->Kd = p->sps->Kd;
|
||||
p->c1 = p->sps->c1;
|
||||
p->c2 = p->sps->c2;
|
||||
p->Umax = p->sps->Umax;
|
||||
p->Umin = p->sps->Umin;
|
||||
DCL_RESTORE_INTS(v);
|
||||
DCL_CLEAR_UPDATE_REQUEST(p);
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Loads PID32 tuning parameters
|
||||
//! Implemented as assembly module
|
||||
//! \param[in] p Pointer to the active DCL_PID32 controller structure
|
||||
//! \return None
|
||||
//!
|
||||
extern void DCL_fupdatePID32(DCL_PID32 *p);
|
||||
|
||||
//! \brief Executes a parallel form PID controller on the C28x
|
||||
//! \param[in] p Pointer to the DCL_PID32 structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \param[in] lk External output clamp flag
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern int32_t DCL_runPID_A1(DCL_PID32 *p, int32_t rk, int32_t yk);
|
||||
|
||||
|
||||
//--- Linear PI controller ----------------------------------------------------
|
||||
|
||||
//! \brief Defines the PI32 shadow parameter set
|
||||
//!
|
||||
typedef struct dcl_pi32_sps {
|
||||
int32_t Kp; //!< Proportional gain
|
||||
int32_t Ki; //!< Integral gain
|
||||
int32_t Umax; //!< Upper saturation limit
|
||||
int32_t Umin; //!< Lower saturation limit
|
||||
} DCL_PI32_SPS;
|
||||
|
||||
//! \brief Defines default values to initialize the PI32 shadow structure
|
||||
//!
|
||||
#define PI32_SPS_DEFAULTS { Q24_PLUS_1, 0L, Q24_PLUS_1, Q24_MINUS_1 }
|
||||
|
||||
//! \brief Defines the PI32 controller structure
|
||||
//!
|
||||
typedef struct dcl_pi32 {
|
||||
int32_t Kp; //!< Proportional gain
|
||||
int32_t Ki; //!< Integral gain
|
||||
int32_t i6; //!< Saturation storage
|
||||
int32_t i10; //!< I storage
|
||||
int32_t Umax; //!< Upper saturation limit
|
||||
int32_t Umin; //!< Lower saturation limit
|
||||
DCL_PI32_SPS *sps; //!< Pointer to the shadow parameter set
|
||||
DCL_CSS *css; //!< Pointer to the common support structure
|
||||
} DCL_PI32;
|
||||
|
||||
//! \brief Defines default values to initialize the active PI structure
|
||||
//!
|
||||
#define DCL_PI32_DEFAULTS { Q24_PLUS_1, 0L, Q24_PLUS_1, 0L, \
|
||||
Q24_PLUS_1, Q24_MINUS_1, \
|
||||
NULL_ADDR, NULL_ADDR }
|
||||
|
||||
//! \brief Resets PI32 internal storage data
|
||||
//! \param[in] p Pointer to the DCL_PI32 active controller structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_resetPI32(DCL_PI32 *p)
|
||||
{
|
||||
int16_t v;
|
||||
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->i10 = 0L;
|
||||
p->i6 = Q24_PLUS_1;
|
||||
DCL_RESTORE_INTS(v);
|
||||
}
|
||||
|
||||
//! \brief Loads active PI32 controller parameters
|
||||
//! \param[in] p Pointer to the DCL_PI32 active controller structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_updatePI32(DCL_PI32 *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
if (p->css->sts & STS_UPDATE_PENDING)
|
||||
{
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->Kp = p->sps->Kp;
|
||||
p->Ki = p->sps->Ki;
|
||||
p->Umax = p->sps->Umax;
|
||||
p->Umin = p->sps->Umin;
|
||||
DCL_RESTORE_INTS(v);
|
||||
DCL_CLEAR_UPDATE_REQUEST(p);
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Loads PI32 tuning parameters
|
||||
//! Implemented as assembly module
|
||||
//! \param[in] p Pointer to the active DCL_PI32 controller structure
|
||||
//! \return None
|
||||
//!
|
||||
extern void DCL_fupdatePI32(DCL_PI32 *p);
|
||||
|
||||
//! \brief Executes a series form PI_FP controller on the C28x
|
||||
//! \param[in] p Pointer to the DCL_PI structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern int32_t DCL_runPI_A1(DCL_PI32 *p, int32_t rk, int32_t yk);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCLC28_H
|
||||
@@ -0,0 +1,479 @@
|
||||
/* DCLCLA.h - C2000 Digital Controller Library header file
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCLCLA_H
|
||||
#define _C_DCLCLA_H
|
||||
|
||||
//! \file DCLCLA.h
|
||||
//! \brief Contains the public interface to the
|
||||
//! Digital Controller Library CLA functions
|
||||
|
||||
#include "DCL.h"
|
||||
|
||||
|
||||
//--- Linear PID controller ---------------------------------------------------
|
||||
|
||||
//! \brief Defines the DCL_PID_CLA controller structure
|
||||
//!
|
||||
typedef struct {
|
||||
float32_t Kp; //!< Proportional gain
|
||||
float32_t Ki; //!< Integral gain
|
||||
float32_t Kd; //!< Derivative gain
|
||||
float32_t Kr; //!< Set point weight
|
||||
float32_t c1; //!< D-term filter coefficient 1
|
||||
float32_t c2; //!< D-term filter coefficient 2
|
||||
float32_t d2; //!< D-term filter intermediate storage 1
|
||||
float32_t d3; //!< D-term filter intermediate storage 2
|
||||
float32_t i10; //!< I-term intermediate storage
|
||||
float32_t i14; //!< Intermediate saturation storage
|
||||
float32_t Umax; //!< Upper saturation limit
|
||||
float32_t Umin; //!< Lower saturation limit
|
||||
} DCL_PID_CLA;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_PID structure
|
||||
//!
|
||||
#define PID_CLA_DEFAULTS { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 1.0f, -1.0f }
|
||||
|
||||
//! \brief Executes an ideal form PID controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_PID_CLA structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \param[in] lk External output clamp flag
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runPID_L1(DCL_PID_CLA *p, float32_t rk, float32_t yk, float32_t lk);
|
||||
|
||||
//! \brief Executes a parallel form PID controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_PID_CLA structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \param[in] lk External output clamp flag
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runPID_L2(DCL_PID_CLA *p, float32_t rk, float32_t yk, float32_t lk);
|
||||
|
||||
|
||||
//--- Linear PI controller ----------------------------------------------------
|
||||
|
||||
//! \brief Defines the DCL_PI_CLA controller structure
|
||||
//!
|
||||
typedef struct {
|
||||
float32_t Kp; //!< Proportional gain
|
||||
float32_t Ki; //!< Integral gain
|
||||
float32_t i10; //!< I storage
|
||||
float32_t Umax; //!< Upper control saturation limit
|
||||
float32_t Umin; //!< Lower control saturation limit
|
||||
float32_t i6; //!< Saturation storage
|
||||
float32_t i11; //!< I storage
|
||||
float32_t Imax; //!< Upper integrator saturation limit
|
||||
float32_t Imin; //!< Lower integrator saturation limit
|
||||
} DCL_PI_CLA;
|
||||
|
||||
//! \brief Defines default values to initialize the PI_CLA structure
|
||||
//!
|
||||
#define PI_CLA_DEFAULTS { 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f }
|
||||
|
||||
//! \brief Executes a series form PI controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_PI_CLA structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runPI_L1(DCL_PI_CLA *p, float32_t rk, float32_t yk);
|
||||
|
||||
//! \brief Executes a parallel form PI controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_PI_CLA structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runPI_L2(DCL_PI_CLA *p, float32_t rk, float32_t yk);
|
||||
|
||||
//! \brief Executes an inline series form PI controller on the CLA
|
||||
//! Implemented as inline C function
|
||||
//! \param[in] p Pointer to the DCL_PI structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runPI_L3(DCL_PI_CLA *p, float32_t rk, float32_t yk)
|
||||
{
|
||||
float32_t v2, v4, v5, v9;
|
||||
|
||||
asm(" MSETFLG RNDF32=1");
|
||||
v2 = p->Kp * (rk - yk);
|
||||
v4 = p->i10 + (p->Ki * p->i6 * v2);
|
||||
v5 = v2 + v4;
|
||||
v9 = (v5 > p->Umax) ? p->Umax : v5;
|
||||
v9 = (v9 < p->Umin) ? p->Umin : v9;
|
||||
p->i10 = v4;
|
||||
p->i6 = (v5 == v9) ? 1.0f : 0.0f;
|
||||
|
||||
return(v9);
|
||||
}
|
||||
|
||||
//! \brief Executes an parallel form PI controller on the CLA
|
||||
//! Implemented as inline C function
|
||||
//! \param[in] p Pointer to the DCL_PI structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runPI_L4(DCL_PI_CLA *p, float32_t rk, float32_t yk)
|
||||
{
|
||||
float32_t v1, v2, v4, v5, v9;
|
||||
|
||||
asm(" MSETFLG RNDF32=1");
|
||||
v1 = rk - yk;
|
||||
v2 = p->Kp * v1;
|
||||
v4 = (v1 * p->Ki * p->i6) + p->i10;
|
||||
p->i10 = v4;
|
||||
v5 = v2 + v4;
|
||||
v9 = (v5 > p->Umax) ? p->Umax : v5;
|
||||
v9 = (v9 < p->Umin) ? p->Umin : v9;
|
||||
p->i6 = (v5 == v9) ? 1.0f : 0.0f;
|
||||
|
||||
return(v9);
|
||||
}
|
||||
|
||||
//! \brief Executes a series form PI controller with Tustin integrator
|
||||
//! on the CLA.
|
||||
//! \param[in] p Pointer to the DCL_PI_CLA structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runPI_L5(DCL_PI_CLA *p, float32_t rk, float32_t yk)
|
||||
{
|
||||
float32_t v2, v4, v5, v8, v9;
|
||||
|
||||
asm(" MSETFLG RNDF32=1");
|
||||
v2 = (rk - yk) * p->Kp;
|
||||
v8 = v2 * p->Ki * p->i6;
|
||||
v4 = v8 + p->i11 + p->i10;
|
||||
v5 = v2 + v4;
|
||||
p->i10 = v4;
|
||||
p->i11 = v8;
|
||||
v9 = (v5 > p->Umax) ? p->Umax : v5;
|
||||
v9 = (v9 < p->Umin) ? p->Umin : v9;
|
||||
p->i6 = (v5 == v9) ? 1.0f : 0.0f;
|
||||
|
||||
return(v9);
|
||||
}
|
||||
|
||||
|
||||
//--- Direct Form 1 - 1st order -----------------------------------------------
|
||||
|
||||
//! \brief Defines the DCL_DF11 controller structure
|
||||
//!
|
||||
typedef struct {
|
||||
float32_t b0; //!< b0
|
||||
float32_t b1; //!< b1
|
||||
float32_t a1; //!< a1
|
||||
float32_t d1; //!< e(k-1)
|
||||
float32_t d2; //!< u(k-1)
|
||||
} DCL_DF11_CLA;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_DF11_CLA structure
|
||||
//!
|
||||
#define DF11_CLA_DEFAULTS { 0.5f, 0.5f, 1.0f, 0.0f, 0.0f }
|
||||
|
||||
//! \brief Executes a 1st order Direct Form 1 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF11_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runDF11_L1(DCL_DF11_CLA *p, float32_t ek);
|
||||
|
||||
|
||||
//--- Direct Form 1 - 3rd order -----------------------------------------------
|
||||
|
||||
//! \brief Defines the DCL_DF13_CLA controller structure
|
||||
//!
|
||||
typedef struct {
|
||||
// coefficients
|
||||
float32_t b0; //!< b0
|
||||
float32_t b1; //!< b1
|
||||
float32_t b2; //!< b2
|
||||
float32_t b3; //!< b3
|
||||
float32_t a0; //!< a0
|
||||
float32_t a1; //!< a1
|
||||
float32_t a2; //!< a2
|
||||
float32_t a3; //!< a3
|
||||
|
||||
//data
|
||||
float32_t d0; //!< e(k)
|
||||
float32_t d1; //!< e(k-1)
|
||||
float32_t d2; //!< e(k-2)
|
||||
float32_t d3; //!< e(k-3)
|
||||
float32_t d4; //!< u(k)
|
||||
float32_t d5; //!< u(k-1)
|
||||
float32_t d6; //!< u(k-2)
|
||||
float32_t d7; //!< u(k-3)
|
||||
} DCL_DF13_CLA;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_DF13_CLA structure
|
||||
//!
|
||||
#define DF13_CLA_DEFAULTS { 0.25f, 0.25f, 0.25f, 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }
|
||||
|
||||
//! \brief Executes a full 3rd order Direct Form 1 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF13_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runDF13_L1(DCL_DF13_CLA *p, float32_t ek);
|
||||
|
||||
//! \brief Executes an immediate 3rd order Direct Form 1 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF13_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \param[in] vk The partial pre-computed control effort
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runDF13_L2(DCL_DF13_CLA *p, float32_t ek, float32_t vk);
|
||||
|
||||
//! \brief Executes a partial pre-computed 3rd order Direct Form 1 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF13_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \param[in] uk The controller output in the previous sample interval
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runDF13_L3(DCL_DF13_CLA *p, float32_t ek, float32_t uk);
|
||||
|
||||
//! \brief Executes a full 3rd order Direct Form 1 controller on the CLA
|
||||
//! Implemented as inline C function
|
||||
//! Note: d0 not used
|
||||
//! \param[in] p Pointer to the DCL_DF13_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runDF13_L4(DCL_DF13_CLA *p, float32_t ek)
|
||||
{
|
||||
asm(" MSETFLG RNDF32=1");
|
||||
p->d4 = (ek * p->b0) + (p->d1 * p->b1) + (p->d2 * p->b2) + (p->d3 * p->b3) - (p->d5 * p->a1) - (p->d6 * p->a2) - (p->d7 * p->a3);
|
||||
p->d3 = p->d2;
|
||||
p->d2 = p->d1;
|
||||
p->d1 = ek;
|
||||
p->d7 = p->d6;
|
||||
p->d6 = p->d5;
|
||||
p->d5 = p->d4;
|
||||
|
||||
return(p->d4);
|
||||
}
|
||||
|
||||
//! \brief Executes an immediate 3rd order Direct Form 1 controller on the CLA
|
||||
//! Implemented as inline C function
|
||||
//! \param[in] p Pointer to the DCL_DF13_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \param[in] vk The partial pre-computed control effort
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runDF13_L5(DCL_DF13_CLA *p, float32_t ek, float32_t vk)
|
||||
{
|
||||
asm(" MSETFLG RNDF32=1");
|
||||
p->d4 = (ek * p->b0) + vk;
|
||||
|
||||
return(p->d4);
|
||||
}
|
||||
|
||||
//! \brief Executes a partial pre-computed 3rd order Direct Form 1 controller on the CLA
|
||||
//! Implemented as inline C function
|
||||
//! Note: d0 not used
|
||||
//! \param[in] p Pointer to the DCL_DF13_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \param[in] uk The controller output in the previous sample interval
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runDF13_L6(DCL_DF13_CLA *p, float32_t ek, float32_t uk)
|
||||
{
|
||||
float32_t v9;
|
||||
|
||||
asm(" MSETFLG RNDF32=1");
|
||||
v9 = (ek * p->b1) + (p->d1 * p->b2) + (p->d2 * p->b3) - (uk * p->a1) - (p->d5 * p->a2) - (p->d6 * p->a3);
|
||||
p->d2 = p->d1;
|
||||
p->d1 = ek;
|
||||
p->d6 = p->d5;
|
||||
p->d5 = uk;
|
||||
|
||||
return(v9);
|
||||
}
|
||||
|
||||
|
||||
//--- Direct Form 2 - 2nd order -----------------------------------------------
|
||||
|
||||
//! \brief Defines the DCL_DF22_CLA controller structure
|
||||
//!
|
||||
typedef struct {
|
||||
float32_t b0; //!< b0
|
||||
float32_t b1; //!< b1
|
||||
float32_t b2; //!< b2
|
||||
float32_t a1; //!< a1
|
||||
float32_t a2; //!< a2
|
||||
float32_t x1; //!< x1
|
||||
float32_t x2; //!< x2
|
||||
} DCL_DF22_CLA;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_DF22_CLA structure
|
||||
//!
|
||||
#define DF22_CLA_DEFAULTS { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }
|
||||
|
||||
//! \brief Executes a full 2nd order Direct Form 2 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF22_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runDF22_L1(DCL_DF22_CLA *p, float32_t ek);
|
||||
|
||||
//! \brief Executes an immediate 2nd order Direct Form 2 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF22_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runDF22_L2(DCL_DF22_CLA *p, float32_t ek);
|
||||
|
||||
//! \brief Executes a partial pre-computed 2nd order Direct Form 2 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF22_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \param[in] uk The controller output in the previous sample interval
|
||||
//!
|
||||
extern void DCL_runDF22_L3(DCL_DF22_CLA *p, float32_t ek, float32_t uk);
|
||||
|
||||
//! \brief Executes a full 2nd order Direct Form 2 controller on the CLA
|
||||
//! Implemented as inline C function
|
||||
//! \param[in] p Pointer to the DCL_DF22 controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runDF22_L4(DCL_DF22_CLA *p, float32_t ek)
|
||||
{
|
||||
float32_t v7;
|
||||
|
||||
asm(" MSETFLG RNDF32=1");
|
||||
v7 = (ek * p->b0) + p->x1;
|
||||
p->x1 = (ek * p->b1) + p->x2 - (v7 * p->a1);
|
||||
p->x2 = (ek * p->b2) - (v7 * p->a2);
|
||||
|
||||
return(v7);
|
||||
}
|
||||
|
||||
|
||||
//--- Direct Form 2 - 3rd order -----------------------------------------------
|
||||
|
||||
//! \brief Defines the DCL_DF23_CLA controller structure
|
||||
//!
|
||||
typedef struct {
|
||||
float32_t b0; //!< b0
|
||||
float32_t b1; //!< b1
|
||||
float32_t b2; //!< b2
|
||||
float32_t b3; //!< b3
|
||||
float32_t a1; //!< a1
|
||||
float32_t a2; //!< a2
|
||||
float32_t a3; //!< a3
|
||||
float32_t x1; //!< x1
|
||||
float32_t x2; //!< x2
|
||||
float32_t x3; //!< x3
|
||||
} DCL_DF23_CLA;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_DF23_CLA structure
|
||||
//!
|
||||
#define DF23_CLA_DEFAULTS { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }
|
||||
|
||||
//! \brief Executes a full 3rd order Direct Form 2 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF23_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runDF23_L1(DCL_DF23_CLA *p, float32_t ek);
|
||||
|
||||
//! \brief Executes an immediate 3rd order Direct Form 2 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF23_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runDF23_L2(DCL_DF23_CLA *p, float32_t ek);
|
||||
|
||||
//! \brief Executes a partial pre-computed 2nd order Direct Form 2 controller on the CLA
|
||||
//! \param[in] p Pointer to the DCL_DF23_CLA controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \param[in] uk The controller output in the previous sample interval
|
||||
//!
|
||||
extern void DCL_runDF23_L3(DCL_DF23_CLA *p, float32_t ek, float32_t uk);
|
||||
|
||||
|
||||
//--- Direct Form 2 - clamp ---------------------------------------------------
|
||||
|
||||
//! \brief Saturates a control variable and returns 1.0f if either limit is exceeded
|
||||
//!
|
||||
//! \details Can be used to saturate a pre-computed Direct Form 2 controller.
|
||||
//! If the immediate result is in range it can be used, otherwise
|
||||
//! it can be clamped and the next partial pre-computation skipped.
|
||||
//! An example of use with a pre-computed DF22 controller follows:
|
||||
//!
|
||||
//! \code
|
||||
//! uk = DCL_runDF22_L2(&arma2, rk); // immediate result from pre-computed controller
|
||||
//! f = DCL_runClamp_L1(&uk, 1.0f, -1.0f); // clamp immediate result to +/-1.0
|
||||
//! // ...use uk here...
|
||||
//! if (0.5f > f) // if immediate result is in range...
|
||||
//! {
|
||||
//! DCL_runDF22_L3(&arma2, rk, uk); // ...pre-compute the next partial result
|
||||
//! }
|
||||
//! \endcode
|
||||
//!
|
||||
//! \param[in] data The address of the data variable
|
||||
//! \param[in] Umax The upper limit
|
||||
//! \param[in] Umin The lower limit
|
||||
//! \return Returns 0.0f if (Umin < data < Umax), else 1.0f
|
||||
//!
|
||||
extern float32_t DCL_runClamp_L1(float32_t *data, float32_t Umax, float32_t Umin);
|
||||
|
||||
#endif // _C_DCLCLA_H
|
||||
|
||||
/* end of file */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,403 @@
|
||||
/* DCLF64.h - Digital Control Library (64-bit floating point)
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCLF64_H
|
||||
#define _C_DCLF64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! \file DCLF64.h
|
||||
//! \brief Contains the public interface to the
|
||||
//! 64-bit PID controller functions
|
||||
|
||||
#include "DCL.h"
|
||||
|
||||
//--- PIDF64 controller -----------------------------------------------
|
||||
|
||||
#pragma CODE_SECTION(DCL_updatePIDF64,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_runPIDF64_S1,"dclfuncs")
|
||||
|
||||
//! \brief Defines the shadow PIDF64 controller structure
|
||||
//!
|
||||
typedef struct dcl_pidf64_sps {
|
||||
float64_t Kp; //!< Proportional gain
|
||||
float64_t Ki; //!< Integral gain
|
||||
float64_t Kd; //!< Derivative gain
|
||||
float64_t Kr; //!< Set point weight
|
||||
float64_t c1; //!< D-term filter coefficient 1
|
||||
float64_t c2; //!< D-term filter coefficient 2
|
||||
float64_t Umax; //!< Upper saturation limit
|
||||
float64_t Umin; //!< Lower saturation limit
|
||||
} DCL_PIDF64_SPS;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_PIDF64 shadow structure
|
||||
//!
|
||||
#define PIDF64_SPS_DEFAULTS { 1.0L, 0.0L, 0.0L, 1.0L, 1.0L, 0.0L, 1.0L, -1.0L }
|
||||
|
||||
//! \brief Defines the active PIDF64 controller structure
|
||||
//!
|
||||
typedef struct dcl_pidf64 {
|
||||
// active parameters
|
||||
float64_t Kp; //!< Proportional gain
|
||||
float64_t Ki; //!< Integral gain
|
||||
float64_t Kd; //!< Derivative gain
|
||||
float64_t Kr; //!< Set point weight
|
||||
float64_t c1; //!< D-term filter coefficient 1
|
||||
float64_t c2; //!< D-term filter coefficient 2
|
||||
float64_t d2; //!< D-term filter intermediate storage 1
|
||||
float64_t d3; //!< D-term filter intermediate storage 2
|
||||
float64_t i10; //!< I-term intermediate storage
|
||||
float64_t i14; //!< Intermediate saturation storage
|
||||
float64_t i16; //!< Spare
|
||||
float64_t Umax; //!< Upper saturation limit
|
||||
float64_t Umin; //!< Lower saturation limit
|
||||
DCL_PIDF64_SPS *sps; //!< Pointer to shadow parameter set
|
||||
DCL_CSS *css; //!< Pointer to common support structure
|
||||
} DCL_PIDF64;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_PIDF64 active structure
|
||||
//!
|
||||
#define PIDF64_DEFAULTS { 1.0L, 0.0L, 0.0L, 1.0L, 1.0L, 0.0L, 0.0L, 0.0L, \
|
||||
0.0L, 1.0L, 0.0L, 1.0L, -1.0L, NULL_ADDR, NULL_ADDR }
|
||||
|
||||
//! \brief Resets the PIDF64 internal storage data
|
||||
//! \param[in] p Pointer to the DCL_PIDF64 structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_resetPIDF64(DCL_PIDF64 *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->d2 = p->d3 = p->i10 = 0.0L;
|
||||
p->i14 = 1.0L;
|
||||
DCL_RESTORE_INTS(v);
|
||||
}
|
||||
|
||||
//! \brief Copies shadow controller parameters to the active
|
||||
//! DCL_PIDF64 structure while global interrupts disabled
|
||||
//! \param[in] p Pointer to the DCL_PIDF64 controller structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_updatePIDF64(DCL_PIDF64 *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
if (p->css->sts == STS_UPDATE_PENDING)
|
||||
{
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->Kp = p->sps->Kp;
|
||||
p->Ki = p->sps->Ki;
|
||||
p->Kd = p->sps->Kd;
|
||||
p->Kr = p->sps->Kr;
|
||||
p->c1 = p->sps->c1;
|
||||
p->c2 = p->sps->c2;
|
||||
p->Umax = p->sps->Umax;
|
||||
p->Umin = p->sps->Umin;
|
||||
DCL_RESTORE_INTS(v);
|
||||
DCL_CLEAR_UPDATE_REQUEST(p);
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Loads the derivative path filter shadow coefficients
|
||||
//! Note: changes will not become effective until update called
|
||||
//! \param[in] p Pointer to the DCL_PIDF64 structure
|
||||
//! \param[in] fc The desired filter bandwidth in Hz
|
||||
//! \param[in] T The sample period in seconds
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setPIDF64filterBW(DCL_PIDF64 *p, float64_t fc)
|
||||
{
|
||||
float64_t tau;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((fc >= 1.0L / (2.0L * p->css->T)) || (fc <= 0.0L)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
tau = 1.0L / (2.0L * CONST_PI_64 * fc);
|
||||
p->sps->c1 = 2.0L / (p->css->T + 2.0L * tau);
|
||||
p->sps->c2 = (p->css->T - 2.0L * tau) / (p->css->T + 2.0L * tau);
|
||||
}
|
||||
|
||||
//! \brief Loads the PIDF64 derivative path filter active coefficients
|
||||
//! Note: new coefficients take effect immediately. SPS &
|
||||
//! CSS contents are unaffected.
|
||||
//! \param[in] p Pointer to the DCL_PIDF64 structure
|
||||
//! \param[in] fc The desired filter bandwidth in Hz
|
||||
//! \param[in] T The controller update rate in seconds
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setActivePIDF64filterBW(DCL_PIDF64 *p, float64_t fc, float64_t T)
|
||||
{
|
||||
float64_t tau;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((fc >= 1.0L / (2.0L * T)) || (fc <= 0.0L)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
tau = 1.0L / (2.0L * CONST_PI_64 * fc);
|
||||
p->c1 = 2.0L / (T + 2.0L * tau);
|
||||
p->c2 = (T - 2.0L * tau) / (T + 2.0L * tau);
|
||||
}
|
||||
|
||||
//! \brief Returns the active derivative path filter bandwidth in Hz
|
||||
//! \param[in] p Pointer to the DCL_PIDF64 structure
|
||||
//! \return The filter bandwidth in Hz
|
||||
//!
|
||||
static inline float64_t DCL_getPIDF64filterBW(DCL_PIDF64 *p)
|
||||
{
|
||||
float64_t tau;
|
||||
|
||||
tau = ((2.0L - p->c1 * p->css->T) / (2.0L * p->c1));
|
||||
return(1.0L / (2.0L * CONST_PI_64 * tau));
|
||||
}
|
||||
|
||||
//! \brief Executes an inline series form PIDF64 controller
|
||||
//! \param[in] p Pointer to the DCL_PIDF64 structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \param[in] lk External output clamp flag
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float64_t DCL_runPIDF64_S1(DCL_PIDF64 *p, float64_t rk, float64_t yk, float64_t lk)
|
||||
{
|
||||
float64_t v1, v4, v5, v8, v9, v10, v12;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (p->css->sts & STS_CONTROLLER_RUNNING) ? ERR_CONTROLLER : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
DCL_CONTROLLER_BEGIN(p);
|
||||
#endif
|
||||
|
||||
v5 = (p->Kr * rk) - yk;
|
||||
v8 = ((rk - yk) * p->Ki * p->Kp * p->i14) + p->i10;
|
||||
p->i10 = v8;
|
||||
v1 = yk * p->Kd * p->c1;
|
||||
v4 = v1 - p->d2 - p->d3;
|
||||
p->d2 = v1;
|
||||
p->d3 = v4 * p->c2;
|
||||
v9 = ((v5 - v4) * p->Kp) + v8;
|
||||
v10 = (v9 > p->Umax) ? p->Umax : v9;
|
||||
v10 = (v10 < p->Umin) ? p->Umin : v10;
|
||||
v12 = (v10 == v9) ? 1.0 : 0.0;
|
||||
p->i14 = v12 * lk;
|
||||
|
||||
#ifdef DCL_TESTPOINTS_ENABLED
|
||||
p->css->tpt = (float32_t) v5;
|
||||
#endif
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
DCL_CONTROLLER_END(p);
|
||||
#endif
|
||||
|
||||
return(v10);
|
||||
}
|
||||
|
||||
//--- DF22F64 controller -----------------------------------------------------
|
||||
|
||||
#pragma CODE_SECTION(DCL_updateDF22F64,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_runDF22F64_S1,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_runDF22F64_S2,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_runDF22F64_S3,"dclfuncs")
|
||||
|
||||
//! \brief Defines the DCL_DF22F64 shadow parameter set
|
||||
//!
|
||||
typedef struct dcl_df22f64_sps {
|
||||
float64_t b0; //!< b0
|
||||
float64_t b1; //!< b1
|
||||
float64_t b2; //!< b2
|
||||
float64_t a1; //!< a1
|
||||
float64_t a2; //!< a2
|
||||
} DCL_DF22F64_SPS;
|
||||
|
||||
#define DF22F64_SPS_DEFAULTS { 1.0, 0.0, 0.0, 0.0, 0.0 }
|
||||
|
||||
//! \brief Defines the DCL_DF22F64 controller structure
|
||||
//!
|
||||
typedef struct dcl_df22f64 {
|
||||
float64_t b0; //!< b0
|
||||
float64_t b1; //!< b1
|
||||
float64_t b2; //!< b2
|
||||
float64_t a1; //!< a1
|
||||
float64_t a2; //!< a2
|
||||
float64_t x1; //!< x1
|
||||
float64_t x2; //!< x2
|
||||
DCL_DF22F64_SPS *sps; //!< Pointer to the shadow parameter set
|
||||
DCL_CSS *css; //!< Pointer to the common support structure
|
||||
} DCL_DF22F64;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_DF22F64
|
||||
//! structure
|
||||
//!
|
||||
#define DF22F64_DEFAULTS { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, \
|
||||
NULL_ADDR, NULL_ADDR }
|
||||
|
||||
//! \brief Resets internal DF22F64 controller data to zero
|
||||
//! \param[in] p Pointer to the DCL_DF22F64 controller structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_resetDF22F64(DCL_DF22F64 *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->x1 = p->x2 = 0.0;
|
||||
DCL_RESTORE_INTS(v);
|
||||
}
|
||||
|
||||
//! \brief Updates active coefficients from shadow set
|
||||
//! \param[in] p Pointer to the DCL_DF22F64 controller structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_updateDF22F64(DCL_DF22F64 *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
if (p->css->sts & STS_UPDATE_PENDING)
|
||||
{
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->b0 = p->sps->b0;
|
||||
p->b1 = p->sps->b1;
|
||||
p->b2 = p->sps->b2;
|
||||
p->a1 = p->sps->a1;
|
||||
p->a2 = p->sps->a2;
|
||||
DCL_RESTORE_INTS(v);
|
||||
DCL_CLEAR_UPDATE_REQUEST(p);
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Executes a full 2nd order Direct Form 2 controller on the
|
||||
//! FPU64. Implemented as inline C function.
|
||||
//! \param[in] p Pointer to the DCL_DF22F64 controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float64_t DCL_runDF22F64_S1(DCL_DF22F64 *p, float64_t ek)
|
||||
{
|
||||
float64_t v7;
|
||||
|
||||
v7 = (ek * p->b0) + p->x1;
|
||||
p->x1 = (ek * p->b1) + p->x2 - (v7 * p->a1);
|
||||
p->x2 = (ek * p->b2) - (v7 * p->a2);
|
||||
|
||||
#ifdef DCL_TESTPOINTS_ENABLED
|
||||
p->css->tpt = (float32_t) p->x2;
|
||||
#endif
|
||||
|
||||
return(v7);
|
||||
}
|
||||
|
||||
//! \brief Executes an immediate 2nd order Direct Form 2 controller
|
||||
//! on the FPU64. Implemented as inline C function.
|
||||
//! \param[in] p Pointer to the DCL_DF22F64 controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float64_t DCL_runDF22F64_S2(DCL_DF22F64 *p, float64_t ek)
|
||||
{
|
||||
return((ek * p->b0) + p->x1);
|
||||
}
|
||||
|
||||
//! \brief Executes a partial pre-computed 2nd order Direct Form 2
|
||||
//! controller on the FPU64. Implemented as inline C function.
|
||||
//! \param[in] p Pointer to the DCL_DF22F64 controller structure
|
||||
//! \param[in] ek The servo error
|
||||
//! \param[in] uk The controller output in the previous sample interval
|
||||
//!
|
||||
static inline void DCL_runDF22F64_S3(DCL_DF22F64 *p, float64_t ek, float64_t uk)
|
||||
{
|
||||
p->x1 = (ek * p->b1) + p->x2 - (uk * p->a1);
|
||||
p->x2 = (ek * p->b2) - (uk * p->a2);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//! \brief Saturates a control variable and returns 1 if either limit
|
||||
//! is exceeded
|
||||
//! \param[in] data The address of the data variable
|
||||
//! \param[in] Umax The upper limit
|
||||
//! \param[in] Umin The lower limit
|
||||
//! \return Returns 0 if (Umin < data < Umax), else 1
|
||||
//!
|
||||
static inline int16_t DCL_runClamp_S1(float64_t *data, float64_t Umax, float64_t Umin)
|
||||
{
|
||||
float64_t iv = *(data);
|
||||
|
||||
*(data) = (*(data) > Umax) ? Umax : *(data);
|
||||
*(data) = (*(data) < Umin) ? Umin : *(data);
|
||||
|
||||
return(((iv < Umax) && (iv > Umin)) ? 0 : 1);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCLF64_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,228 @@
|
||||
/* DCL_MLOG.h - Multi-channel data logger
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_MLOG_H
|
||||
#define _C_DCL_MLOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! \file DCL_MLOG.h
|
||||
//! \brief Contains the public interface to the multi-channel data log module (MLOG)
|
||||
//!
|
||||
|
||||
#include <stdint.h>
|
||||
#include "DCL_fdlog.h"
|
||||
|
||||
//! \brief Defines the number of MLOG channels
|
||||
//!
|
||||
#define MLOG_CHANS 4
|
||||
|
||||
//! \brief Defines the MLOG structure
|
||||
//!
|
||||
typedef volatile struct dcl_mlog {
|
||||
FDLOG captFrame[MLOG_CHANS]; //!< Capture data frames
|
||||
float32_t *data[MLOG_CHANS]; //!< Data channel pointers
|
||||
float32_t trigMax; //!< Upper trigger threshold
|
||||
float32_t trigMin; //!< Lower trigger threshold
|
||||
uint16_t tScale; //!< Number of samples per log write
|
||||
uint16_t sCount; //!< Sample counter
|
||||
uint16_t mode; //!< Operating mode
|
||||
} MLOG;
|
||||
|
||||
//! \brief Defines default values to initialise the MLOG structure
|
||||
//! Note: modify to match number of channels
|
||||
//!
|
||||
#define MLOG_DEFAULTS { { FDLOG_DEFAULTS, FDLOG_DEFAULTS, FDLOG_DEFAULTS, FDLOG_DEFAULTS }, \
|
||||
{ 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, \
|
||||
0.1, -0.1, 1, 1, 0 }
|
||||
|
||||
//! \brief Enumerated MLOG operating modes
|
||||
//!
|
||||
typedef enum
|
||||
{
|
||||
MLOG_invalid = 0, //!< Buffer pointers not initialised
|
||||
MLOG_idle, //!< Memory initialised but module not armed
|
||||
MLOG_armed, //!< Armed: capturing monitor frame data and waiting for trigger
|
||||
MLOG_capture, //!< Triggered: logging data into capture frame
|
||||
MLOG_complete, //!< Full data frame captured and available for read-out
|
||||
MLOG_numStates //!< Number of MLOG states
|
||||
} MLOG_states;
|
||||
|
||||
|
||||
//! \brief Initializes the MLOG module
|
||||
//! \param[in] q The MLOG structure
|
||||
//! \param[in] addr The start address of the memory block
|
||||
//! \param[in] size The size of the memory block in 32-bit words
|
||||
//! \param[in] tmin The upper trigger threshold
|
||||
//! \param[in] tmax The lower trigger threshold
|
||||
//!
|
||||
static inline void DCL_initMLOG(MLOG *q, float32_t *addr, uint16_t size, float32_t tmax, float32_t tmin, uint16_t div)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<MLOG_CHANS; i++)
|
||||
{
|
||||
// assign and clear capture frame, and initialize index to end of lead frame
|
||||
DCL_initLog(&(q->captFrame[i]), (addr + i*size), size);
|
||||
DCL_clearLog(&(q->captFrame[i]));
|
||||
}
|
||||
|
||||
q->trigMax = tmax;
|
||||
q->trigMin = tmin;
|
||||
q->tScale = div;
|
||||
q->sCount = div;
|
||||
q->mode = MLOG_idle;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Resets the MLOG module: clears all frame buffers and sets idle mode
|
||||
//! \param[in] q The MLOG structure
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline void DCL_resetMLOG(MLOG *q)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<MLOG_CHANS; i++)
|
||||
{
|
||||
DCL_clearLog(&(q->captFrame[i]));
|
||||
}
|
||||
|
||||
q->mode = MLOG_idle;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Changes the MLOG mode to "MLOG_armed". Only valid if current operating mode is "MLOG_idle"
|
||||
//! \param[in] q The MLOG structure
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline uint16_t DCL_armMLOG(MLOG *q)
|
||||
{
|
||||
q->mode = (q->mode == MLOG_idle) ? MLOG_armed : MLOG_idle;
|
||||
return(q->mode);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Runs the MLOG module
|
||||
//! \param[in] q The MLOG structure
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline uint16_t DCL_runMLOG(MLOG *q)
|
||||
{
|
||||
int i;
|
||||
|
||||
// skip sample unless counter reaches zero
|
||||
if (--(q->sCount) == 0)
|
||||
{
|
||||
switch(q->mode)
|
||||
{
|
||||
// MLOG not initialised
|
||||
case MLOG_invalid:
|
||||
break;
|
||||
|
||||
// idle: do nothing
|
||||
case MLOG_idle:
|
||||
break;
|
||||
|
||||
// armed: ready to begin capturing when either trigger threshold is crossed
|
||||
case MLOG_armed:
|
||||
// check for trigger condition
|
||||
if ((*(q->data[0]) > q->trigMax) || (*(q->data[0]) < q->trigMin))
|
||||
{
|
||||
for (i=0; i<MLOG_CHANS; i++)
|
||||
{
|
||||
DCL_fwriteLog(&(q->captFrame[i]), *(q->data[i]));
|
||||
}
|
||||
q->mode = MLOG_capture;
|
||||
}
|
||||
break;
|
||||
|
||||
// capture mode: acquiring data
|
||||
case MLOG_capture:
|
||||
// check for full capture frame
|
||||
if (q->captFrame[0].dptr == q->captFrame[0].fptr)
|
||||
{
|
||||
q->mode = MLOG_complete;
|
||||
}
|
||||
else
|
||||
{
|
||||
// log data channels
|
||||
for (i=0; i<MLOG_CHANS; i++)
|
||||
{
|
||||
DCL_fwriteLog(&(q->captFrame[i]), *(q->data[i]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// complete: do nothing - results available in capture buffer
|
||||
case MLOG_complete:
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
q->sCount = q->tScale;
|
||||
}
|
||||
|
||||
return(q->mode);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_MLOG_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,228 @@
|
||||
/* DCL_MLOG32.h - Multi-channel data logger (32-bit fixed point version)
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_MLOG32_H
|
||||
#define _C_DCL_MLOG32_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! \file DCL_MLOG32.h
|
||||
//! \brief Contains the public interface to the multi-channel data log module (MLOG32)
|
||||
//!
|
||||
|
||||
#include <stdint.h>
|
||||
#include "DCL_log32.h"
|
||||
|
||||
//! \brief Defines the number of MLOG32 channels
|
||||
//!
|
||||
#define MLOG32_CHANS 4
|
||||
|
||||
//! \brief Defines the MLOG32 structure
|
||||
//!
|
||||
typedef volatile struct dcl_mlog32 {
|
||||
LOG32 captFrame[MLOG32_CHANS]; //!< Capture data frames
|
||||
int32_t *data[MLOG32_CHANS]; //!< Data channel pointers
|
||||
int32_t trigMax; //!< Upper trigger threshold
|
||||
int32_t trigMin; //!< Lower trigger threshold
|
||||
uint16_t tScale; //!< Number of samples per log write
|
||||
uint16_t sCount; //!< Sample counter
|
||||
uint16_t mode; //!< Operating mode
|
||||
} MLOG32;
|
||||
|
||||
//! \brief Defines default values to initialise the MLOG32 structure
|
||||
//! Note: modify to match number of channels defined above
|
||||
//!
|
||||
#define MLOG32_DEFAULTS { { LOG32_DEFAULTS, LOG32_DEFAULTS, LOG32_DEFAULTS, LOG32_DEFAULTS }, \
|
||||
{ 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, \
|
||||
0.1, -0.1, 1, 1, 0 }
|
||||
|
||||
//! \brief Enumerated MLOG32 operating modes
|
||||
//!
|
||||
typedef enum
|
||||
{
|
||||
MLOG32_invalid = 0, //!< Buffer pointers not initialised
|
||||
MLOG32_idle, //!< Memory initialised but module not armed
|
||||
MLOG32_armed, //!< Armed: capturing monitor frame data and waiting for trigger
|
||||
MLOG32_capture, //!< Triggered: logging data into capture frame
|
||||
MLOG32_complete, //!< Full data frame captured and available for read-out
|
||||
MLOG32_numStates //!< Number of MLOG states
|
||||
} MLOG32_states;
|
||||
|
||||
|
||||
//! \brief Initializes the MLOG32 module
|
||||
//! \param[in] q The MLOG32 structure
|
||||
//! \param[in] addr The start address of the memory block
|
||||
//! \param[in] size The size of the memory block in 32-bit words
|
||||
//! \param[in] tmin The upper trigger threshold
|
||||
//! \param[in] tmax The lower trigger threshold
|
||||
//!
|
||||
static inline void DCL_initMLOG32(MLOG32 *q, int32_t *addr, uint16_t size, int32_t tmax, int32_t tmin, uint16_t div)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<MLOG32_CHANS; i++)
|
||||
{
|
||||
// assign and clear capture frame, and initialize index to end of lead frame
|
||||
DCL_initLog32(&(q->captFrame[i]), (addr + i*size), size);
|
||||
DCL_clearLog32(&(q->captFrame[i]));
|
||||
}
|
||||
|
||||
q->trigMax = tmax;
|
||||
q->trigMin = tmin;
|
||||
q->tScale = div;
|
||||
q->sCount = div;
|
||||
q->mode = MLOG32_idle;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Resets the MLOG32 module: clears all frame buffers and sets idle mode
|
||||
//! \param[in] q The MLOG32 structure
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline void DCL_resetMLOG32(MLOG32 *q)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<MLOG32_CHANS; i++)
|
||||
{
|
||||
DCL_clearLog32(&(q->captFrame[i]));
|
||||
}
|
||||
|
||||
q->mode = MLOG32_idle;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Changes the MLOG32 mode to "MLOG32_armed". Only valid if current operating mode is "MLOG32_idle"
|
||||
//! \param[in] q The MLOG32 structure
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline uint16_t DCL_armMLOG32(MLOG32 *q)
|
||||
{
|
||||
q->mode = (q->mode == MLOG32_idle) ? MLOG32_armed : MLOG32_idle;
|
||||
return(q->mode);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Runs the MLOG32 module
|
||||
//! \param[in] q The MLOG32 structure
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline uint16_t DCL_runMLOG32(MLOG32 *q)
|
||||
{
|
||||
int i;
|
||||
|
||||
// skip sample unless counter reaches zero
|
||||
if (--(q->sCount) == 0)
|
||||
{
|
||||
switch(q->mode)
|
||||
{
|
||||
// MLOG32 not initialised
|
||||
case MLOG32_invalid:
|
||||
break;
|
||||
|
||||
// idle: do nothing
|
||||
case MLOG32_idle:
|
||||
break;
|
||||
|
||||
// armed: ready to begin capturing when either trigger threshold is crossed
|
||||
case MLOG32_armed:
|
||||
// check for trigger condition
|
||||
if ((*(q->data[0]) > q->trigMax) || (*(q->data[0]) < q->trigMin))
|
||||
{
|
||||
for (i=0; i<MLOG32_CHANS; i++)
|
||||
{
|
||||
DCL_writeLog32(&(q->captFrame[i]), *(q->data[i]));
|
||||
}
|
||||
q->mode = MLOG32_capture;
|
||||
}
|
||||
break;
|
||||
|
||||
// capture mode: acquiring data
|
||||
case MLOG32_capture:
|
||||
// check for full capture frame
|
||||
if (q->captFrame[0].dptr == q->captFrame[0].fptr)
|
||||
{
|
||||
q->mode = MLOG32_complete;
|
||||
}
|
||||
else
|
||||
{
|
||||
// log data channels
|
||||
for (i=0; i<MLOG32_CHANS; i++)
|
||||
{
|
||||
DCL_writeLog32(&(q->captFrame[i]), *(q->data[i]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// complete: do nothing - results available in capture buffer
|
||||
case MLOG32_complete:
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
q->sCount = q->tScale;
|
||||
}
|
||||
|
||||
return(q->mode);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_MLOG32_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,565 @@
|
||||
/* DCL_NLPID.h - non-linear PID controller
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_NLPID_H
|
||||
#define _C_DCL_NLPID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! \file DCL_NLPID.h
|
||||
//! \brief Contains the public interface to the
|
||||
//! non-linear PID, PI, & NLF controller functions
|
||||
|
||||
#include "DCL.h"
|
||||
|
||||
//! \brief Sets the lower bound on the linear region semi-width
|
||||
//!
|
||||
#define DCL_DELTA_MIN 1.0e-04f
|
||||
|
||||
//! \brief Sets an upper bound on allowable controller gain, and
|
||||
//! therefore fixes the minimum linear region semi-width
|
||||
//!
|
||||
#define DCL_GAMMA_MAX 100
|
||||
|
||||
|
||||
//--- Non-linear PID controllers ---------------------------------------------
|
||||
|
||||
#pragma CODE_SECTION(DCL_updateNLPID,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_runNLPID_C1,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_runNLPID_C2,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_runNLF_C1,"dclfuncs")
|
||||
|
||||
//! \brief Defines the shadow DCL_NLPID controller structure
|
||||
//!
|
||||
typedef struct dcl_nlpid_sps {
|
||||
float32_t Kp; //!< Linear proportional gain
|
||||
float32_t Ki; //!< Linear integral gain
|
||||
float32_t Kd; //!< Linear derivative gain
|
||||
float32_t alpha_p; //!< P path non-linear exponent
|
||||
float32_t alpha_i; //!< I path non-linear exponent
|
||||
float32_t alpha_d; //!< D path non-linear exponent
|
||||
float32_t delta_p; //!< P path linearized range
|
||||
float32_t delta_i; //!< I path linearized range
|
||||
float32_t delta_d; //!< D path linearized range
|
||||
float32_t gamma_p; //!< P path gain limit
|
||||
float32_t gamma_i; //!< I path gain limit
|
||||
float32_t gamma_d; //!< D path gain limit
|
||||
float32_t c1; //!< D path filter coefficient 1
|
||||
float32_t c2; //!< D path filter coefficient 2
|
||||
float32_t Umax; //!< Upper saturation limit
|
||||
float32_t Umin; //!< Lower saturation limit
|
||||
} DCL_NLPID_SPS;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_NLPID structure
|
||||
//!
|
||||
#define NLPID_SPS_DEFAULTS { 1.0f, 0.0f, 0.0f, \
|
||||
1.0f, 1.0f, 1.0f, \
|
||||
0.1f, 0.1f, 0.1f, \
|
||||
1.0f, 1.0f, 1.0f, \
|
||||
1.0f, 0.0f, \
|
||||
1.0f, -1.0f }
|
||||
|
||||
//! \brief Defines the active DCL_NLPID controller structure
|
||||
//!
|
||||
typedef struct dcl_nlpid {
|
||||
float32_t Kp; //!< Linear proportional gain
|
||||
float32_t Ki; //!< Linear integral gain
|
||||
float32_t Kd; //!< Linear derivative gain
|
||||
float32_t alpha_p; //!< P path non-linear exponent
|
||||
float32_t alpha_i; //!< I path non-linear exponent
|
||||
float32_t alpha_d; //!< D path non-linear exponent
|
||||
float32_t delta_p; //!< P path linearized range
|
||||
float32_t delta_i; //!< I path linearized range
|
||||
float32_t delta_d; //!< D path linearized range
|
||||
float32_t gamma_p; //!< P path gain limit
|
||||
float32_t gamma_i; //!< I path gain limit
|
||||
float32_t gamma_d; //!< D path gain limit
|
||||
float32_t c1; //!< D path filter coefficient 1
|
||||
float32_t c2; //!< D path filter coefficient 2
|
||||
float32_t d2; //!< D path filter intermediate storage 1
|
||||
float32_t d3; //!< D path filter intermediate storage 2
|
||||
float32_t i7; //!< I path intermediate storage
|
||||
float32_t i16; //!< Intermediate saturation storage
|
||||
float32_t i18; //!< Spare
|
||||
float32_t Umax; //!< Upper saturation limit
|
||||
float32_t Umin; //!< Lower saturation limit
|
||||
DCL_NLPID_SPS *sps; //!< Pointer to shadow parameter structure
|
||||
DCL_CSS *css; //!< Pointer to controller support structure
|
||||
} DCL_NLPID;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_NLPID structure
|
||||
//!
|
||||
#define NLPID_DEFAULTS { 1.0f, 0.0f, 0.0f, \
|
||||
1.0f, 1.0f, 1.0f, \
|
||||
0.1f, 0.1f, 0.1f, \
|
||||
1.0f, 1.0f, 1.0f, \
|
||||
1.0f, 0.0f, \
|
||||
0.0f, 0.0f, \
|
||||
0.0f, 1.0f, 0.0f, \
|
||||
1.0f, -1.0f, \
|
||||
NULL_ADDR, NULL_ADDR }
|
||||
|
||||
//! \brief Resets DCL_NLPID internal storage data
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_resetNLPID(DCL_NLPID *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->d2 = p->d3 = p->i7 = 0.0f;
|
||||
p->i16 = 1.0f;
|
||||
DCL_RESTORE_INTS(v);
|
||||
}
|
||||
|
||||
//! \brief Copies control parameters from one DCL_NLPID structure to another
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_updateNLPID(DCL_NLPID *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
float32_t tau = (2.0f - p->sps->c1 * p->css->T) / (2.0f * p->sps->c1);
|
||||
float32_t ec2 = p->sps->c1 * (p->css->T - 2.0f * tau) / 2.0f;
|
||||
p->css->err |= ((p->sps->c2 < (ec2 - DEFAULT_FPU32_TOL)) || (p->sps->c2 > (ec2 + DEFAULT_FPU32_TOL))) ? ERR_PARAM_INVALID : ERR_NONE;
|
||||
p->css->err |= (p->sps->delta_p < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->sps->delta_i < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->sps->delta_d < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->sps->Umax <= p->sps->Umin) ? ERR_PARAM_INVALID : ERR_NONE;
|
||||
p->css->err |= (p->css->T <= 0.0f) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= ((p->sps->Kp < 0.0f) || (p->sps->Ki < 0.0f) || (p->sps->Kd < 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (p->css->sts == STS_UPDATE_PENDING)
|
||||
{
|
||||
v = DCL_DISABLE_INTS;
|
||||
p->Kp = p->sps->Kp;
|
||||
p->Ki = p->sps->Ki;
|
||||
p->Kd = p->sps->Kd;
|
||||
p->alpha_p = p->sps->alpha_p;
|
||||
p->alpha_i = p->sps->alpha_i;
|
||||
p->alpha_d = p->sps->alpha_d;
|
||||
p->delta_p = p->sps->delta_p;
|
||||
p->delta_i = p->sps->delta_i;
|
||||
p->delta_d = p->sps->delta_d;
|
||||
p->gamma_p = p->sps->gamma_p;
|
||||
p->gamma_i = p->sps->gamma_i;
|
||||
p->gamma_d = p->sps->gamma_d;
|
||||
p->c1 = p->sps->c1;
|
||||
p->c2 = p->sps->c2;
|
||||
p->Umax = p->sps->Umax;
|
||||
p->Umin = p->sps->Umin;
|
||||
DCL_RESTORE_INTS(v);
|
||||
DCL_CLEAR_UPDATE_REQUEST(p);
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Copies control parameters from one DCL_NLPID structure to another
|
||||
//! Implemented as an external assembly module
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \return None
|
||||
//!
|
||||
extern void DCL_fupdateNLPID(DCL_NLPID *p);
|
||||
|
||||
//! \brief Loads the shadow derivative LP filter coefficients
|
||||
//! Note: active coefficients unchanged DCL_updateNLPID() called
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \param[in] fc The desired filter bandwidth in Hz
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setNLPIDfilterBW(DCL_NLPID *p, float32_t fc)
|
||||
{
|
||||
float32_t tau = 1.0f / (2.0f * CONST_PI_32 * fc);
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((fc >= 1.0f / (2.0f * p->css->T)) || (fc <= 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
p->sps->c1 = 2.0f / (p->css->T + 2.0f * tau);
|
||||
p->sps->c2 = (p->css->T - 2.0f * tau) / (p->css->T + 2.0f * tau);
|
||||
}
|
||||
|
||||
//! \brief Loads the NLPID derivative path filter active coefficients
|
||||
//! Note: new coefficients take effect immediately. SPS &
|
||||
//! CSS contents are unaffected.
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \param[in] fc The desired filter bandwidth in Hz
|
||||
//! \param[in] T The controller update rate in seconds
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setActiveNLPIDfilterBW(DCL_NLPID *p, float32_t fc, float32_t T)
|
||||
{
|
||||
float32_t tau;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((fc >= 1.0f / (2.0f * T)) || (fc <= 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
tau = 1.0f / (2.0f * CONST_PI_32 * fc);
|
||||
p->c1 = 2.0f / (T + 2.0f * tau);
|
||||
p->c2 = (T - 2.0f * tau) / (T + 2.0f * tau);
|
||||
}
|
||||
|
||||
//! \brief Returns the derivative LP filter bandwidth in Hz
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \return The filter bandwidth in Hz
|
||||
//!
|
||||
static inline float32_t DCL_getNLPIDfilterBW(DCL_NLPID *p)
|
||||
{
|
||||
float32_t tau = ((2.0f - p->c1 * p->css->T) / (2.0f * p->c1));
|
||||
return(1.0f / (2.0f * CONST_PI_32 * tau));
|
||||
}
|
||||
|
||||
//! \brief Returns the linearized region gain for specified (alpha,delta)
|
||||
//! \param[in] alpha The non-linear gain
|
||||
//! \param[in] delta The linear region semi-width
|
||||
//! \return The linear region gain
|
||||
//!
|
||||
static inline float32_t DCL_getNLPIDgamma(float32_t alpha, float32_t delta)
|
||||
{
|
||||
return((float32_t) powf(delta, (alpha - 1.0f)));
|
||||
}
|
||||
|
||||
//! \brief Returns the semi-width of the linear gain region for specified (alpha,gamma)
|
||||
//! \param[in] alpha The non-linear gain
|
||||
//! \param[in] gamma The linear region gain
|
||||
//! \return The linear region semi-width
|
||||
//!
|
||||
static inline float32_t DCL_getNLPIDdelta(float32_t alpha, float32_t gamma)
|
||||
{
|
||||
return((float32_t) powf(gamma, (1.0f / (alpha - 1.0f))));
|
||||
}
|
||||
|
||||
//! \brief Computes the linear gain region for specified (alpha, delta)
|
||||
//! Implemented as external assembly module
|
||||
//! \param[in] alpha The nonlinear tuning parameter (0.0f <= alpha <= 2.0f)
|
||||
//! \param[in] delta The linear region semi-width (0.0f < delta <= 1.0f)
|
||||
//! \return The linear region gain (gamma)
|
||||
//!
|
||||
extern float32_t DCL_calcGamma(float32_t alpha, float32_t delta);
|
||||
|
||||
//! \brief Computes the linearized gains for each path
|
||||
//! Note: active coefficients not update DCL_updateNLPID() called
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setNLPIDgamma(DCL_NLPID *p)
|
||||
{
|
||||
float32_t xP = (float32_t) powf(p->sps->delta_p, (p->sps->alpha_p - 1.0f));
|
||||
float32_t xI = (float32_t) powf(p->sps->delta_i, (p->sps->alpha_i - 1.0f));
|
||||
float32_t xD = (float32_t) powf(p->sps->delta_d, (p->sps->alpha_d - 1.0f));
|
||||
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((p->sps->delta_p > 1.0f) || (p->sps->delta_p > 1.0f) || (p->sps->delta_p > 1.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->sps->delta_p < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->sps->delta_i < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->sps->delta_d < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= ((xP > DCL_GAMMA_MAX) || (xI > DCL_GAMMA_MAX) || (xD > DCL_GAMMA_MAX)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
p->sps->gamma_p = xP;
|
||||
p->sps->gamma_i = xI;
|
||||
p->sps->gamma_d = xD;
|
||||
}
|
||||
|
||||
//! \brief Computes the linearized gains for each path and loads the
|
||||
//! parameters in the active NLPID structure
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setActiveNLPIDgamma(DCL_NLPID *p)
|
||||
{
|
||||
float32_t xP = (float32_t) powf(p->delta_p, (p->alpha_p - 1.0f));
|
||||
float32_t xI = (float32_t) powf(p->delta_i, (p->alpha_i - 1.0f));
|
||||
float32_t xD = (float32_t) powf(p->delta_d, (p->alpha_d - 1.0f));
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((p->delta_p > 1.0f) || (p->delta_p > 1.0f) || (p->delta_p > 1.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->delta_p < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->delta_i < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (p->delta_d < DCL_DELTA_MIN) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= ((xP > DCL_GAMMA_MAX) || (xI > DCL_GAMMA_MAX) || (xD > DCL_GAMMA_MAX)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
p->gamma_p = xP;
|
||||
p->gamma_i = xI;
|
||||
p->gamma_d = xD;
|
||||
}
|
||||
|
||||
//! \brief Executes a parallel form non-linear PID controller on the FPU32
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \param[in] lk External output clamp flag
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runNLPID_C1(DCL_NLPID *p, float32_t rk, float32_t yk, float32_t lk)
|
||||
{
|
||||
float32_t v1, v2, v3, v4, v5, v8, v9, v10, v12, v13, v14, v15;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (p->css->sts & STS_CONTROLLER_RUNNING) ? ERR_CONTROLLER : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
DCL_CONTROLLER_BEGIN(p);
|
||||
#endif
|
||||
|
||||
// pre-conditioning block
|
||||
v1 = (rk - yk) * 0.5f;
|
||||
v2 = (v1 < 0.0f) ? -1.0f : 1.0f;
|
||||
v3 = fabsf(v1);
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((p->alpha_p >= 2.0f) || (p->alpha_p <= 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= ((p->alpha_i >= 2.0f) || (p->alpha_i <= 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= ((p->alpha_d >= 2.0f) || (p->alpha_d <= 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (v3 > 1.0f) ? ERR_INPUT_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
// non-linear modules
|
||||
v4 = ((v3 > p->delta_p) ? (v2 * (float32_t) powf(v3, p->alpha_p)) : (v1 * p->gamma_p));
|
||||
v5 = ((v3 > p->delta_i) ? (v2 * (float32_t) powf(v3, p->alpha_i)) : (v1 * p->gamma_i));
|
||||
v9 = ((v3 > p->delta_d) ? (v2 * (float32_t) powf(v3, p->alpha_d)) : (v1 * p->gamma_d));
|
||||
|
||||
// integral path
|
||||
v8 = (v5 * p->Kp * p->Ki * p->i16) + p->i7;
|
||||
p->i7 = v8;
|
||||
|
||||
// derivative path
|
||||
v10 = v9 * p->Kd * p->c1;
|
||||
v12 = v10 - p->d2 - p->d3;
|
||||
p->d2 = v10;
|
||||
p->d3 = v12 * p->c2;
|
||||
|
||||
// output sum & clamp
|
||||
v13 = (p->Kp * (v4 + v12)) + v8;
|
||||
#ifndef __TMS320C28XX_CLA__
|
||||
v14 = __fsat(v13, p->Umax, p->Umin);
|
||||
#else
|
||||
v14 = (v13 > p->Umax) ? p->Umax : v13;
|
||||
v14 = (v14 < p->Umin) ? p->Umin : v14;
|
||||
#endif
|
||||
v15 = (v14 == v13) ? 1.0f : 0.0f;
|
||||
p->i16 = v15 * lk;
|
||||
|
||||
#ifdef DCL_TESTPOINTS_ENABLED
|
||||
p->css->tpt = v4;
|
||||
#endif
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
DCL_CONTROLLER_END(p);
|
||||
#endif
|
||||
|
||||
return(v14);
|
||||
}
|
||||
|
||||
//! \brief Executes a series form non-linear PID controller on the FPU32
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \param[in] lk External output clamp flag
|
||||
//! \return The control effort
|
||||
//!
|
||||
static inline float32_t DCL_runNLPID_C2(DCL_NLPID *p, float32_t rk, float32_t yk, float32_t lk)
|
||||
{
|
||||
float32_t v1, v2, vd2, v3, vd3, v4, v5, v6, v8, v9, v12, v15, v16, v17;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (p->css->sts & STS_CONTROLLER_RUNNING) ? ERR_CONTROLLER : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
DCL_CONTROLLER_BEGIN(p);
|
||||
#endif
|
||||
|
||||
// pre-conditioning block for P & I
|
||||
v1 = (rk - yk) * 0.5f;
|
||||
v2 = (v1 < 0.0f) ? -1.0f : 1.0f;
|
||||
v3 = fabsf(v1);
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((p->alpha_p >= 2.0f) || (p->alpha_p <= 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= ((p->alpha_i >= 2.0f) || (p->alpha_i <= 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (v3 > 1.0f) ? ERR_INPUT_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
// P & I non-linear modules
|
||||
v4 = ((v3 > p->delta_p) ? (v2 * (float32_t) powf(v3, p->alpha_p)) : (v1 * p->gamma_p));
|
||||
v5 = ((v3 > p->delta_i) ? (v2 * (float32_t) powf(v3, p->alpha_i)) : (v1 * p->gamma_i));
|
||||
|
||||
// D path non-linear block
|
||||
vd2 = (yk < 0.0f) ? -1.0f : 1.0f;
|
||||
vd3 = fabsf(yk);
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((p->alpha_d >= 2.0f) || (p->alpha_d <= 0.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
p->css->err |= (vd3 > 1.0f) ? ERR_INPUT_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
v6 = ((vd3 > p->delta_d) ? (vd2 * (float32_t) powf(vd3, p->alpha_d)) : (yk * p->gamma_d));
|
||||
|
||||
// integral path
|
||||
v8 = (v5 * p->Kp * p->Ki * p->i16) + p->i7;
|
||||
p->i7 = v8;
|
||||
|
||||
// derivative path
|
||||
v15 = v6 * p->Kd * p->c1;
|
||||
v16 = v15 - p->d2 - p->d3;
|
||||
p->d2 = v15;
|
||||
p->d3 = v16 * p->c2;
|
||||
|
||||
// output sum & clamp
|
||||
v9 = (p->Kp * (v4 - v16)) + v8;
|
||||
#ifndef __TMS320C28XX_CLA__
|
||||
v17 = __fsat(v9, p->Umax, p->Umin);
|
||||
#else
|
||||
v17 = (v9 > p->Umax) ? p->Umax : v9;
|
||||
v17 = (v17 < p->Umin) ? p->Umin : v17;
|
||||
#endif
|
||||
v12 = (v17 == v9) ? 1.0f : 0.0f;
|
||||
p->i16 = v12 * lk;
|
||||
|
||||
#ifdef DCL_TESTPOINTS_ENABLED
|
||||
p->css->tpt = v1;
|
||||
#endif
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
DCL_CONTROLLER_END(p);
|
||||
#endif
|
||||
|
||||
return(v17);
|
||||
}
|
||||
|
||||
//! \brief Executes a series form non-linear PID controller on the FPU32
|
||||
//! Note: this prototype covers a future assembly implementation
|
||||
//! \param[in] p Pointer to the DCL_NLPID structure
|
||||
//! \param[in] rk The controller set-point reference
|
||||
//! \param[in] yk The measured feedback value
|
||||
//! \param[in] lk External output clamp flag
|
||||
//! \return The control effort
|
||||
//!
|
||||
extern float32_t DCL_runNLPID_C3(DCL_NLPID *p, float32_t rk, float32_t yk, float32_t lk);
|
||||
|
||||
//--- Basic non-linear function ----------------------------------------------
|
||||
|
||||
//! \brief Executes the non-linear control function on the FPU32
|
||||
//! \param[in] x The input variable
|
||||
//! \param[in] alpha The non-linear exponent
|
||||
//! \param[in] delta The linear region semi-width
|
||||
//! \return The non-linear output
|
||||
//!
|
||||
static inline float32_t DCL_runNLF_C1(float32_t x, float32_t alpha, float32_t delta)
|
||||
{
|
||||
float32_t v2 = (x < 0.0f) ? -1.0f : 1.0f;
|
||||
float32_t v3 = fabsf(x);
|
||||
|
||||
return((v3 > delta) ? (v2 * (float32_t) powf(v3, alpha)) : (x * powf(delta, (alpha - 1.0f))));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_NLPID_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,323 @@
|
||||
/* DCL_TCM.h - Transient Capture Module header file
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_TCM_H
|
||||
#define _C_DCL_TCM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! \file DCL_TCM.h
|
||||
//! \brief Contains the public interface to the Transient Capture Module (TCM)
|
||||
//!
|
||||
|
||||
#include <stdint.h>
|
||||
#include "DCL_fdlog.h"
|
||||
|
||||
|
||||
//! \brief Defines the TCM structure
|
||||
//!
|
||||
typedef volatile struct dcl_tcm {
|
||||
FDLOG moniFrame; //!< Monitor data frame
|
||||
FDLOG leadFrame; //!< Lead data frame
|
||||
FDLOG captFrame; //!< Capture data frame
|
||||
float32_t trigMax; //!< Upper trigger threshold
|
||||
float32_t trigMin; //!< Lower trigger threshold
|
||||
uint16_t mode; //!< Operating mode
|
||||
uint16_t lead; //!< Lead frame size in 32-bit words = trigger crossing index
|
||||
} TCM;
|
||||
|
||||
|
||||
//! \brief Defines default values to initialize the TCM structure
|
||||
//!
|
||||
#define TCM_DEFAULTS { FDLOG_DEFAULTS, FDLOG_DEFAULTS, FDLOG_DEFAULTS, 0.1, -0.1, 0, 10 }
|
||||
|
||||
|
||||
//! \brief Enumerated TCM operating modes
|
||||
//!
|
||||
typedef enum dcl_tcm_states {
|
||||
TCM_invalid = 0, //!< Buffer pointers not initialized
|
||||
TCM_idle, //!< Memory initialized but module not armed
|
||||
TCM_armed, //!< Armed: capturing monitor frame data and waiting for trigger
|
||||
TCM_capture, //!< Triggered: logging data into capture frame and un-winding monitor frame
|
||||
TCM_complete, //!< Full data frame captured and available for read-out
|
||||
TCM_numStates //!< Number of TCM states
|
||||
} TCM_states;
|
||||
|
||||
|
||||
//! \brief Resets the TCM module: clears buffers and sets idle mode
|
||||
//! \param[in] q The TCM structure
|
||||
//! \param[in] addr The start address of the memory block
|
||||
//! \param[in] size The size of the memory block in 32-bit words
|
||||
//! \param[in] lead The length of the lead frame in samples
|
||||
//! \param[in] tmin The upper trigger threshold
|
||||
//! \param[in] tmax The lower trigger threshold
|
||||
//!
|
||||
static inline void DCL_initTCM(TCM *q, float32_t *addr, uint16_t size, uint16_t lead, float32_t tmin, float32_t tmax)
|
||||
{
|
||||
// assign and clear capture frame, and initialize index to end of lead frame
|
||||
DCL_initLog(&(q->captFrame), addr, size);
|
||||
DCL_clearLog(&(q->captFrame));
|
||||
q->captFrame.dptr = q->captFrame.fptr + lead;
|
||||
|
||||
// assign lead & monitor frame pointers
|
||||
DCL_initLog(&(q->leadFrame), addr, lead);
|
||||
DCL_initLog(&(q->moniFrame), q->captFrame.lptr - lead + 1, lead);
|
||||
|
||||
// load remaining TCM vars
|
||||
q->lead = lead;
|
||||
q->trigMax = tmax;
|
||||
q->trigMin = tmin;
|
||||
q->mode = TCM_idle;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Resets the TCM module: clears all frame buffers and sets idle mode
|
||||
//! \param[in] q The TCM structure
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline void DCL_resetTCM(TCM *q)
|
||||
{
|
||||
DCL_clearLog(&(q->captFrame));
|
||||
q->captFrame.dptr = q->captFrame.fptr + q->lead - 1;
|
||||
DCL_resetLog(&(q->leadFrame));
|
||||
DCL_resetLog(&(q->moniFrame));
|
||||
q->mode = TCM_idle;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Changes the TCM mode to "TCM_armed". Only valid if current operating mode is "TCM_idle"
|
||||
//! \param[in] q The TCM structure
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline uint16_t DCL_armTCM(TCM *q)
|
||||
{
|
||||
q->mode = (q->mode == TCM_idle) ? TCM_armed : TCM_idle;
|
||||
return(q->mode);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Runs the TCM module
|
||||
//! \param[in] q The TCM structure
|
||||
//! \param[in] data The input data
|
||||
//! \return The operating mode
|
||||
//!
|
||||
static inline uint16_t DCL_runTCM(TCM *q, float32_t data)
|
||||
{
|
||||
switch(q->mode)
|
||||
{
|
||||
// TCM not initialized
|
||||
case TCM_invalid:
|
||||
break;
|
||||
|
||||
// idle: do nothing
|
||||
case TCM_idle:
|
||||
break;
|
||||
|
||||
// armed: ready to begin capturing when either trigger threshold is crossed
|
||||
case TCM_armed:
|
||||
// check for trigger condition
|
||||
if ((data > q->trigMax) || (data < q->trigMin))
|
||||
{
|
||||
// capture first data point & switch to capture mode
|
||||
DCL_writeLog(&(q->captFrame), data);
|
||||
DCL_writeLog(&(q->leadFrame), DCL_readLog(&(q->moniFrame)));
|
||||
q->mode = TCM_capture;
|
||||
}
|
||||
else
|
||||
{
|
||||
// log data into monitor frame
|
||||
DCL_writeLog(&(q->moniFrame), data);
|
||||
}
|
||||
break;
|
||||
|
||||
// capture mode: acquiring data
|
||||
case TCM_capture:
|
||||
// check for full capture frame
|
||||
if (q->captFrame.dptr > q->captFrame.fptr)
|
||||
{
|
||||
// write data into main frame
|
||||
DCL_writeLog(&(q->captFrame), data);
|
||||
|
||||
// check for full lead frame
|
||||
if (q->leadFrame.dptr > q->leadFrame.fptr)
|
||||
{
|
||||
// un-wind monitor data into lead frame
|
||||
DCL_writeLog(&(q->leadFrame), DCL_readLog(&(q->moniFrame)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TCM complete, capture frame spans full buffer
|
||||
q->captFrame.fptr = q->leadFrame.fptr;
|
||||
q->captFrame.dptr = q->captFrame.fptr;
|
||||
q->mode = TCM_complete;
|
||||
}
|
||||
break;
|
||||
|
||||
// complete: do nothing - results available in capture buffer
|
||||
case TCM_complete:
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
return(q->mode);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Computes ITAE performance index from a log of servo error.
|
||||
//! Assembly function.
|
||||
//! \param[in] elog The servo error log
|
||||
//! \param[in] prd The sampling period in seconds
|
||||
//! \return The ITAE index
|
||||
//!
|
||||
extern float32_t DCL_runITAE_C1(FDLOG *elog, float32_t prd);
|
||||
|
||||
|
||||
//! \brief Computes ITAE performance index from a log of servo error.
|
||||
//! \param[in] elog The servo error log
|
||||
//! \param[in] prd The sampling period in seconds
|
||||
//! \return The ITAE index
|
||||
//!
|
||||
static inline float32_t DCL_runITAE_C2(FDLOG *elog, float32_t prd)
|
||||
{
|
||||
float32_t tim = 0.0f;
|
||||
float32_t rlt = 0.0f;
|
||||
|
||||
// set index pointer to buffer start
|
||||
DCL_resetLog(elog);
|
||||
|
||||
// accumulate ITAE data
|
||||
while (elog->dptr <= elog->lptr)
|
||||
{
|
||||
rlt += fabs(*(elog->dptr++)) * tim;
|
||||
tim += prd;
|
||||
}
|
||||
DCL_resetLog(elog);
|
||||
|
||||
return(rlt);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Computes IAE performance index from a log of servo error.
|
||||
//! Assembly function.
|
||||
//! \param[in] elog The servo error log
|
||||
//! \return The IAE index
|
||||
//!
|
||||
extern float32_t DCL_runIAE_C1(FDLOG *elog);
|
||||
|
||||
|
||||
//! \brief Computes IAE performance index from a log of servo error.
|
||||
//! \param[in] elog The servo error log
|
||||
//! \return The IAE index
|
||||
//!
|
||||
static inline float32_t DCL_runIAE_C2(FDLOG *elog)
|
||||
{
|
||||
float32_t rlt = 0.0f;
|
||||
|
||||
// set index pointer to buffer start
|
||||
DCL_resetLog(elog);
|
||||
|
||||
// accumulate IAE data
|
||||
while (elog->dptr <= elog->lptr)
|
||||
{
|
||||
rlt += fabs(*(elog->dptr++));
|
||||
}
|
||||
DCL_resetLog(elog);
|
||||
|
||||
return(rlt);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Computes IES performance index from a log of servo error.
|
||||
//! Assembly function.
|
||||
//! \param[in] elog The servo error log
|
||||
//! \return The IES index
|
||||
//!
|
||||
extern float32_t DCL_runIES_C1(FDLOG *elog);
|
||||
|
||||
|
||||
//! \brief Computes IES performance index from a log of servo error.
|
||||
//! \param[in] elog The servo error log
|
||||
//! \return The IES index
|
||||
//!
|
||||
static inline float32_t DCL_runIES_C2(FDLOG *elog)
|
||||
{
|
||||
float32_t err;
|
||||
float32_t rlt = 0.0f;
|
||||
|
||||
// set index pointers to buffer start
|
||||
DCL_resetLog(elog);
|
||||
|
||||
// accumulate IES data
|
||||
while (elog->dptr <= elog->lptr)
|
||||
{
|
||||
err = *(elog->dptr++);
|
||||
rlt += (err * err);
|
||||
}
|
||||
|
||||
// restore index pointer
|
||||
DCL_resetLog(elog);
|
||||
|
||||
return(rlt);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_TCM_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,274 @@
|
||||
/* DCL_fdlog.h - 32-bit floating-point data logger
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_FDLOG_H
|
||||
#define _C_DCL_FDLOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "DCL.h"
|
||||
#include <stdint.h>
|
||||
|
||||
//! \file DCL_fdlog.h
|
||||
//!
|
||||
//! \brief Defines the single precision data buffer structure used in
|
||||
//! the DCL.
|
||||
//!
|
||||
//! \details The FDLOG structure contains three pointers which define
|
||||
//! the start and end of a memory block, and index into it.
|
||||
//! Manipulation of the indexing pointer permits linear and
|
||||
//! circular buffers, stacks, data logs, etc. to be implemented
|
||||
//! with a common data structure. An example of initialization
|
||||
//! and use is shown below:
|
||||
//!
|
||||
//! \code
|
||||
//! #pragma DATA_SECTION(r_Array, "DataLogSection")
|
||||
//! float32_t r_Array[FDLOG_DEFAULT_SIZE];
|
||||
//! FDLOG rBuf = FDLOG_DEFAULTS;
|
||||
//! float32_t x, y = 1.234f;
|
||||
//!
|
||||
//! DCL_createFDLOG(&rBuf, r_Array, FDLOG_DEFAULT_SIZE);
|
||||
//! DCL_clearFDLOG(&rBuf);
|
||||
//!
|
||||
//! DCL_writeFDLOG(&rBuf, y);
|
||||
//! x = readFDLOG(&rBuf);
|
||||
//! \endcode
|
||||
//!
|
||||
typedef volatile struct dcl_fdlog {
|
||||
float32_t *fptr; //!< Pointer to first buffer element
|
||||
float32_t *lptr; //!< Pointer to last buffer element
|
||||
float32_t *dptr; //!< Data index pointer
|
||||
} FDLOG;
|
||||
|
||||
|
||||
//! \brief Function name compatibility with DCL version 1
|
||||
//!
|
||||
#define DCL_createLog DCL_initLog
|
||||
|
||||
//! \brief Defines a default size for the FDLOG buffer
|
||||
//!
|
||||
#define FDLOG_DEFAULT_SIZE 0x0400
|
||||
|
||||
//! \brief Defines default values to initialise the FDLOG structure
|
||||
//!
|
||||
#define FDLOG_DEFAULTS { 0x00000000, \
|
||||
0x00000000, \
|
||||
0x00000000 \
|
||||
}
|
||||
|
||||
|
||||
/******************** macro definitions ********************/
|
||||
|
||||
//! \brief Distance from indexed element to end of buffer
|
||||
//!
|
||||
#define FDLOG_SPACE(buf) ((buf)->lptr - (buf)->dptr + 1)
|
||||
|
||||
//! \brief Total buffer size in 32-bit words
|
||||
//!
|
||||
#define FDLOG_SIZE(buf) ((buf)->lptr - (buf)->fptr + 1)
|
||||
|
||||
//! \brief Current indexed element
|
||||
//!
|
||||
#define FDLOG_ELEMENT(buf) ((buf)->dptr - (buf)->fptr + 1)
|
||||
|
||||
//! \brief Index pointer is at start of buffer
|
||||
//!
|
||||
#define FDLOG_START(buf) ((buf)->dptr == (buf)->fptr)
|
||||
|
||||
//! \brief Index pointer is at end of buffer
|
||||
//!
|
||||
#define FDLOG_END(buf) ((buf)->dptr == (buf)->lptr)
|
||||
|
||||
//! \brief Indexed pointer not in buffer range
|
||||
//!
|
||||
#define FDLOG_OUT_OF_RANGE(buf) (((buf)->dptr < (buf)->fptr) || ((buf)->dptr > (buf)->lptr))
|
||||
|
||||
//! \brief Check if the buffer has a non-zero size
|
||||
//!
|
||||
#define FDLOG_EXISTS(buf) ((buf)->lptr != (buf)->fptr)
|
||||
|
||||
|
||||
/******************** inline functions ********************/
|
||||
|
||||
//! \brief Resets all structure pointers to null value
|
||||
//! \param[in] p The FDLOG structure
|
||||
//!
|
||||
static inline void DCL_deleteLog(FDLOG *p) { p->dptr = p->lptr = p->fptr = 0; }
|
||||
|
||||
//! \brief Resets the data index pointer to start of buffer
|
||||
//! \param[in] p The FDLOG structure
|
||||
//!
|
||||
static inline void DCL_resetLog(FDLOG *p) { p->dptr = p->fptr; }
|
||||
|
||||
//! \brief Assigns the buffer pointers to a memory block or array and
|
||||
//! sets the data index pointer to the first address
|
||||
//! \param[in] p The FDLOG structure
|
||||
//! \param[in] addr The start address of the memory block
|
||||
//! \param[in] size The length of the memory block in 32-bit words
|
||||
//!
|
||||
static inline void DCL_initLog(FDLOG *p, float32_t *addr, uint16_t size)
|
||||
{
|
||||
p->fptr = addr;
|
||||
p->lptr = addr + size - 1;
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
//! \brief Writes a data point into the buffer and advances the
|
||||
//! indexing pointer, wrapping if necessary.
|
||||
//! Returns the over-written data value for delay line or FIFO
|
||||
//! implementation.
|
||||
//! \param[in] p The FDLOG structure
|
||||
//! \param[in] data The input data value
|
||||
//! \return The over-written data value
|
||||
//!
|
||||
static inline float32_t DCL_writeLog(FDLOG *p, float32_t data)
|
||||
{
|
||||
float32_t rv = *(p->dptr); // save existing data
|
||||
|
||||
// write new data to log
|
||||
*(p->dptr++) = data;
|
||||
|
||||
// check for end of buffer & wrap if necessary
|
||||
if (p->dptr > p->lptr)
|
||||
{
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
//! \brief Fills the buffer with a given data value and resets the
|
||||
//! data index pointer to the start of the buffer
|
||||
//! \param[in] p The FDLOG structure
|
||||
//! \param[in] data The fill data value
|
||||
//!
|
||||
static inline void DCL_fillLog(FDLOG *p, float32_t data)
|
||||
{
|
||||
p->dptr = p->lptr;
|
||||
*(p->dptr) = data;
|
||||
while (p->dptr > p->fptr)
|
||||
{
|
||||
*(--p->dptr) = data;
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Clears the buffer contents by writing 0 to all elements and
|
||||
//! resets the data index pointer to the start of the buffer.
|
||||
//! Deprecated in DCL version 2: alias for DCL_fillLog.
|
||||
//!
|
||||
#define DCL_clearLog(bufAddr) DCL_fillLog(bufAddr,0)
|
||||
|
||||
|
||||
//! \brief Reads a data point from the buffer and then advances the
|
||||
//! indexing pointer, wrapping if necessary
|
||||
//! \param[in] p The FDLOG structure
|
||||
//! \return The indexed data value
|
||||
//!
|
||||
static inline float32_t DCL_readLog(FDLOG *p)
|
||||
{
|
||||
float32_t rv = *(p->dptr++);
|
||||
|
||||
if (p->dptr > p->lptr)
|
||||
{
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
//! \brief Copies the contents of one log (q) into another (p) and
|
||||
//! resets both buffer index pointers. Both logs must have the
|
||||
//! same length.
|
||||
//! \param[in] p The destination FDLOG structure
|
||||
//! \param[in] q The source FDLOG structure
|
||||
//!
|
||||
static inline void DCL_copyLog(FDLOG *p, FDLOG *q)
|
||||
{
|
||||
p->dptr = p->lptr;
|
||||
q->dptr = q->lptr;
|
||||
*(p->dptr) = *(q->dptr);
|
||||
while (p->dptr > p->fptr)
|
||||
{
|
||||
*(--p->dptr) = *(--q->dptr);
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Reads a data point into the buffer and then advances the
|
||||
//! indexing pointer, wrapping if necessary
|
||||
//! Fast assembly form of DCL_readLog()
|
||||
//! Implemented as external assembly module
|
||||
//! \param[in] p The FDLOG structure
|
||||
//! \return The indexed data value
|
||||
//!
|
||||
extern float32_t DCL_freadLog(FDLOG *p);
|
||||
|
||||
//! \brief Writes a data point into the buffer and advances the indexing
|
||||
//! pointer, wrapping if necessary.
|
||||
//! Returns the over-written data value for delay line or FIFO
|
||||
//! implementation.
|
||||
//! Fast assembly form of DCL_writeLog()
|
||||
//! Implemented as external assembly module
|
||||
//! \param[in] p The FDLOG structure
|
||||
//! \param[in] data The input data value
|
||||
//! \return The over-written data value
|
||||
//!
|
||||
extern float32_t DCL_fwriteLog(FDLOG *p, float32_t data);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_FDLOG_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,247 @@
|
||||
/* DCL_fdlog64.h - 64-bit floating-point data buffer utility
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_FDLOG64_H
|
||||
#define _C_DCL_FDLOG64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "DCL.h"
|
||||
#include <stdint.h>
|
||||
|
||||
//! \file DCL_fdlog64.h
|
||||
//!
|
||||
//! \brief Defines the double precision data buffer structure used in the DCL
|
||||
//!
|
||||
//! \details The FDLOG64 structure contains three pointers which define the
|
||||
//! start and end of a memory block, and index into it.
|
||||
//! Manipulation of the indexing pointer permits linear and
|
||||
//! circular buffers, stacks, data logs, etc. to be implemented
|
||||
//! with a common data structure. An example of initialization
|
||||
//! and use is shown below:
|
||||
//!
|
||||
//! \code
|
||||
//! #pragma DATA_SECTION(r_Array, "DataLogSection")
|
||||
//! float64_t r_Array[FDLOG_DEFAULT_SIZE];
|
||||
//! FDLOG64 rBuf = FDLOG64_DEFAULTS;
|
||||
//! float64_t x, y = 1.234L;
|
||||
//!
|
||||
//! DCL_createFDLOG64(&rBuf, r_Array, FDLOG64_DEFAULT_SIZE);
|
||||
//! DCL_clearFDLOG64(&rBuf);
|
||||
//!
|
||||
//! DCL_writeFDLOG64(&rBuf, y);
|
||||
//! x = readFDLOG64(&rBuf);
|
||||
//! \endcode
|
||||
//!
|
||||
typedef volatile struct dcl_fdlog64 {
|
||||
float64_t *fptr; //!< Pointer to first buffer element
|
||||
float64_t *lptr; //!< Pointer to last buffer element
|
||||
float64_t *dptr; //!< Data index pointer
|
||||
} FDLOG64;
|
||||
|
||||
//! \brief Defines a default size for the FDLOG64 buffer
|
||||
//!
|
||||
#define FDLOG64_DEFAULT_SIZE 0x0400
|
||||
|
||||
//! \brief Defines default values to initialize the FDLOG64 structure
|
||||
//!
|
||||
#define FDLOG64_DEFAULTS { 0x00000000, \
|
||||
0x00000000, \
|
||||
0x00000000 \
|
||||
}
|
||||
|
||||
|
||||
/******************** macro definitions ********************/
|
||||
|
||||
//! \brief Distance from indexed element to end of buffer
|
||||
//!
|
||||
#define FDLOG64_SPACE(buf) ( (buf)->lptr - (buf)->dptr + 1 )
|
||||
|
||||
//! \brief Total buffer size in 64-bit words
|
||||
//!
|
||||
#define FDLOG64_SIZE(buf) ( (buf)->lptr - (buf)->fptr + 1 )
|
||||
|
||||
//! \brief Current indexed element
|
||||
//!
|
||||
#define FDLOG64_ELEMENT(buf) ( (buf)->dptr - (buf)->fptr + 1 )
|
||||
|
||||
//! \brief Index pointer is at start of buffer
|
||||
//!
|
||||
#define FDLOG64_START(buf) ( (buf)->dptr == (buf)->fptr )
|
||||
|
||||
//! \brief Index pointer is at end of buffer
|
||||
//!
|
||||
#define FDLOG64_END(buf) ( (buf)->dptr == (buf)->lptr )
|
||||
|
||||
//! \brief Indexed pointer not in buffer range
|
||||
//!
|
||||
#define FDLOG64_OUT_OF_RANGE(buf) ( ((buf)->dptr < (buf)->fptr) || ((buf)->dptr > (buf)->lptr) )
|
||||
|
||||
//! \brief Check if the buffer has a non-zero size
|
||||
//!
|
||||
#define FDLOG64_EXISTS(buf) ( (buf)->lptr != (buf)->fptr )
|
||||
|
||||
|
||||
/******************** inline functions ********************/
|
||||
|
||||
//! \brief Resets all structure pointers to null value
|
||||
//! \param[in] p The FDLOG64 structure
|
||||
//!
|
||||
static inline void DCL_deleteLog64(FDLOG64 *p) { p->dptr = p->lptr = p->fptr = 0; }
|
||||
|
||||
//! \brief Resets the data index pointer to start of buffer
|
||||
//! \param[in] p The FDLOG64 structure
|
||||
//!
|
||||
static inline void DCL_resetLog64(FDLOG64 *p) { p->dptr = p->fptr; }
|
||||
|
||||
//! \brief Assigns the buffer pointers to a memory block or array and sets
|
||||
//! the data index pointer to the first address
|
||||
//! \param[in] p The FDLOG64 structure
|
||||
//! \param[in] addr The start address of the memory block
|
||||
//! \param[in] size The length of the memory block in 64-bit words
|
||||
//!
|
||||
static inline void DCL_initLog64(FDLOG64 *p, float64_t *addr, uint16_t size)
|
||||
{
|
||||
p->fptr = addr;
|
||||
p->lptr = addr + size - 1;
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
//! \brief Writes a data point into the buffer and advances the indexing
|
||||
//! pointer, wrapping if necessary.
|
||||
//! Returns the over-written data value for delay line or FIFO
|
||||
//! implementation.
|
||||
//! \param[in] p The FDLOG64 structure
|
||||
//! \param[in] data The input data value
|
||||
//! \return The over-written data value
|
||||
//!
|
||||
static inline float64_t DCL_writeLog64(FDLOG64 *p, float64_t data)
|
||||
{
|
||||
float64_t rv = *(p->dptr); // save existing data
|
||||
|
||||
// write new data to log
|
||||
*(p->dptr++) = data;
|
||||
|
||||
// check for end of buffer & wrap if necessary
|
||||
if (p->dptr > p->lptr)
|
||||
{
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//! \brief Fills the buffer with a given data value and resets the data
|
||||
//! index pointer to the start of the buffer
|
||||
//! \param[in] p The FDLOG64 structure
|
||||
//! \param[in] data The fill data value
|
||||
//!
|
||||
static inline void DCL_fillLog64(FDLOG64 *p, float64_t data)
|
||||
{
|
||||
p->dptr = p->lptr;
|
||||
*(p->dptr) = data;
|
||||
while (p->dptr > p->fptr)
|
||||
{
|
||||
*(--p->dptr) = data;
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Clears the buffer contents by writing 0 to all elements and
|
||||
//! resets the data index pointer to the start of the buffer.
|
||||
//! Alias for DCL_fillLog64.
|
||||
//!
|
||||
#define DCL_clearLog64(bufAddr) DCL_fillLog64(bufAddr,0)
|
||||
|
||||
|
||||
//! \brief Reads a data point from the buffer and then advances the
|
||||
//! indexing pointer, wrapping if necessary
|
||||
//! \param[in] p The FDLOG64 structure
|
||||
//! \return The indexed data value
|
||||
//!
|
||||
static inline float64_t DCL_readLog64(FDLOG64 *p)
|
||||
{
|
||||
float64_t rv = *(p->dptr++);
|
||||
|
||||
if (p->dptr > p->lptr)
|
||||
{
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//! \brief Copies the contents of one log (q) into another (p) and resets
|
||||
//! both buffer index pointers. The function assumes both logs
|
||||
//! have the same length.
|
||||
//! \param[in] p The destination FDLOG64 structure
|
||||
//! \param[in] q The source FDLOG64 structure
|
||||
//!
|
||||
static inline void DCL_copyLog64(FDLOG64 *p, FDLOG64 *q)
|
||||
{
|
||||
p->dptr = p->lptr;
|
||||
q->dptr = q->lptr;
|
||||
*(p->dptr) = *(q->dptr);
|
||||
while (p->dptr > p->fptr)
|
||||
{
|
||||
*(--p->dptr) = *(--q->dptr);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_FDLOG64_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,250 @@
|
||||
/* DCL_log32.h - 32-bit fixed-point data buffer utility
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_LOG32_H
|
||||
#define _C_DCL_LOG32_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
//! \file DCL_log32.h
|
||||
//!
|
||||
//! \brief Defines the 32-bit fixed-point data buffer structure
|
||||
//!
|
||||
//! \details The LOG32 structure contains three pointers which define the
|
||||
//! start and end of a memory block, and index into it.
|
||||
//! Manipulation of the indexing pointer permits linear and
|
||||
//! circular buffers, stacks, data logs, etc. to be implemented
|
||||
//! with a common data structure. An example of initialisation
|
||||
//! and use is shown below:
|
||||
//!
|
||||
//! \code
|
||||
//! #pragma DATA_SECTION(r_Array, "DataLogSection")
|
||||
//! int32_t r_Array[FDLOG_DEFAULT_SIZE];
|
||||
//! LOG32 rBuf = LOG32_DEFAULTS;
|
||||
//! int32_t x, y = 0x12345678;
|
||||
//!
|
||||
//! DCL_createLOG32(&rBuf, r_Array, LOG32_DEFAULT_SIZE);
|
||||
//! DCL_clearLOG32(&rBuf);
|
||||
//!
|
||||
//! DCL_writeLOG32(&rBuf, y);
|
||||
//! x = readLOG32(&rBuf);
|
||||
//! \endcode
|
||||
//!
|
||||
typedef volatile struct dcl_log32 {
|
||||
int32_t *fptr; //!< Pointer to first buffer element
|
||||
int32_t *lptr; //!< Pointer to last buffer element
|
||||
int32_t *dptr; //!< Data index pointer
|
||||
} LOG32;
|
||||
|
||||
|
||||
//! \brief Function name compatibility with DCL version 1
|
||||
//!
|
||||
#define DCL_createLog32 DCL_initLog32
|
||||
|
||||
//! \brief Defines a default size for the FDLOG buffer
|
||||
//!
|
||||
#define LOG32_DEFAULT_SIZE 0x0400
|
||||
|
||||
//! \brief Defines default values to initialise the FDLOG structure
|
||||
//!
|
||||
#define LOG32_DEFAULTS { 0x00000000, \
|
||||
0x00000000, \
|
||||
0x00000000 \
|
||||
}
|
||||
|
||||
|
||||
/******************** macro definitions ********************/
|
||||
|
||||
//! \brief Distance from indexed element to end of buffer
|
||||
//!
|
||||
#define LOG32_SPACE(buf) ((buf)->lptr - (buf)->dptr + 1)
|
||||
|
||||
//! \brief Total buffer size in 32-bit words
|
||||
//!
|
||||
#define LOG32_SIZE(buf) ((buf)->lptr - (buf)->fptr + 1)
|
||||
|
||||
//! \brief Current indexed element
|
||||
//!
|
||||
#define LOG32_ELEMENT(buf) ((buf)->dptr - (buf)->fptr + 1)
|
||||
|
||||
//! \brief Index pointer is at start of buffer
|
||||
//!
|
||||
#define LOG32_START(buf) ((buf)->dptr == (buf)->fptr)
|
||||
|
||||
//! \brief Index pointer is at end of buffer
|
||||
//!
|
||||
#define LOG32_END(buf) ((buf)->dptr == (buf)->lptr)
|
||||
|
||||
//! \brief Indexed pointer not in buffer range
|
||||
//!
|
||||
#define LOG32_OUT_OF_RANGE(buf) (((buf)->dptr < (buf)->fptr) || ((buf)->dptr > (buf)->lptr))
|
||||
|
||||
//! \brief Check if the buffer has a non-zero size
|
||||
//!
|
||||
#define LOG32_EXISTS(buf) ((buf)->lptr != (buf)->fptr)
|
||||
|
||||
|
||||
/******************** inline functions ********************/
|
||||
|
||||
//! \brief Resets all structure pointers to null value
|
||||
//! \param[in] p The LOG32 structure
|
||||
//!
|
||||
static inline void DCL_deleteLog32(LOG32 *p) { p->dptr = p->lptr = p->fptr = 0; }
|
||||
|
||||
//! \brief Resets the data index pointer to start of buffer
|
||||
//! \param[in] p The LOG32 structure
|
||||
//!
|
||||
static inline void DCL_resetLog32(LOG32 *p) { p->dptr = p->fptr; }
|
||||
|
||||
//! \brief Assigns the buffer pointers to a memory block or array and sets
|
||||
//! the data index pointer to the first address
|
||||
//! \param[in] p The LOG32 structure
|
||||
//! \param[in] addr The start address of the memory block
|
||||
//! \param[in] size The length of the memory block in 32-bit words
|
||||
//!
|
||||
static inline void DCL_initLog32(LOG32 *p, int32_t *addr, uint16_t size)
|
||||
{
|
||||
p->fptr = addr;
|
||||
p->lptr = addr + size - 1;
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
//! \brief Writes a data point into the buffer and advances the indexing
|
||||
//! pointer, wrapping if necessary.
|
||||
//! Returns the over-written data value for delay line or FIFO
|
||||
//! implementation.
|
||||
//! \param[in] p The LOG32 structure
|
||||
//! \param[in] data The input data value
|
||||
//! \return The over-written data value
|
||||
//!
|
||||
static inline int32_t DCL_writeLog32(LOG32 *p, int32_t data)
|
||||
{
|
||||
int32_t rv = *(p->dptr); // save existing data
|
||||
|
||||
// write new data to log
|
||||
*(p->dptr++) = data;
|
||||
|
||||
// check for end of buffer & wrap if necessary
|
||||
if (p->dptr > p->lptr)
|
||||
{
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
//! \brief Fills the buffer with a given data value and resets the data
|
||||
//! index pointer to the start of the buffer
|
||||
//! \param[in] p The LOG32 structure
|
||||
//! \param[in] data The fill data value
|
||||
//!
|
||||
static inline void DCL_fillLog32(LOG32 *p, int32_t data)
|
||||
{
|
||||
p->dptr = p->lptr;
|
||||
*(p->dptr) = data;
|
||||
while (p->dptr > p->fptr)
|
||||
{
|
||||
*(--p->dptr) = data;
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Clears the buffer contents by writing 0 to all elements and
|
||||
//! resets the data index pointer to the start of the buffer.
|
||||
//!
|
||||
#define DCL_clearLog32(bufAddr) DCL_fillLog32(bufAddr, 0L)
|
||||
|
||||
|
||||
//! \brief Reads a data point from the buffer and then advances the
|
||||
//! indexing pointer, wrapping if necessary
|
||||
//! \param[in] p The LOG32 structure
|
||||
//! \return The indexed data value
|
||||
//!
|
||||
static inline int32_t DCL_readLog32(LOG32 *p)
|
||||
{
|
||||
int32_t rv = *(p->dptr++);
|
||||
|
||||
if (p->dptr > p->lptr)
|
||||
{
|
||||
p->dptr = p->fptr;
|
||||
}
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
//! \brief Copies the contents of one log (q) into another (p) and resets
|
||||
//! both buffer index pointers. The function assumes both logs
|
||||
//! have the same length.
|
||||
//! \param[in] p The destination LOG32 structure
|
||||
//! \param[in] q The source LOG32 structure
|
||||
//!
|
||||
static inline void DCL_copyLog32(LOG32 *p, LOG32 *q)
|
||||
{
|
||||
p->dptr = p->lptr;
|
||||
q->dptr = q->lptr;
|
||||
*(p->dptr) = *(q->dptr);
|
||||
while (p->dptr > p->fptr)
|
||||
{
|
||||
*(--p->dptr) = *(--q->dptr);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_LOG32_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,564 @@
|
||||
/* DCL_refgen.h - Reference generator module header file
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_REFGEN_H
|
||||
#define _C_DCL_REFGEN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "DCL.h"
|
||||
|
||||
//! \brief Region related symbols for function placement
|
||||
//
|
||||
#pragma CODE_SECTION(DCL_runRefgen,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_getRefgenPhaseA,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_getRefgenPhaseB,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_getRefgenPhaseC,"dclfuncs")
|
||||
|
||||
//! \brief Defines the minimum normalized increment
|
||||
//!
|
||||
#define DCL_REFGEN_MIN_INC 1.0e-06f
|
||||
|
||||
//! \brief Defines the REFGEN operating modes
|
||||
//!
|
||||
enum dcl_rgen_modes {
|
||||
REFGEN_OFF = 0,
|
||||
REFGEN_STATIC,
|
||||
REFGEN_SINE,
|
||||
REFGEN_SQUARE,
|
||||
REFGEN_SAW,
|
||||
REFGEN_TRIANGLE,
|
||||
REFGEN_PULSE,
|
||||
REFGEN_SINE2,
|
||||
REFGEN_SINE3
|
||||
};
|
||||
|
||||
//! \brief Defines the DCL_REFGEN structure
|
||||
//!
|
||||
typedef volatile struct dcl_refgen {
|
||||
float32_t rtgt; //!< Target ramp value
|
||||
float32_t rinc; //!< Ramp increment
|
||||
float32_t amtgt; //!< Target amplitude value
|
||||
float32_t aminc; //!< Amplitude increment
|
||||
float32_t fmtgt; //!< Frequency ramp value
|
||||
float32_t fminc; //!< Frequency increment
|
||||
float32_t thinc; //!< Angular increment
|
||||
float32_t duty; //!< Pulse duty cycle
|
||||
float32_t umax; //!< Maximum allowable output
|
||||
float32_t umin; //!< Minimum allowable output
|
||||
float32_t yr; //!< Ramp generator output
|
||||
float32_t ampl; //!< Dynamic amplitude
|
||||
float32_t freq; //!< Dynamic frequency
|
||||
float32_t theta; //!< Normalized angle - phase A
|
||||
float32_t thetb; //!< Normalized angle - phase B
|
||||
float32_t thetc; //!< Normalized angle - phase C
|
||||
float32_t ya; //!< Phase A output
|
||||
float32_t yb; //!< Phase B output
|
||||
float32_t yc; //!< Phase C output
|
||||
int16_t mode; //!< Operating mode
|
||||
int16_t spare; //!< Spare for alignment
|
||||
DCL_CSS *css; //!< Pointer to the common support structure
|
||||
} DCL_REFGEN;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_REFGEN structure
|
||||
//!
|
||||
#define DCL_REFGEN_DEFAULTS { 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 1.0f, 1.0f, 1.0f, -1.0f, \
|
||||
0.0f, 0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f, \
|
||||
REFGEN_OFF, 0, NULL_ADDR }
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//! \brief Resets DCL_REFGEN dynamic data
|
||||
//! \param[in] p Pointer to the DCL_REFGEN structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_resetRefgen(DCL_REFGEN *p)
|
||||
{
|
||||
p->ampl = 0.0f;
|
||||
p->freq = 0.0f;
|
||||
p->rinc = 0.0f;
|
||||
p->theta = 0.0f;
|
||||
p->thetb = 0.0f;
|
||||
p->thetc = 0.0f;
|
||||
p->thinc = 0.0f;
|
||||
p->yr = 0.0f;
|
||||
p->ya = 0.0f;
|
||||
p->yb = 0.0f;
|
||||
p->yc = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Loads the REFGEN ramp parameters
|
||||
//!
|
||||
//! \param[in] p Pointer to the DCL_REFGEN structure
|
||||
//! \param[in] tgt The new static reference target
|
||||
//! \param[in] tr The time interval to reach the new target
|
||||
//! \return Void
|
||||
//!
|
||||
static inline void DCL_setRefgenRamp(DCL_REFGEN *p, float32_t tgt, float32_t tr)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (tr < 0.0f) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute ramp increment
|
||||
tr = (tr < p->css->T) ? p->css->T : tr;
|
||||
p->rtgt = tgt;
|
||||
p->rinc = p->css->T * (tgt - p->yr) / tr;
|
||||
|
||||
// clamp minimum ramp increment
|
||||
if (!(0.0f == p->rinc) && (fabsf(p->rinc) < DCL_REFGEN_MIN_INC))
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
#endif
|
||||
if (signbit(p->rinc))
|
||||
{
|
||||
p->rinc = -DCL_REFGEN_MIN_INC;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->rinc = DCL_REFGEN_MIN_INC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! \brief Loads the REFGEN dynamic amplitude
|
||||
//!
|
||||
//! \param[in] p Pointer to the DCL_REFGEN structure
|
||||
//! \param[in] ampl The new target amplitude
|
||||
//! \param[in] tr The time interval to reach the new target
|
||||
//! \return Void
|
||||
//!
|
||||
static inline void DCL_setRefgenAmpl(DCL_REFGEN *p, float32_t ampl, float32_t tr)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (tr < 0.0f) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute amplitude increment
|
||||
tr = (tr < p->css->T) ? p->css->T : tr;
|
||||
p->amtgt = ampl;
|
||||
p->aminc = p->css->T * (ampl - p->ampl) / tr;
|
||||
|
||||
// clamp minimum amplitude increment
|
||||
if ((p->aminc > 0.0f) && (fabsf(p->aminc) < DCL_REFGEN_MIN_INC))
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
#endif
|
||||
if (signbit(p->aminc))
|
||||
{
|
||||
p->aminc = -DCL_REFGEN_MIN_INC;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->aminc = DCL_REFGEN_MIN_INC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! \brief Loads the REFGEN frequency
|
||||
//!
|
||||
//! \param[in] p Pointer to the DCL_REFGEN structure
|
||||
//! \param[in] freq The new frequency in Hz
|
||||
//! \param[in] tr The time interval to reach the new target
|
||||
//! \return Void
|
||||
//!
|
||||
static inline void DCL_setRefgenFreq(DCL_REFGEN *p, float32_t freq, float32_t tr)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (tr < 0.0f) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute frequency increment
|
||||
tr = (tr < p->css->T) ? p->css->T : tr;
|
||||
p->fmtgt = freq;
|
||||
p->fminc = p->css->T * (freq - p->freq) / tr;
|
||||
|
||||
// clamp minimum frequency increment
|
||||
if ((p->fminc > 0.0f) && (fabsf(p->fminc) < DCL_REFGEN_MIN_INC))
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
#endif
|
||||
if (signbit(p->fminc))
|
||||
{
|
||||
p->fminc = -DCL_REFGEN_MIN_INC;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->fminc = DCL_REFGEN_MIN_INC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! \brief Loads the REFGEN pulse duty cycle
|
||||
//! \param[in] p Pointer to the DCL_REFGEN structure
|
||||
//! \param[in] duty The new per-unit duty cycle
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setRefgenDuty(DCL_REFGEN *p, float32_t duty)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((duty < 0.0f) || (duty > 1.0f)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
p->duty = duty;
|
||||
}
|
||||
|
||||
//! \brief Loads the REFGEN output clam limits
|
||||
//! \param[in] p Pointer to the DCL_REFGEN structure
|
||||
//! \param[in] max The upper limit
|
||||
//! \param[in] min The lower limit
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setRefgenClamp(DCL_REFGEN *p, float32_t max, float32_t min)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (max < min) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
p->umax = max;
|
||||
p->umin = min;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Sets the REFGEN operating mode
|
||||
//! \param[in] p Pointer to the DCL_REFGEN structure
|
||||
//! \param[in] mode The new operating mode
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setRefgenMode(DCL_REFGEN *p, int16_t mode)
|
||||
{
|
||||
p->mode = mode;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Runs the REFGEN module
|
||||
//! \param[in] p Pointer to the DCL_REFGEN structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_runRefgen(DCL_REFGEN *p)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
float32_t v;
|
||||
#endif
|
||||
|
||||
// static offset generator
|
||||
if (!F32_IS_ZERO(p->rinc))
|
||||
{
|
||||
if (fabsf(p->rinc) > fabsf(p->rtgt - p->yr))
|
||||
{
|
||||
p->yr = p->rtgt;
|
||||
p->rinc = 0.0f;
|
||||
DCL_ADJUSTMENT_COMPLETE(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
v = p->yr;
|
||||
#endif
|
||||
p->yr += p->rinc;
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
if (F32_IS_ZERO(v - p->yr))
|
||||
{
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
DCL_ADJUSTMENT_RUNNING(p);
|
||||
}
|
||||
}
|
||||
|
||||
// amplitude modulator
|
||||
if (!F32_IS_ZERO(p->aminc))
|
||||
{
|
||||
if (fabsf(p->aminc) > fabsf(p->amtgt - p->ampl))
|
||||
{
|
||||
p->ampl = p->amtgt;
|
||||
p->aminc = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
v = p->ampl;
|
||||
#endif
|
||||
p->ampl += p->aminc;
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
if (F32_IS_ZERO(v - p->ampl))
|
||||
{
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// frequency modulator
|
||||
if (!F32_IS_ZERO(p->fminc))
|
||||
{
|
||||
if (fabsf(p->fminc) > fabsf(p->fmtgt - p->freq))
|
||||
{
|
||||
p->freq = p->fmtgt;
|
||||
p->fminc = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
v = p->freq;
|
||||
#endif
|
||||
p->freq += p->fminc;
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
if (F32_IS_ZERO(v - p->freq))
|
||||
{
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// angle increment
|
||||
if (p->freq > 0.0f)
|
||||
{
|
||||
p->thinc = p->css->T * p->freq;
|
||||
if (p->thinc < DCL_REFGEN_MIN_INC)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
#endif
|
||||
p->thinc = DCL_REFGEN_MIN_INC;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p->thinc = 0.0f;
|
||||
}
|
||||
|
||||
p->theta += p->thinc;
|
||||
p->theta -= (p->theta >= 1.0f) ? 1.0f : 0.0f;
|
||||
|
||||
// dynamic signal generator
|
||||
switch (p->mode) {
|
||||
|
||||
case REFGEN_STATIC:
|
||||
p->ya = 0.0f;
|
||||
p->yb = 0.0f;
|
||||
p->yc = 0.0f;
|
||||
break;
|
||||
|
||||
case REFGEN_SINE:
|
||||
#ifdef __TMS320C28XX_TMU__
|
||||
p->ya = __sinpuf32(p->theta);
|
||||
#else
|
||||
p->ya = sinf(CONST_2PI_32 * p->theta);
|
||||
#endif
|
||||
p->yb = 0.0f;
|
||||
p->yc = 0.0f;
|
||||
break;
|
||||
|
||||
case REFGEN_SQUARE:
|
||||
p->ya = (p->theta > 0.5f) ? 1.0f : 0.0f;
|
||||
p->yb = 0.0f;
|
||||
p->yc = 0.0f;
|
||||
break;
|
||||
|
||||
case REFGEN_SAW:
|
||||
p->ya = p->theta;
|
||||
p->yb = 0.0f;
|
||||
p->yc = 0.0f;
|
||||
break;
|
||||
|
||||
case REFGEN_TRIANGLE:
|
||||
if (p->theta < 0.5f)
|
||||
{
|
||||
p->ya = 2.0f * p->theta;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->ya = 1.0f - 2.0f * (p->theta - 0.5f);
|
||||
}
|
||||
p->yb = 0.0f;
|
||||
p->yc = 0.0f;
|
||||
break;
|
||||
|
||||
case REFGEN_PULSE:
|
||||
p->ya = (p->theta > p->duty) ? 0.0f : 1.0f;
|
||||
p->yb = 0.0f;
|
||||
p->yc = 0.0f;
|
||||
break;
|
||||
|
||||
case REFGEN_SINE2:
|
||||
#ifdef __TMS320C28XX_TMU__
|
||||
p->ya = __sinpuf32(p->theta);
|
||||
p->yb = __cospuf32(p->theta);
|
||||
#else
|
||||
p->ya = sinf(CONST_2PI_32 * p->theta);
|
||||
p->yb = cosf(CONST_2PI_32 * p->theta);
|
||||
#endif
|
||||
p->yc = 0.0f;
|
||||
break;
|
||||
|
||||
case REFGEN_SINE3:
|
||||
p->thetb = p->theta + 0.3333333333333f;
|
||||
p->thetc = p->theta + 0.6666666666667f;
|
||||
p->thetb -= (p->thetb >= 1.0f) ? 1.0f : 0.0f;
|
||||
p->thetc -= (p->thetc >= 1.0f) ? 1.0f : 0.0f;
|
||||
|
||||
#ifdef __TMS320C28XX_TMU__
|
||||
p->ya = __sinpuf32(p->theta);
|
||||
p->yb = __sinpuf32(p->thetb);
|
||||
p->yc = __sinpuf32(p->thetc);
|
||||
#else
|
||||
p->ya = sinf(CONST_2PI_32 * p->theta);
|
||||
p->yb = sinf(CONST_2PI_32 * p->thetb);
|
||||
p->yc = sinf(CONST_2PI_32 * p->thetc);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case REFGEN_OFF:
|
||||
default:
|
||||
p->yr = 0.0f;
|
||||
p->ya = 0.0f;
|
||||
p->yb = 0.0f;
|
||||
p->yc = 0.0f;
|
||||
}
|
||||
|
||||
// output sum & saturation
|
||||
p->ya = __fsat(p->ampl * p->ya + p->yr, p->umax, p->umin);
|
||||
p->yb = __fsat(p->ampl * p->yb + p->yr, p->umax, p->umin);
|
||||
p->yc = __fsat(p->ampl * p->yc + p->yr, p->umax, p->umin);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Returns the phase reference output
|
||||
//! \param[in] p Pointer to the active DCL_REFGEN structure
|
||||
//! \return The phase A reference output
|
||||
//!
|
||||
static inline float32_t DCL_getRefgenPhaseA(DCL_REFGEN *p)
|
||||
{
|
||||
return(p->ya);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Returns the phase reference output
|
||||
//! \param[in] p Pointer to the active DCL_REFGEN structure
|
||||
//! \return The phase B reference output
|
||||
//!
|
||||
static inline float32_t DCL_getRefgenPhaseB(DCL_REFGEN *p)
|
||||
{
|
||||
return(p->yb);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Returns the phase reference output
|
||||
//! \param[in] p Pointer to the active DCL_REFGEN structure
|
||||
//! \return The phase C reference output
|
||||
//!
|
||||
static inline float32_t DCL_getRefgenPhaseC(DCL_REFGEN *p)
|
||||
{
|
||||
return(p->yc);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_REFGEN_H
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,565 @@
|
||||
/* DCL_refgen64.h - Reference generator module header file (double precision)
|
||||
*
|
||||
*/
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef _C_DCL_REFGEN64_H
|
||||
#define _C_DCL_REFGEN64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "DCL.h"
|
||||
|
||||
//! \brief Region related symbols for function placement
|
||||
//
|
||||
#pragma CODE_SECTION(DCL_runRefgen64,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_getRefgen64PhaseA,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_getRefgen64PhaseB,"dclfuncs")
|
||||
#pragma CODE_SECTION(DCL_getRefgen64PhaseC,"dclfuncs")
|
||||
|
||||
//! \brief Defines the minimum normalized increment
|
||||
//!
|
||||
#define DCL_REFGEN64_MIN_INC 1.0e-10
|
||||
|
||||
//! \brief Defines the REFGEN operating modes
|
||||
//!
|
||||
enum dcl_rgen64_modes {
|
||||
REFGEN64_OFF = 0,
|
||||
REFGEN64_STATIC,
|
||||
REFGEN64_SINE,
|
||||
REFGEN64_SQUARE,
|
||||
REFGEN64_SAW,
|
||||
REFGEN64_TRIANGLE,
|
||||
REFGEN64_PULSE,
|
||||
REFGEN64_SINE2,
|
||||
REFGEN64_SINE3
|
||||
};
|
||||
|
||||
//! \brief Defines the DCL_REFGEN64 structure
|
||||
//!
|
||||
typedef volatile struct dcl_refgen64 {
|
||||
float64_t rtgt; //!< Target ramp value
|
||||
float64_t rinc; //!< Ramp increment
|
||||
float64_t amtgt; //!< Target amplitude value
|
||||
float64_t aminc; //!< Amplitude increment
|
||||
float64_t fmtgt; //!< Frequency ramp value
|
||||
float64_t fminc; //!< Frequency increment
|
||||
float64_t thinc; //!< Angular increment
|
||||
float64_t duty; //!< Pulse duty cycle
|
||||
float64_t umax; //!< Maximum allowable output
|
||||
float64_t umin; //!< Minimum allowable output
|
||||
float64_t yr; //!< Ramp generator output
|
||||
float64_t ampl; //!< Dynamic amplitude
|
||||
float64_t freq; //!< Dynamic frequency
|
||||
float64_t theta; //!< Normalized angle - phase A
|
||||
float64_t thetb; //!< Normalized angle - phase B
|
||||
float64_t thetc; //!< Normalized angle - phase C
|
||||
float64_t ya; //!< Phase A output
|
||||
float64_t yb; //!< Phase B output
|
||||
float64_t yc; //!< Phase C output
|
||||
int16_t mode; //!< Operating mode
|
||||
int16_t spare; //!< Spare for alignment
|
||||
DCL_CSS *css; //!< Pointer to the common support structure
|
||||
} DCL_REFGEN64;
|
||||
|
||||
//! \brief Defines default values to initialize the DCL_REFGEN64 structure
|
||||
//!
|
||||
#define DCL_REFGEN64_DEFAULTS { 0.0, 0.0, \
|
||||
0.0, 0.0, \
|
||||
0.0, 0.0, 0.0, \
|
||||
0.0, 1.0, 1.0, 1.0, -1.0, \
|
||||
0.0, 0.0, 0.0, 0.0, \
|
||||
0.0, 0.0, 0.0, \
|
||||
REFGEN64_OFF, 0, NULL_ADDR }
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//! \brief Resets DCL_REFGEN64 dynamic data
|
||||
//! \param[in] p Pointer to the DCL_REFGEN64 structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_resetRefgen64(DCL_REFGEN64 *p)
|
||||
{
|
||||
p->ampl = 0.0;
|
||||
p->freq = 0.0;
|
||||
p->rinc = 0.0;
|
||||
p->theta = 0.0;
|
||||
p->thetb = 0.0;
|
||||
p->thetc = 0.0;
|
||||
p->thinc = 0.0;
|
||||
p->yr = 0.0;
|
||||
p->ya = 0.0;
|
||||
p->yb = 0.0;
|
||||
p->yc = 0.0;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Loads the REFGEN64 ramp parameters
|
||||
//!
|
||||
//! \param[in] p Pointer to the DCL_REFGEN64 structure
|
||||
//! \param[in] tgt The new static reference target
|
||||
//! \param[in] tr The time interval to reach the new target
|
||||
//! \return Void
|
||||
//!
|
||||
static inline void DCL_setRefgen64Ramp(DCL_REFGEN64 *p, float64_t tgt, float64_t tr)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (tr < 0.0) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute ramp increment
|
||||
tr = (tr < p->css->T) ? p->css->T : tr;
|
||||
p->rtgt = tgt;
|
||||
p->rinc = p->css->T * (tgt - p->yr) / tr;
|
||||
|
||||
// clamp minimum ramp increment
|
||||
if (!(0.0 == p->rinc) && (fabs(p->rinc) < DCL_REFGEN64_MIN_INC))
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
#endif
|
||||
if (signbit(p->rinc))
|
||||
{
|
||||
p->rinc = -DCL_REFGEN64_MIN_INC;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->rinc = DCL_REFGEN64_MIN_INC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! \brief Loads the REFGEN dynamic amplitude
|
||||
//!
|
||||
//! \param[in] p Pointer to the DCL_REFGEN64 structure
|
||||
//! \param[in] ampl The new target amplitude
|
||||
//! \param[in] tr The time interval to reach the new target
|
||||
//! \return Void
|
||||
//!
|
||||
static inline void DCL_setRefgen64Ampl(DCL_REFGEN64 *p, float64_t ampl, float64_t tr)
|
||||
{
|
||||
float64_t v;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (tr < 0.0) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute amplitude increment
|
||||
v = (float64_t) p->css->T;
|
||||
tr = (tr < v) ? v : tr;
|
||||
p->amtgt = ampl;
|
||||
p->aminc = v * (ampl - p->ampl) / tr;
|
||||
|
||||
// clamp minimum amplitude increment
|
||||
if ((p->aminc > 0.0) && (fabs(p->aminc) < DCL_REFGEN64_MIN_INC))
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
#endif
|
||||
if (signbit(p->aminc))
|
||||
{
|
||||
p->aminc = -DCL_REFGEN64_MIN_INC;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->aminc = DCL_REFGEN64_MIN_INC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! \brief Loads the REFGEN64 frequency
|
||||
//!
|
||||
//! \param[in] p Pointer to the DCL_REFGEN64 structure
|
||||
//! \param[in] freq The new frequency in Hz
|
||||
//! \param[in] tr The time interval to reach the new target
|
||||
//! \return Void
|
||||
//!
|
||||
static inline void DCL_setRefgen64Freq(DCL_REFGEN64 *p, float64_t freq, float64_t tr)
|
||||
{
|
||||
float64_t v;
|
||||
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (tr < 0.0) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute frequency increment
|
||||
v = (float64_t) p->css->T;
|
||||
tr = (tr < v) ? v : tr;
|
||||
p->fmtgt = freq;
|
||||
p->fminc = v * (freq - p->freq) / tr;
|
||||
|
||||
// clamp minimum frequency increment
|
||||
if ((p->fminc > 0.0) && (fabs(p->fminc) < DCL_REFGEN64_MIN_INC))
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
#endif
|
||||
if (signbit(p->fminc))
|
||||
{
|
||||
p->fminc = -DCL_REFGEN64_MIN_INC;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->fminc = DCL_REFGEN64_MIN_INC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! \brief Loads the REFGEN64 pulse duty cycle
|
||||
//! \param[in] p Pointer to the DCL_REFGEN64 structure
|
||||
//! \param[in] duty The new per-unit duty cycle
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setRefgen64Duty(DCL_REFGEN64 *p, float64_t duty)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= ((duty < 0.0) || (duty > 1.0)) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
p->duty = duty;
|
||||
}
|
||||
|
||||
//! \brief Loads the REFGEN64 output clam limits
|
||||
//! \param[in] p Pointer to the DCL_REFGEN64 structure
|
||||
//! \param[in] max The upper limit
|
||||
//! \param[in] min The lower limit
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setRefgen64Clamp(DCL_REFGEN64 *p, float64_t max, float64_t min)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err |= (max < min) ? ERR_PARAM_RANGE : ERR_NONE;
|
||||
if (p->css->err)
|
||||
{
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
|
||||
p->umax = max;
|
||||
p->umin = min;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Sets the REFGEN64 operating mode
|
||||
//! \param[in] p Pointer to the DCL_REFGEN64 structure
|
||||
//! \param[in] mode The new operating mode
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_setRefgen64Mode(DCL_REFGEN64 *p, int16_t mode)
|
||||
{
|
||||
p->mode = mode;
|
||||
}
|
||||
|
||||
|
||||
//! \brief Runs the REFGEN64 module
|
||||
//! \param[in] p Pointer to the DCL_REFGEN64 structure
|
||||
//! \return None
|
||||
//!
|
||||
static inline void DCL_runRefgen64(DCL_REFGEN64 *p)
|
||||
{
|
||||
float64_t v;
|
||||
|
||||
// static offset generator
|
||||
if (!F64_IS_ZERO(p->rinc))
|
||||
{
|
||||
if (fabs(p->rinc) > fabs(p->rtgt - p->yr))
|
||||
{
|
||||
p->yr = p->rtgt;
|
||||
p->rinc = 0.0;
|
||||
DCL_ADJUSTMENT_COMPLETE(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
v = p->yr;
|
||||
#endif
|
||||
p->yr += p->rinc;
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
if (F64_IS_ZERO(v - p->yr))
|
||||
{
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
DCL_ADJUSTMENT_RUNNING(p);
|
||||
}
|
||||
}
|
||||
|
||||
// amplitude modulator
|
||||
if (!F64_IS_ZERO(p->aminc))
|
||||
{
|
||||
if (fabs(p->aminc) > fabs(p->amtgt - p->ampl))
|
||||
{
|
||||
p->ampl = p->amtgt;
|
||||
p->aminc = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
v = p->ampl;
|
||||
#endif
|
||||
p->ampl += p->aminc;
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
if (F64_IS_ZERO(v - p->ampl))
|
||||
{
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// frequency modulator
|
||||
if (!F64_IS_ZERO(p->fminc))
|
||||
{
|
||||
if (fabs(p->fminc) > fabs(p->fmtgt - p->freq))
|
||||
{
|
||||
p->freq = p->fmtgt;
|
||||
p->fminc = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
v = p->freq;
|
||||
#endif
|
||||
p->freq += p->fminc;
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
if (F64_IS_ZERO(v - p->freq))
|
||||
{
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// angle increment
|
||||
if (p->freq > 0.0)
|
||||
{
|
||||
p->thinc = p->css->T * p->freq;
|
||||
if (p->thinc < DCL_REFGEN64_MIN_INC)
|
||||
{
|
||||
#ifdef DCL_ERROR_HANDLING_ENABLED
|
||||
p->css->err = ERR_COMPUTATION;
|
||||
DCL_GET_ERROR_LOC(p->css);
|
||||
DCL_RUN_ERROR_HANDLER(p->css);
|
||||
#endif
|
||||
p->thinc = DCL_REFGEN64_MIN_INC;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p->thinc = 0.0;
|
||||
}
|
||||
|
||||
p->theta += p->thinc;
|
||||
p->theta -= (p->theta >= 1.0) ? 1.0 : 0.0;
|
||||
|
||||
// dynamic signal generator
|
||||
switch (p->mode) {
|
||||
|
||||
case REFGEN64_STATIC:
|
||||
p->ya = 0.0;
|
||||
p->yb = 0.0;
|
||||
p->yc = 0.0;
|
||||
break;
|
||||
|
||||
case REFGEN64_SINE:
|
||||
p->ya = sin(CONST_2PI_64 * p->theta);
|
||||
p->yb = 0.0;
|
||||
p->yc = 0.0;
|
||||
break;
|
||||
|
||||
case REFGEN64_SQUARE:
|
||||
p->ya = (p->theta > 0.5) ? 1.0 : 0.0;
|
||||
p->yb = 0.0;
|
||||
p->yc = 0.0;
|
||||
break;
|
||||
|
||||
case REFGEN64_SAW:
|
||||
p->ya = p->theta;
|
||||
p->yb = 0.0;
|
||||
p->yc = 0.0;
|
||||
break;
|
||||
|
||||
case REFGEN64_TRIANGLE:
|
||||
if (p->theta < 0.5)
|
||||
{
|
||||
p->ya = 2.0 * p->theta;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->ya = 1.0 - 2.0 * (p->theta - 0.5);
|
||||
}
|
||||
p->yb = 0.0;
|
||||
p->yc = 0.0;
|
||||
break;
|
||||
|
||||
case REFGEN64_PULSE:
|
||||
p->ya = (p->theta > p->duty) ? 0.0 : 1.0;
|
||||
p->yb = 0.0;
|
||||
p->yc = 0.0;
|
||||
break;
|
||||
|
||||
case REFGEN64_SINE2:
|
||||
p->ya = sin(CONST_2PI_64 * p->theta);
|
||||
p->yb = cos(CONST_2PI_64 * p->theta);
|
||||
p->yc = 0.0;
|
||||
break;
|
||||
|
||||
case REFGEN64_SINE3:
|
||||
p->thetb = p->theta + 0.3333333333333;
|
||||
p->thetc = p->theta + 0.6666666666667;
|
||||
p->thetb -= (p->thetb >= 1.0) ? 1.0 : 0.0;
|
||||
p->thetc -= (p->thetc >= 1.0) ? 1.0 : 0.0;
|
||||
|
||||
p->ya = sin(CONST_2PI_64 * p->theta);
|
||||
p->yb = sin(CONST_2PI_64 * p->thetb);
|
||||
p->yc = sin(CONST_2PI_64 * p->thetc);
|
||||
break;
|
||||
|
||||
case REFGEN64_OFF:
|
||||
default:
|
||||
p->yr = 0.0;
|
||||
p->ya = 0.0;
|
||||
p->yb = 0.0;
|
||||
p->yc = 0.0;
|
||||
}
|
||||
|
||||
// output sum & saturation
|
||||
#if (__TI_COMPILER_VERSION__ > 19005000)
|
||||
v = __fmin64(p->ampl * p->ya + p->yr, p->umax);
|
||||
p->ya = __fmax64(v, p->umin);
|
||||
v = __fmin64(p->ampl * p->yb + p->yr, p->umax);
|
||||
p->yb = __fmax64(v, p->umin);
|
||||
v = __fmin64(p->ampl * p->yc + p->yr, p->umax);
|
||||
p->yc = __fmax64(v, p->umin);
|
||||
#else
|
||||
v = fmin(p->ampl * p->ya + p->yr, p->umax);
|
||||
p->ya = fmax(v, p->umin);
|
||||
v = fmin(p->ampl * p->yb + p->yr, p->umax);
|
||||
p->yb = fmax(v, p->umin);
|
||||
v = fmin(p->ampl * p->yc + p->yr, p->umax);
|
||||
p->yc = fmax(v, p->umin);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//! \brief Returns the phase reference output
|
||||
//! \param[in] p Pointer to the active DCL_REFGEN64 structure
|
||||
//! \return The phase A reference output
|
||||
//!
|
||||
static inline float64_t DCL_getRefgen64PhaseA(DCL_REFGEN64 *p)
|
||||
{
|
||||
return(p->ya);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Returns the phase reference output
|
||||
//! \param[in] p Pointer to the active DCL_REFGEN64 structure
|
||||
//! \return The phase B reference output
|
||||
//!
|
||||
static inline float64_t DCL_getRefgen64PhaseB(DCL_REFGEN64 *p)
|
||||
{
|
||||
return(p->yb);
|
||||
}
|
||||
|
||||
|
||||
//! \brief Returns the phase reference output
|
||||
//! \param[in] p Pointer to the active DCL_REFGEN64 structure
|
||||
//! \return The phase C reference output
|
||||
//!
|
||||
static inline float64_t DCL_getRefgen64PhaseC(DCL_REFGEN64 *p)
|
||||
{
|
||||
return(p->yc);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // extern "C"
|
||||
|
||||
#endif // _C_DCL_REFGEN64_H
|
||||
|
||||
/* end of file */
|
||||
Reference in new issue
Block a user