ModusToolbox Power Conversion Middleware
Functions

General Description

Most of the Power Conversion functions are instance-based; function names start with the instance name and depend on user configuration.

The instance name 'myPwrConv' has been chosen for the current documentation.

Functions

cy_rslt_t myPwrConv_init (void)
 Performs the Power Conversion instance initialization sequence: More...
 
cy_rslt_t myPwrConv_enable (void)
 Performs the Power Conversion instance enable sequence: More...
 
cy_rslt_t myPwrConv_start (void)
 Performs the Power Conversion instance start sequence: More...
 
cy_rslt_t pwrconv_start (void)
 Starts all the Power Conversion instances in the project synchronously. More...
 
cy_rslt_t myPwrConv_disable (void)
 Performs the Control System disable (stop) sequence for the Power Conversion instance. More...
 
void myPwrConv_ramp (void)
 Generates the reference ramping for soft start and target changing of the instance. More...
 
cy_rslt_t myPwrConv_set_target (float32_t targ)
 Applies a new target for Ramp Generator in case of Infineon Control Loop. More...
 
cy_rslt_t myPwrConv_set_target (uint32_t targ)
 Applies a new target for Ramp Generator in case of Custom Control Loop. More...
 
cy_rslt_t myPwrConv_get_state (uint32_t mask)
 Returns the Power Converter instance current state. More...
 
void myPwrConv_scheduled_adc_trigger (void)
 Triggers the scheduled ADC group. More...
 
__STATIC_FORCEINLINE uint32_t myPwrConv_Vout_get_result (void)
 Gets the ADC channel result in raw counts. More...
 
__STATIC_INLINE void myPwrConv_Vout_prot_enable (void)
 Enables HW protection for PwrConv ADC channel. More...
 
__STATIC_INLINE void myPwrConv_Vout_prot_disable (void)
 Disables HW protection for the PwrConv ADC channel. More...
 
__STATIC_INLINE void myPwrConv_prot_enable (void)
 Enables HW protection for all PwrConv ADC channels. More...
 
__STATIC_INLINE void myPwrConv_prot_disable (void)
 Disables HW protection for all PwrConv ADC channels. More...
 
__STATIC_INLINE uint32_t myPwrConv_prot_get_status (void)
 Returns the HW protection status for all PwrConv ADC channels. More...
 
__STATIC_INLINE uint32_t myPwrConv_Vout_units_to_counts (float32_t units)
 Calculates the value in ADC counts from the value in the channel natural units (Volts/Amperes/etc.). More...
 
__STATIC_FORCEINLINE int32_t myPwrConv_get_error (void)
 Returns the error value calculated from reference and feedback values. More...
 
__STATIC_FORCEINLINE void myPwrConv_mod_upd (void)
 Updates the modulator phase(s) peripheral registers with the mtb_stc_pwrconv_ctx_t::mod value. More...
 

Function Documentation

◆ myPwrConv_init()

cy_rslt_t myPwrConv_init ( void  )

Performs the Power Conversion instance initialization sequence:

  • Initializes FW resources used in the instance
  • Either sets the initial instance target for Infineon Control Loop or resets it for Custom Control Loop
  • Initializes FW resources used in the instance: Interrupt(s) and PWM(s)
Returns
The function operation result Status.

◆ myPwrConv_enable()

cy_rslt_t myPwrConv_enable ( void  )

Performs the Power Conversion instance enable sequence:

  • Initializes the regulator used in the instance
  • Enables PWM(s) and ADC(s) of the instance
Returns
The function operation result Status.
Function Usage
#include "cycfg.h"
void scheduler_callback(void)
{
}
int main(void)
{
init_cycfg_all(); /* Initialize everything configured by the Device Configurator */
__enable_irq();
/* Setup a simple scheduled event timer */
Cy_SysTick_Init(CY_SYSTICK_CLOCK_SOURCE_CLK_LF, (uint32_t)(0.01 * 32768)); /* Set the desired 10ms SysTick period: 0.01s * CLK_LF frequency in Hz */
(void) Cy_SysTick_SetCallback(0UL, scheduler_callback); /* Bing the callback */
Cy_SysTick_Enable(); /* Enable the scheduled events generation */
myPwrConv_enable(); /* Set target and enable HW */
myPwrConv_start(); /* Start HW */
while (0UL != myPwrConv_get_state(MTB_PWRCONV_STATE_RAMP)); /* Wait while it is ramping to the target */
/* Work with original target (configured in PCC) */
myPwrConv_set_target(3.3); /* Change the target to e.g. 3.3V */
/* Now ramping is ended and the converter works with new target */
while (true);
}
void myPwrConv_ramp(void)
Generates the reference ramping for soft start and target changing of the instance.
cy_rslt_t myPwrConv_set_target(float32_t targ)
Applies a new target for Ramp Generator in case of Infineon Control Loop.
cy_rslt_t myPwrConv_get_state(uint32_t mask)
Returns the Power Converter instance current state.
cy_rslt_t myPwrConv_enable(void)
Performs the Power Conversion instance enable sequence:
cy_rslt_t myPwrConv_start(void)
Performs the Power Conversion instance start sequence:
#define MTB_PWRCONV_STATE_RAMP
The ramping flag, indicates that the converter currently is changing the reference value smoothly to ...
Definition: mtb_pwrconv.h:359

◆ myPwrConv_start()

cy_rslt_t myPwrConv_start ( void  )

Performs the Power Conversion instance start sequence:

Returns
The function operation result Status.
Function Usage
#include "cycfg.h"
void scheduler_callback(void)
{
}
int main(void)
{
init_cycfg_all(); /* Initialize everything configured by the Device Configurator */
__enable_irq();
/* Setup a simple scheduled event timer */
Cy_SysTick_Init(CY_SYSTICK_CLOCK_SOURCE_CLK_LF, (uint32_t)(0.01 * 32768)); /* Set the desired 10ms SysTick period: 0.01s * CLK_LF frequency in Hz */
(void) Cy_SysTick_SetCallback(0UL, scheduler_callback); /* Bing the callback */
Cy_SysTick_Enable(); /* Enable the scheduled events generation */
myPwrConv_enable(); /* Set target and enable HW */
myPwrConv_start(); /* Start HW */
while (0UL != myPwrConv_get_state(MTB_PWRCONV_STATE_RAMP)); /* Wait while it is ramping to the target */
/* Work with original target (configured in PCC) */
myPwrConv_set_target(3.3); /* Change the target to e.g. 3.3V */
/* Now ramping is ended and the converter works with new target */
while (true);
}

◆ pwrconv_start()

cy_rslt_t pwrconv_start ( void  )

Starts all the Power Conversion instances in the project synchronously.

This non-instance-based function (common for all the instances) initiates the ramp generation and triggers synchronous start of all Power Conversion instances PWMs in the same clock cycle. See Synchronous Start for details.

Returns
The function operation result Status.
Function Usage
/* separately start each instance */
//firstBuck_start();
//secondBuck_start();
/* multi-instance synchronous start */
cy_rslt_t pwrconv_start(void)
Starts all the Power Conversion instances in the project synchronously.

◆ myPwrConv_disable()

cy_rslt_t myPwrConv_disable ( void  )

Performs the Control System disable (stop) sequence for the Power Conversion instance.

Returns
The function operation result Status.
Function Usage
void scheduler_callback(void)
{
(0UL == myPwrConv_get_state(MTB_PWRCONV_STATE_RAMP))) /* When ramp is finished */
{
myPwrConv_Vout_prot_enable(); /* Enable protection for the Vout channel */
}
}
uint32_t protStatus = 0UL;
void myPwrConv_fault_callback(void)
{
/* The converter is already disabled, there is no need to call myPwrConv_disable(); here */
protStatus = myPwrConv_prot_get_status(); /* Inform the application about the fault event */
/* The protection status for all the converter's channels is cleared automatically after the returning from this callback */
}
__STATIC_INLINE uint32_t myPwrConv_prot_get_status(void)
Returns the HW protection status for all PwrConv ADC channels.
__STATIC_INLINE void myPwrConv_Vout_prot_enable(void)
Enables HW protection for PwrConv ADC channel.
#define MTB_PWRCONV_STATE_RUN
The running flag, indicates that the converter is currently running.
Definition: mtb_pwrconv.h:356

◆ myPwrConv_ramp()

void myPwrConv_ramp ( void  )

Generates the reference ramping for soft start and target changing of the instance.

Function Usage
See the Ramp Generator section

◆ myPwrConv_set_target() [1/2]

cy_rslt_t myPwrConv_set_target ( float32_t  targ)

Applies a new target for Ramp Generator in case of Infineon Control Loop.

This function:

The target value is limited by the min/max values of the controlled parameter (typically Vout) in the PCC:

Parameters
[in]targThe target value in Volts.
Returns
The function operation result Status.
Function Usage
result = myPwrConv_enable();
result = myPwrConv_set_target(5.5); /* Set the output voltage target to 5.5V */
result = myPwrConv_start();
For details, see the Ramp Generator section.

◆ myPwrConv_set_target() [2/2]

cy_rslt_t myPwrConv_set_target ( uint32_t  targ)

Applies a new target for Ramp Generator in case of Custom Control Loop.

This function:

Parameters
[in]targThe target value in Counts.
Returns
The function operation result Status.
Function Usage
result = myPwrConv_enable();
result = myPwrConv_set_target(myPwrConv_Vout_units_to_counts(7.0)); /* Set the output voltage target to 7.0V */
result = myPwrConv_start();
__STATIC_INLINE uint32_t myPwrConv_Vout_units_to_counts(float32_t units)
Calculates the value in ADC counts from the value in the channel natural units (Volts/Amperes/etc....
For details, see the Ramp Generator section.

◆ myPwrConv_get_state()

cy_rslt_t myPwrConv_get_state ( uint32_t  mask)

Returns the Power Converter instance current state.

Parameters
[in]maskThe mask to get one or more specified power converter States.
Returns
The power converter state States.
Function Usage
#include "cycfg.h"
void scheduler_callback(void)
{
}
int main(void)
{
init_cycfg_all(); /* Initialize everything configured by the Device Configurator */
__enable_irq();
/* Setup a simple scheduled event timer */
Cy_SysTick_Init(CY_SYSTICK_CLOCK_SOURCE_CLK_LF, (uint32_t)(0.01 * 32768)); /* Set the desired 10ms SysTick period: 0.01s * CLK_LF frequency in Hz */
(void) Cy_SysTick_SetCallback(0UL, scheduler_callback); /* Bing the callback */
Cy_SysTick_Enable(); /* Enable the scheduled events generation */
myPwrConv_enable(); /* Set target and enable HW */
myPwrConv_start(); /* Start HW */
while (0UL != myPwrConv_get_state(MTB_PWRCONV_STATE_RAMP)); /* Wait while it is ramping to the target */
/* Work with original target (configured in PCC) */
myPwrConv_set_target(3.3); /* Change the target to e.g. 3.3V */
/* Now ramping is ended and the converter works with new target */
while (true);
}

◆ myPwrConv_scheduled_adc_trigger()

void myPwrConv_scheduled_adc_trigger ( void  )

Triggers the scheduled ADC group.

The instance-based function to trigger the scheduled ADC group, if such is configured by the Power Conversion Configurator.

Function Usage
void scheduler_callback(void)
{
}
void myPwrConv_scheduled_adc_callback(void)
{
if (myPwrConv_Temp_MAX < myPwrConv_Temp_get_result())
{
myPwrConv_disable(); /* Emergency stop for overheat protection */
}
}
void myPwrConv_scheduled_adc_trigger(void)
Triggers the scheduled ADC group.
cy_rslt_t myPwrConv_disable(void)
Performs the Control System disable (stop) sequence for the Power Conversion instance.

◆ myPwrConv_Vout_get_result()

__STATIC_FORCEINLINE uint32_t myPwrConv_Vout_get_result ( void  )

Gets the ADC channel result in raw counts.

The instance-based ADC-channel-based function to get the ADC channel result directly from the ADC result register.
If ADC DMA is configured for this channel, this function gets ADC value from the SRAM cell, which is more efficient on terms of CPU cycles consumption.
This function exists for each PwrConv ADC channel, under the name: [instance_name]_[channel_name]_get_result.

Returns
The ADC channel result value
Note
In Infineon Control Loop mode, for the feedback ADC channel (Vout by default), this function gets the value from mtb_stc_pwrconv_ctx_t::res instead of the ADC register.
In Custom Control Loop mode there is no feedback ADC channel defined, so mtb_stc_pwrconv_ctx_t::res has to be updated in the application code using this function.
Function Usage
__STATIC_INLINE void myPwrConv_custom_callback(void)
{
static float32_t modAvg = 0.0;
myPwrConv.ctx->res = myPwrConv_Vout_get_result(); /* Retrieving the feedback value */
modAvg = 0.99 * modAvg + 0.01 * myPwrConv_get_error(); /* The simplest first-order regulator */
modAvg = (modAvg < myPwrConv_SLOPE_START_MIN) ? myPwrConv_SLOPE_START_MIN : /* Anti-windup limitation */
(modAvg > myPwrConv_SLOPE_START_MAX) ? myPwrConv_SLOPE_START_MAX : modAvg;
myPwrConv.ctx->mod = (uint32_t)(int32_t)modAvg; /* Update modulation value */
myPwrConv_mod_upd(); /* Update modulator HW */
}
__STATIC_FORCEINLINE void myPwrConv_mod_upd(void)
Updates the modulator phase(s) peripheral registers with the mtb_stc_pwrconv_ctx_t::mod value.
__STATIC_FORCEINLINE uint32_t myPwrConv_Vout_get_result(void)
Gets the ADC channel result in raw counts.
__STATIC_FORCEINLINE int32_t myPwrConv_get_error(void)
Returns the error value calculated from reference and feedback values.

◆ myPwrConv_Vout_prot_enable()

__STATIC_INLINE void myPwrConv_Vout_prot_enable ( void  )

Enables HW protection for PwrConv ADC channel.

The instance-based ADC-channel-based function activates the limit crossing detection for the specific ADC channel which is configured with Hardware Protection in the PCC.

This function exists for each Hardware Protection -enabled PwrConv ADC channel, under the name: [instance_name]_[channel_name]_prot_enable.

Function Usage
void scheduler_callback(void)
{
(0UL == myPwrConv_get_state(MTB_PWRCONV_STATE_RAMP))) /* When ramp is finished */
{
myPwrConv_Vout_prot_enable(); /* Enable protection for the Vout channel */
}
}
uint32_t protStatus = 0UL;
void myPwrConv_fault_callback(void)
{
/* The converter is already disabled, there is no need to call myPwrConv_disable(); here */
protStatus = myPwrConv_prot_get_status(); /* Inform the application about the fault event */
/* The protection status for all the converter's channels is cleared automatically after the returning from this callback */
}

◆ myPwrConv_Vout_prot_disable()

__STATIC_INLINE void myPwrConv_Vout_prot_disable ( void  )

Disables HW protection for the PwrConv ADC channel.

The instance-based ADC-channel-based function disactivates the limit crossing detection for the specific ADC channel which is configured with Hardware Protection in the PCC.

This function exists for each Hardware Protection -enabled PwrConv ADC channel, under the name: [instance_name]_[channel_name]_prot_disable.

◆ myPwrConv_prot_enable()

__STATIC_INLINE void myPwrConv_prot_enable ( void  )

Enables HW protection for all PwrConv ADC channels.

The instance-based function activates the limit crossing detection for all ADC channels which are configured with Hardware Protection in the PCC.

◆ myPwrConv_prot_disable()

__STATIC_INLINE void myPwrConv_prot_disable ( void  )

Disables HW protection for all PwrConv ADC channels.

The instance-based function disactivates the limit crossing detection for all ADC channels which are configured with Hardware Protection in the PCC.

This function is being called by myPwrConv_disable

◆ myPwrConv_prot_get_status()

__STATIC_INLINE uint32_t myPwrConv_prot_get_status ( void  )

Returns the HW protection status for all PwrConv ADC channels.

The instance-based function returns a combined mask of HW protection status for all ADC channels which are configured with Hardware Protection in the PCC.

Returns
The combined mask of the channel HW protection status

The channel specific masks are generated for each HW-protection-enabled channel in the following format: [instance_name]_[channel_name]_MSK

◆ myPwrConv_Vout_units_to_counts()

__STATIC_INLINE uint32_t myPwrConv_Vout_units_to_counts ( float32_t  units)

Calculates the value in ADC counts from the value in the channel natural units (Volts/Amperes/etc.).

The instance-based ADC-channel-based function considers the particular-channel external gain (voltage divider, shunt resistance, etc.), internal correspondent sampler gain, the ADC resolution, and the reference voltage.

This function exists for each PwrConv ADC channel, under the name: [instance_name]_[channel_name]_units_to_counts.

Parameters
[in]unitsThe value in natural measurement units (Volts/Amperes/etc.)
Returns
The value in ADC counts
Function Usage
See the Ramp Generator section

◆ myPwrConv_get_error()

__STATIC_FORCEINLINE int32_t myPwrConv_get_error ( void  )

Returns the error value calculated from reference and feedback values.

The error value is calculated as the difference between the reference mtb_stc_pwrconv_ctx_t::ref and result mtb_stc_pwrconv_ctx_t::res values.

Returns
The error value, also saved into mtb_stc_pwrconv_ctx_t::err
Function Usage
__STATIC_INLINE void myPwrConv_custom_callback(void)
{
static float32_t modAvg = 0.0;
myPwrConv.ctx->res = myPwrConv_Vout_get_result(); /* Retrieving the feedback value */
modAvg = 0.99 * modAvg + 0.01 * myPwrConv_get_error(); /* The simplest first-order regulator */
modAvg = (modAvg < myPwrConv_SLOPE_START_MIN) ? myPwrConv_SLOPE_START_MIN : /* Anti-windup limitation */
(modAvg > myPwrConv_SLOPE_START_MAX) ? myPwrConv_SLOPE_START_MAX : modAvg;
myPwrConv.ctx->mod = (uint32_t)(int32_t)modAvg; /* Update modulation value */
myPwrConv_mod_upd(); /* Update modulator HW */
}

◆ myPwrConv_mod_upd()

__STATIC_FORCEINLINE void myPwrConv_mod_upd ( void  )

Updates the modulator phase(s) peripheral registers with the mtb_stc_pwrconv_ctx_t::mod value.

Note
For the Modulator DMA usage, this function only triggers the Modulator DMA channel.
Function Usage
__STATIC_INLINE void myPwrConv_custom_callback(void)
{
static float32_t modAvg = 0.0;
myPwrConv.ctx->res = myPwrConv_Vout_get_result(); /* Retrieving the feedback value */
modAvg = 0.99 * modAvg + 0.01 * myPwrConv_get_error(); /* The simplest first-order regulator */
modAvg = (modAvg < myPwrConv_SLOPE_START_MIN) ? myPwrConv_SLOPE_START_MIN : /* Anti-windup limitation */
(modAvg > myPwrConv_SLOPE_START_MAX) ? myPwrConv_SLOPE_START_MAX : modAvg;
myPwrConv.ctx->mod = (uint32_t)(int32_t)modAvg; /* Update modulation value */
myPwrConv_mod_upd(); /* Update modulator HW */
}