ModusToolbox Power Control Middleware Library
Using the Library

Library configuration and variant selection
Each functional block provides multiple implementation variants to suit different requirements:

Including the library

The recommended way to add the Power Control Middleware Library to your project is through the ModusToolbox Library Manager. Open the Library Manager from the IDE or by running 'make modlibs' from a ModusToolbox shell terminal, search for mtb-mw-pctrl, and add it to your project. The Library Manager will handle downloading and configuring the library dependency automatically.

Alternatively, you can manually create a dependency file deps/mtb-mw-pctrl.mtb to include the Power Control Middleware Library into the project, and run 'make getlibs' from a ModusToolbox shell terminal in your project to install the dependency.

The Power Control Middleware Library can be used in an application source file by including the header file:

#include "mtb_mw_pctrl.h"

Functional Blocks

The library provides the following functional blocks and implementation variants:

Block NameVariantDescription
filter_3p3zDF1-Q23 (default) Bit-accurate emulation of HWFILTER peripheral from PSoC Control Performance line MCUs for portability and simulation.
filter_3p3zHardware Hardware-accelerated implementation using HWFILTER peripheral on PSoC Control Performance line MCUs.
filter_3p3zDF2-F32 Software implementation in Direct Form 2 using single-precision floating-point for MCUs without HWFILTER peripheral.
ac_rms_pllThree phase (default) Standard SRF-PLL for balanced three-phase systems using alpha-beta frame inputs.
ac_rms_pllSingle phase SRF-PLL with SOGI for quadrature signal generation in single-phase systems. Supports DC offset and harmonic rejection.
ac_rms_pllThree phase double decoupling DDSRF-PLL for superior phase tracking under unbalanced grid conditions and voltage sags.
mpptPerturb and observe (default) Duty-cycle based P&O algorithm for maximum power point tracking in photovoltaic and other variable power sources.

Each block provides multiple implementation variants optimized for different use cases (e.g., hardware-accelerated, software-portable, precision vs. performance trade-offs). See Configuration for variant selection details. Before including the library, the variants can be configured. Otherwise, the default variant is used.

Configuration

  • Hardware-accelerated variants: Utilize MCU-specific peripherals for optimal performance
  • Software variants: Portable implementations for simulation or targets without hardware acceleration
  • Specialized variants: Optimized for specific use cases (e.g., single-phase vs. three-phase PLLs)

Unless otherwise stated in the block description, all variants of a block share the same API, allowing seamless switching between variants without application code changes.

Library configuration is done project-wide using a user configuration header file (see User configuration file). This ensures consistent behavior across all compilation units in your application.

The following table lists the available configuration options:

BlockMacro nameDefaultPurpose
filter_3p3zFILTER_3P3Z_USE_VARIANT_DF1_Q23 definedUse software variant (DF1-Q23)
filter_3p3zFILTER_3P3Z_USE_VARIANT_DF2_F32 not definedUse software variant (DF2-float32)
filter_3p3zFILTER_3P3Z_USE_VARIANT_HW not definedUse hardware-accelerated variant
filter_3p3zFILTER_3P3Z_USE_INLINE not definedUse function inlining
filter_3p3z FILTER_3P3Z_USE_VARIANT_DF1_Q23_HW_PPCA_BEHAVIOR not defined Enable bit-accurate HW emulation (DF1-Q23 only)
ac_rms_pllAC_RMS_PLL_USE_VARIANT_1PH not definedUse single phase variant
ac_rms_pllAC_RMS_PLL_USE_VARIANT_3PH definedUse three phase variant
ac_rms_pllAC_RMS_PLL_USE_VARIANT_3PHDD not defined Use three phase double-decoupling variant
ac_rms_pllAC_RMS_PLL_USE_INLINE not definedUse function inlining
ac_rms_pllAC_RMS_PLL_FREQ_FILTER not definedEnable frequency low-pass filter
ac_rms_pllAC_RMS_PLL_RMS_FILTER not definedEnable RMS low-pass filter
ac_rms_pllAC_RMS_PLL_D_AXIS_ALIGN not defined Align PLL to d-axis instead of q-axis
ac_rms_pllAC_RMS_PLL_USE_CMSIS_DSP_LIB not defined Use ARM CMSIS DSP library for math operations
ac_rms_pllAC_RMS_PLL_3PHDD_USE_CTRL_3P3Z_HW not defined Use hardware 3P3Z controller (3PHDD only)
ac_rms_pllACRMSPLL_DCOFFSET_REJECT not defined Enable DC offset rejection (1PH only)
ac_rms_pllACRMSPLL_3RD_HARMONIC_REJECT not defined Enable 3rd harmonic rejection (1PH only)
ac_rms_pllACRMSPLL_5TH_HARMONIC_REJECT not defined Enable 5th harmonic rejection (1PH only)
mpptMPPT_USE_VARIANT_PNO definedUse Perturb and Observe variant
mpptMPPT_USE_INLINE not definedUse function inlining

Without defining the macros for variant selection, the default variants are used.

User configuration file


Implementation variants are selected project-wide in the user configuration file (mtb_mw_pctrl_user_config.h) as a centralized location. This file must be placed in the include path of the application project. It is included by the library to apply configurations that deviate from the default values.

For using the filter software variant as an inline function, the user config file should contain

#define FILTER_3P3Z_USE_VARIANT_DF1_Q23
#define FILTER_3P3Z_USE_INLINE

Alternatively, for using the filter hardware variant, the user config file should contain

#define FILTER_3P3Z_USE_VARIANT_HW