Library configuration and variant selection
Each functional block provides multiple implementation variants to suit different requirements:
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:
The library provides the following functional blocks and implementation variants:
| Block Name | Variant | Description |
|---|---|---|
| filter_3p3z | DF1-Q23 (default) | Bit-accurate emulation of HWFILTER peripheral from PSoC Control Performance line MCUs for portability and simulation. |
| filter_3p3z | Hardware | Hardware-accelerated implementation using HWFILTER peripheral on PSoC Control Performance line MCUs. |
| filter_3p3z | DF2-F32 | Software implementation in Direct Form 2 using single-precision floating-point for MCUs without HWFILTER peripheral. |
| ac_rms_pll | Three phase (default) | Standard SRF-PLL for balanced three-phase systems using alpha-beta frame inputs. |
| ac_rms_pll | Single phase | SRF-PLL with SOGI for quadrature signal generation in single-phase systems. Supports DC offset and harmonic rejection. |
| ac_rms_pll | Three phase double decoupling | DDSRF-PLL for superior phase tracking under unbalanced grid conditions and voltage sags. |
| mppt | Perturb 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.
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:
| Block | Macro name | Default | Purpose |
|---|---|---|---|
| filter_3p3z | FILTER_3P3Z_USE_VARIANT_DF1_Q23 | defined | Use software variant (DF1-Q23) |
| filter_3p3z | FILTER_3P3Z_USE_VARIANT_DF2_F32 | not defined | Use software variant (DF2-float32) |
| filter_3p3z | FILTER_3P3Z_USE_VARIANT_HW | not defined | Use hardware-accelerated variant |
| filter_3p3z | FILTER_3P3Z_USE_INLINE | not defined | Use 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_pll | AC_RMS_PLL_USE_VARIANT_1PH | not defined | Use single phase variant |
| ac_rms_pll | AC_RMS_PLL_USE_VARIANT_3PH | defined | Use three phase variant |
| ac_rms_pll | AC_RMS_PLL_USE_VARIANT_3PHDD | not defined | Use three phase double-decoupling variant |
| ac_rms_pll | AC_RMS_PLL_USE_INLINE | not defined | Use function inlining |
| ac_rms_pll | AC_RMS_PLL_FREQ_FILTER | not defined | Enable frequency low-pass filter |
| ac_rms_pll | AC_RMS_PLL_RMS_FILTER | not defined | Enable RMS low-pass filter |
| ac_rms_pll | AC_RMS_PLL_D_AXIS_ALIGN | not defined | Align PLL to d-axis instead of q-axis |
| ac_rms_pll | AC_RMS_PLL_USE_CMSIS_DSP_LIB | not defined | Use ARM CMSIS DSP library for math operations |
| ac_rms_pll | AC_RMS_PLL_3PHDD_USE_CTRL_3P3Z_HW | not defined | Use hardware 3P3Z controller (3PHDD only) |
| ac_rms_pll | ACRMSPLL_DCOFFSET_REJECT | not defined | Enable DC offset rejection (1PH only) |
| ac_rms_pll | ACRMSPLL_3RD_HARMONIC_REJECT | not defined | Enable 3rd harmonic rejection (1PH only) |
| ac_rms_pll | ACRMSPLL_5TH_HARMONIC_REJECT | not defined | Enable 5th harmonic rejection (1PH only) |
| mppt | MPPT_USE_VARIANT_PNO | defined | Use Perturb and Observe variant |
| mppt | MPPT_USE_INLINE | not defined | Use function inlining |
Without defining the macros for variant selection, the default variants are used.
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
Alternatively, for using the filter hardware variant, the user config file should contain