Main Content

PWM Interface

Simulate pulse width modulation (PWM) output from hardware

  • Library:
  • SoC Blockset / Peripherals

  • Block icon of PWM Interface.

Description

The PWM Interface block simulates the PWM output of a hardware board. This blocks gets duty cycle data messages from a connected PWM Write block that can either generate a switching pulse-width-modulated waveform or pass the duty cycle value to the output.

Ports

Input

expand all

This port receives the duty cycle data from the msg port of a connected PWM Write block.

Data Types: SoCData

Output

expand all

This port outputs the pulse-width-modulated rectangular wave defined by the dCycle input port.

Dependencies

To enable this port, set the Output mode parameter to Switching.

Data Types: double

This port outputs the complimentary PWM signal.

Dependencies

To enable this port, set the Output mode parameter to Switching.

Data Types: double

This port emits the averaged value of the PWM waveform, which is a pass-through of the duty cycle input value. This image shows the average output signal equivalent to the PWM output.

Dependencies

To enable this port, set the Output mode parameter to Average.

Data Types: double

This port sends a message during each PWM output event that can connect to the start port of the ADC Interface block to synchronize ADC and PWM events in closed-loop systems.

Data Types: rteEvent

Parameters

expand all

Main

Specify the period of the PWM waveform in seconds.

Note

For PWM waveform period (s) of 10ns, the duty cycle must be greater than 1%.

Simulate the output signal as either a true PWM waveform by specifying Switching or as the average of the duty cycle by specifying Average.

Example: 50e-6

The counter mode specifies the shape of the underlying sawtooth waveform that drives the PWM output signal inside the PWM module. In Up mode, the sawtooth counter increments to the maximum and then resets to zero on each period. In Down mode, the sawtooth counter decrements to zero then resets to the maximum. In Up-Down mode, the sawtooth counter oscillates from zero to the maximum value.

Example: Up

Specify the time at which the input duty cycle is sampled.

Example: Mid or End of PWM period

A time delay is introduced between turning off one of the transistors of a leg of an inverter and turning on the other transistor to ensure that a dead short circuit does not occur. This diagram shows the expected duty cycle and the delay introduced by the transistor switching the dead band.

Example: 450e-9

Specify when this block triggers an event relative to the PWM waveform.

Example: Mid or End of PWM period

PWM Output

Specify the state of the PWM waveform signal at the position in the waveform relative to the total period. When set to High or Low, the waveform output changes to 1 or 0, respectively. When set to Change, the waveform inverts the current value. When set to NoChange, the waveform does not change. The position can either be the start or mid point of the PWM waveform. This table gives the default settings for these parameters.

ParameterDefault
At start of periodHigh
At mid of periodNoChange

Dependencies

At mid of period is only available when the Counter mode parameter is set to Up-Down.

Specify the state of the PWM waveform signal when the internal PWM counter triggers comparator n. When set to High or Low, the waveform output changes to 1 or 0, respectively. When set to Change, the waveform inverts the current value. When set to NoChange, the waveform does not change. Two comparators, 1 and 2, are available to modify the PWM signal. This table gives the default settings for these parameters.

ParameterDefault
At compare 1Low
At compare 2NoChange

Dependencies

At compare 1 and At compare 2 parameters are only available when the Counter mode parameter is set to Up-Down.

Specify the state of the PWM waveform signal when the internal PWM counter crosses the comparator n value in the specified direction. When set to High or Low, the waveform output changes to 1 or 0, respectively. When set to Change, the waveform inverts the current value. When set to NoChange, the waveform does not change. Two comparators, 1 and 2, are available to modify the PWM signal. This table gives the default settings for these parameters.

ParameterDefault
At compare 1 up countLow
At compare 1 down countHigh
At compare 2 up countNoChange
At compare 2 down countNoChange

Dependencies

These arguments are only available when the Counter mode parameter is set to Up-Down.

Phase

Specify the phase of the PWM waveform relative period of waveform. The phase is represented as a scalar between 0 to 360 degrees.

Extended Capabilities

Introduced in R2020b