CB-PWM - Carrier-based PWM

The carrier-based PWM block supports generating PWM signals using common digital carriers. The following configuration options are available:

  • The carrier shape can be selected from the following options: triangle, sawtooth, inverted triangle, or inverted sawtooth (see below).
  • The carrier frequency can be configured by connecting the CB-PWM block to a CLK block. The frequency can even be configured and changed during control execution.
  • The duty cycle and phase shift of the carrier can be adjusted independently during execution. These parameters can be updated either once or twice per period (with triangular-shaped carriers, see below).
  • Like other PWM blocks, CB-PWM supports dead-time generation (see PWM).
  • CB-PWM resources can be activated or deactivated during exection.
Triangle carrier
Inverted triangle carrier
Sawtooth carrier
Inverted sawtooth carrier

With sawtooth carriers, the duty-cycle and phase-shift parameters are always updated at the beginning of the PWM period. However, with triangular carrier shapes, two options are available:

  • Using a single-rate update, these parameters are updated once per period: at the end.
  • With a double-rate update, these parameters are updated twice per period: in the middle and at the end (i.e., when the carrier reaches its maximum and minimum).

The time resolution of the CB-PWM resources is hardware-dependent:

  • On Gen 3 devices (B-Box RCP, B-Box Micro, B-Board PRO and TPI8032) the CB-PWM resolution is directly set by the base clock of 250 MHz. This corresponds to a resolution of 4 ns at the signal edges.
  • On the Gen 4 (B-Box 4), higher resolution is achieved using phase-shifted derivatives of the 250 MHz clock, effectively increasing it by a factor of 16.
duty-cycle
resolution
(sawtooth)
duty-cycle
resolution
(triangle)
phase shift
resolution
High-resolution (B-Box 4 only)250 ps500 ps250 ps
Standard resolution (all other devices)4 ns8 ns4 ns
Resolution specification of the CB-PWM block

Parameters

Addressing

  • Device ID selects which B-Box/B-Board to address when used in a multi-device configuration.
  • Output mode selects between a single PWM signal and complementary signals with a dead-time.
  • Addressed channel(s) or Addressed lane(s) (vectorizable) selects the PWM outputs to address.

Modulation

  • Carrier type: selects the type of carrier (TRIANGLE, SAWTOOTH, INVTRIANGLE, or INVSAWTOOTH)
  • Duty-cycle(s): (vectorizable) configures the duty cycle. It can be tuned in real time using the D signal input or configured only once via the block mask parameter.
  • Phase(s): (vectorizable) configures the carrier phase-shift relative to the CLK. It can be tuned in real time using the P signal input or configured only once via the block mask parameter.
  • Show ”activate” input: makes the A signal input visible. If not checked, the CB-PWM block is active by default.
  • PWM parameters update rate: selects when the duty cycle and phase parameters are updated.
    • Single-rate: they are applied at the end of the carrier period.
    • Double-rate: they are applied twice per carrier period: when the carrier reaches its lowest point and when it reaches its highest point. (for TRIANGLE and INVTRIANGLE carriers only)
  • Simulation output type:
    • PWM signals: outputs are logic gate signals 0 or 1.
    • Duty-cycle: outputs are duty-cycles between 0 and 1. This option is only relevant for simulation with period-averaged models.

Complementary signal parameters

  • Dead-time duration: configures the dead-time duration if the Output mode is set to Dual (PWM_H + PWM_L).

Signal specification

  • The input signal D is the duty-cycle (0.0 to 1.0)
  • The input signal P is the carrier phase-shift relative to the CLK (0.0 to 1.0)
  • The input signal > is the clock input and must be connected to the CONFIG block or to an independent CLK
  • The input A allows the activation (>0) or deactivation (<=0) of the PWM output(s).
  • The output(s) is/are the generated PWM signal(s), according to the selected Output mode. The output(s) is/are only used in simulation.

Mask

PLECS block

Signal specification

  • The input signal D is the duty-cycle (0.0 to 1.0)
  • The input signal P is the carrier phase-shift relative to the CLK (0.0 to 1.0)
  • The input signal > is the clock input and must be connected to the CONFIG block or to an independent CLK
  • The input A allows the activation (>0) or deactivation (<=0) of the PWM output(s).
  • The target outport(s) (only visible at the atomic subsystem level) is/are the generated PWM signal(s), according to the selected Output mode. The output(s) is/are only used in the simulation.

Mask

C++ functions

Functions specific to the carrier-based PWM

void CbPwm_ConfigureClock(tPwmOutput output, tClock clock, unsigned int device=0);
Code language: C++ (cpp)

Connects a clock generator to the modulator.

Can only be called in UserInit().

See: CLK – Clock generator

Parameters

  • output: the PWM channel or lane to address
  • clock: the clock to use (CLOCK_0CLOCK_1CLOCK_2 or CLOCK_3)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void CbPwm_ConfigureCarrier(tPwmOutput output, tPwmCarrier carrier, unsigned int device=0);
Code language: C++ (cpp)

Selects the carrier shape of the modulator.

Can only be called in UserInit().

Parameters

  • output: the PWM channel or lane to address
  • carrier: the carrier to use (TRIANGLESAWTOOTHINVTRIANGLE, or INVSAWTOOTH)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void CbPwm_ConfigureUpdateRate(tPwmOutput output, tPwmRate rate, unsigned int device=0);
Code language: C++ (cpp)

Select when the duty-cycle and phase parameters are applied.

  • Single-rate: they are applied at the end of the carrier period.
  • Double-rate: they are applied twice per carrier period: when the carrier reaches its lowest point and when it reaches its highest point. (for TRIANGLE and INVTRIANGLE carriers only)

Can only be called in UserInit().

Parameters

  • output: the PWM channel or lane to address
  • rate: the update rate to use (SINGLE_RATE or DOUBLE_RATE)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void CbPwm_SetPhase(tPwmOutput output, float phase, unsigned int device=0);
Code language: C++ (cpp)

Configures the carrier phase-shift relative to the CLK.

Can only be called in UserInit() or in the interrupt routine.

Parameters

  • output: the PWM channel or lane to address
  • phase: the carrier phase-shift relative to the CLK (0.0 to 1.0)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void CbPwm_SetDutyCycle(tPwmOutput output, float dutyCycle, unsigned int device=0);Code language: C++ (cpp)

Configures the duty-cycle.

Can only be called in UserInit() or in the interrupt routine.

Parameters

  • output: the PWM channel or lane to address
  • dutyCycle: the duty-cycle (0.0 to 1.0)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)

Functions common to all PWM drivers

These functions are common to all PWM blocks. Further documentation is available on the PWM page.

void CbPwm_ConfigureOutputMode(tPwmOutput output, tPwmOutMode outMode, unsigned int device=0);Code language: C++ (cpp)

Selects the PWM output mode.

If the output mode selected is COMPLEMENTARY, a dead-time must be configured using the CbPwm_ConfigureDeadTime() function.

Can only be called in UserInit().

Parameters

  • output: the PWM channel or lane to address
  • outMode: the output mode to use (COMPLEMENTARYINDEPENDENT or PWMH_ACTIVE)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void CbPwm_ConfigureDeadTime(tPwmOutput output, float deadTime, unsigned int device=0);Code language: C++ (cpp)

Configures the dead-time duration if the output mode is set as COMPLEMENTARY.

Can only be called in UserInit().

Parameters

  • output: the PWM channel or lane to address
  • outMode: the output mode to use (COMPLEMENTARYINDEPENDENT or PWMH_ACTIVE)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void CbPwm_Activate(tPwmOutput output, unsigned int device=0);
Code language: C++ (cpp)

Activates the addressed PWM output(s). If the addressed PWM output has been set as COMPLEMENTARY or PWMH_ACTIVE this function acts on both outputs.

Can only be called in UserInit() or in the interrupt routine.

Parameters

  • output: the PWM channel or lane to address
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void CbPwm_Deactivate(tPwmOutput output, unsigned int device=0);Code language: C++ (cpp)

Deactivates the addressed PWM output(s). If the addressed PWM output has been set as COMPLEMENTARY or PWMH_ACTIVE this function acts on both outputs.

Can only be called in UserInit() or in the interrupt routine.

Parameters

  • output: the PWM channel or lane to address
  • device: the ID of the addressed device (optional, used in multi-device configuration only)