DCL Direct Form 1 2nd Order Functions

Module: Digital Control Library (DCL)

More…

Structures

Name

struct

DCL_DF12_SPS
Defines the DCL_DF12 shadow parameter set used for updating compensator parameter.

Types

Name

typedef _DCL_VOLATILE struct

DCL_DF12
DCL_DF12 object for storing df12 specific parameters.

Functions

Name

_DCL_CODE_ACCESS void

DCL_resetDF12(DCL_DF12 * df)
Resets DF12 internal storage data with interrupt protection Implemented as inline C function.

_DCL_CODE_ACCESS void

DCL_forceUpdateDF12(DCL_DF12 * df)
Loads DF12 tuning parameter from its SPS parameter without interrupt protection.

_DCL_CODE_ACCESS void

DCL_updateDF12NoCheck(DCL_DF12 * df)
Loads DF12 tuning parameter from its SPS parameter with interrupt protection.

_DCL_CODE_ACCESS bool

DCL_updateDF12(DCL_DF12 * df)
A conditional update based on the update flag. If the update status is set, the function will update DF12 parameter from its SPS parameter and clear the status flag on completion…

_DCL_CODE_ACCESS bool

DCL_isStableDF12(DCL_DF12 * df)
Determines stability of the shadow compensator.

_DCL_CODE_ACCESS void

DCL_loadDF12asZPK(DCL_DF12 * df, DCL_ZPK3 * zpk)
Loads the DF12 shadow coefficients from a ZPK3 description.

_DCL_CRIT_ACCESSfloat32_t

DCL_runDF12(DCL_DF12 * df, float32_t ek)
Executes a 3rd order Direct Form 1 controller.

_DCL_CRIT_ACCESSfloat32_t

DCL_runDF12PartialCompute(DCL_DF12 * df, float32_t ek)
Immediate computation to obtain DF12 servo error without updating the controller.

_DCL_CRIT_ACCESS void

DCL_runDF12PartialUpdate(DCL_DF12 * df, float32_t ek, float32_t uk)
Update DF12 controller based on pre-computed control effort.

_DCL_CRIT_ACCESSfloat32_t

DCL_runDF12Clamp(DCL_DF12 * df, float32_t ek, float32_t Umax, float32_t Umin)
Executes a 3rd order Direct Form 1 controller with clamp.

Defines

Name

DF12_SPS_DEFAULTS
Defaults for DCL_DF12_SPS.

DF12_DEFAULTS
Defines default values to initialize DCL_DF12.

DF12_INT_DEFAULTS
Macro for internal default values to initialize DCL_DF12 Example: DCL_DF12 df12_ctrl = { .b0 = 0.25f, .b1 = 0.25f, … .a2 = 0.0f, DF12_INT_DEFAULTS };.

DCL_initDF12()
Initialize DCL_DF12 struct with default parameters Example: DCL_DF12* df12_ctrl = DCL_initDF12();.

DCL_initDF12asParam(_b0, _b1, _b2, _a1, _a2)
Initialize DCL_DF12 struct with input compensator parameters Example: DCL_DF12* DF12_ctrl = DCL_initDF12asParam(0.25f,0.25f,0.25f,0.0f,0.0f);.

DCL_initDF12asSPS(df_ptr, sps_ptr)
Initialize DCL_DF12 struct with sps parameters Example: DCL_DF12_SPS df_sps = { .b0 = , .b1 = , …}; //initial parameter DCL_DF12 df_ctrl; DCL_initDF12asSPS(&df_ctrl,&df_sps);.

Detailed Description

Contains direct form 1 2nd order DF12 compensator with its related structures and functions

Types Documentation

typedef DCL_DF12

typedef _DCL_VOLATILE struct  DCL_DF12;

DCL_DF12 object for storing df12 specific parameters.

Functions Documentation

function DCL_resetDF12

_DCL_CODE_ACCESS void DCL_resetDF12(
    DCL_DF12 * df
)

Resets DF12 internal storage data with interrupt protection Implemented as inline C function.

Parameters:

  • df Pointer to the DCL_DF12 controller structure

function DCL_forceUpdateDF12

_DCL_CODE_ACCESS void DCL_forceUpdateDF12(
    DCL_DF12 * df
)

Loads DF12 tuning parameter from its SPS parameter without interrupt protection.

Parameters:

  • df Pointer to the active DCL_DF12 controller structure

function DCL_updateDF12NoCheck

_DCL_CODE_ACCESS void DCL_updateDF12NoCheck(
    DCL_DF12 * df
)

Loads DF12 tuning parameter from its SPS parameter with interrupt protection.

Parameters:

  • df Pointer to the DCL_DF12 controller structure

function DCL_updateDF12

_DCL_CODE_ACCESS bool DCL_updateDF12(
    DCL_DF12 * df
)

A conditional update based on the update flag. If the update status is set, the function will update DF12 parameter from its SPS parameter and clear the status flag on completion…

Parameters:

  • df Pointer to the DCL_DF12 controller structure

Return: ‘true’ if an update is applied, otherwise ‘false’

Note: Note: Use DCL_setUpdateStatus(df) to set the update status.

function DCL_isStableDF12

_DCL_CODE_ACCESS bool DCL_isStableDF12(
    DCL_DF12 * df
)

Determines stability of the shadow compensator.

Parameters:

  • df Pointer to the DCL_DF12 controller structure

Return: ‘true’ if all poles have magnitude less than 1, ‘false’ otherwise

function DCL_loadDF12asZPK

_DCL_CODE_ACCESS void DCL_loadDF12asZPK(
    DCL_DF12 * df,
    DCL_ZPK3 * zpk
)

Loads the DF12 shadow coefficients from a ZPK3 description.

Parameters:

  • df Pointer to the DCL_DF12 controller structure

  • zpk Pointer to the DCL_ZPK3 structure

Note: Note: Sampling period df->css->T are used in the calculation. New settings take effect after DCL_updateDF12(). Only z1, z2, p1 & p2 are considered, z3 & p3 are ignored.

function DCL_runDF12

_DCL_CRIT_ACCESSfloat32_t DCL_runDF12(
    DCL_DF12 * df,
    float32_t ek
)

Executes a 3rd order Direct Form 1 controller.

Parameters:

  • df Pointer to the DCL_DF12 controller structure

  • ek The servo error

Return: The control effort

function DCL_runDF12PartialCompute

_DCL_CRIT_ACCESSfloat32_t DCL_runDF12PartialCompute(
    DCL_DF12 * df,
    float32_t ek
)

Immediate computation to obtain DF12 servo error without updating the controller.

Parameters:

  • df Pointer to the DCL_DF12 controller structure

  • ek The servo error

Return: The control effort

function DCL_runDF12PartialUpdate

_DCL_CRIT_ACCESS void DCL_runDF12PartialUpdate(
    DCL_DF12 * df,
    float32_t ek,
    float32_t uk
)

Update DF12 controller based on pre-computed control effort.

Parameters:

  • df Pointer to the DCL_DF12 controller structure

  • ek The servo error

  • uk The controller output in the previous sample interval

function DCL_runDF12Clamp

_DCL_CRIT_ACCESSfloat32_t DCL_runDF12Clamp(
    DCL_DF12 * df,
    float32_t ek,
    float32_t Umax,
    float32_t Umin
)

Executes a 3rd order Direct Form 1 controller with clamp.

Parameters:

  • df Pointer to the DCL_DF12 controller structure

  • ek The servo error

  • Umax Upper saturation limit

  • Umin Lower saturation limit

Return: uk The control effort

Macros Documentation

define DF12_SPS_DEFAULTS

#define DF12_SPS_DEFAULTS {0.25f, 0.25f, 0.25f, 0.0f, 0.0f}

Defaults for DCL_DF12_SPS.

define DF12_DEFAULTS

#define DF12_DEFAULTS     {0.25f,                            \
     0.25f,                            \
     0.25f,                            \
     0.0f,                             \
     0.0f,                             \
     0.0f,                             \
     0.0f,                             \
     0.0f,                             \
     0.0f,                             \
     &(DCL_DF12_SPS)DF12_SPS_DEFAULTS, \
     &(DCL_CSS)DCL_CSS_DEFAULTS}

Defines default values to initialize DCL_DF12.

define DF12_INT_DEFAULTS

#define DF12_INT_DEFAULTS     .d1 = 0.0f, .d2 = 0.0f, .d3 = 0.0f, .d4 = 0.0f, .sps = &(DCL_DF12_SPS)DF12_SPS_DEFAULTS, \
    .css = &(DCL_CSS)DCL_CSS_DEFAULTS

Macro for internal default values to initialize DCL_DF12 Example: DCL_DF12 df12_ctrl = { .b0 = 0.25f, .b1 = 0.25f, … .a2 = 0.0f, DF12_INT_DEFAULTS };.

define DCL_initDF12

#define DCL_initDF12(
    
)
&(DCL_DF12)DF12_DEFAULTS

Initialize DCL_DF12 struct with default parameters Example: DCL_DF12* df12_ctrl = DCL_initDF12();.

Return: A DCL_DF12* pointer

define DCL_initDF12asParam

#define DCL_initDF12asParam(
    _b0,
    _b1,
    _b2,
    _a1,
    _a2
)
    &(DCL_DF12)                                                                  \
    {                                                                            \
        .b0 = _b0, .b1 = _b1, .b2 = _b2, .a1 = _a1, .a2 = _a2, DF12_INT_DEFAULTS \
    }

Initialize DCL_DF12 struct with input compensator parameters Example: DCL_DF12* DF12_ctrl = DCL_initDF12asParam(0.25f,0.25f,0.25f,0.0f,0.0f);.

Return: A DCL_DF12* pointer

Note: Note: input parameter needs to be in the same order as listed in DF12_SPS struct

define DCL_initDF12asSPS

#define DCL_initDF12asSPS(
    df_ptr,
    sps_ptr
)
    ({                                                                                  \
        DCL_DF12     *new_df  = (df_ptr) ? df_ptr : DCL_initDF12();                     \
        DCL_DF12_SPS *new_sps = (sps_ptr) ? sps_ptr : &(DCL_DF12_SPS)DF12_SPS_DEFAULTS; \
        if (sps_ptr)                                                                    \
        {                                                                               \
            *new_df = (DCL_DF12){(new_sps)->b0,                                         \
                                 (new_sps)->b1,                                         \
                                 (new_sps)->b2,                                         \
                                 (new_sps)->a1,                                         \
                                 (new_sps)->a2,                                         \
                                 0.0f,                                                  \
                                 0.0f,                                                  \
                                 0.0f,                                                  \
                                 0.0f,                                                  \
                                 (DCL_DF12_SPS *)new_sps,                               \
                                 &(DCL_CSS)DCL_CSS_DEFAULTS};                           \
        }                                                                               \
        new_df;                                                                         \
    })

Initialize DCL_DF12 struct with sps parameters Example: DCL_DF12_SPS df_sps = { .b0 = , .b1 = , …}; //initial parameter DCL_DF12 df_ctrl; DCL_initDF12asSPS(&df_ctrl,&df_sps);.

Parameters:

  • df_ptr DCL_DF12* pointer that needs to be initialized

  • sps_ptr DCL_DF12_SPS* pointer with assigned parameters

Return: DCL_DF12* Returns DCL_DF12* with set sps parameters, default parameter will be used if sps_ptr is not specified