Main Content

PWM Interface

Simulate pulse width modulation (PWM) output from hardware

Since R2020b

  • Block icon of PWM Interface.

Libraries:
C2000 Microcontroller Blockset / Test Bench Blocks
SoC Blockset / Peripherals

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.

Approximate waveform of PWM signal.

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.

Dependencies

To enable this port, the Type parameter must be set to ADC start or ADC start and PWM interrupt.

Data Types: rteEvent

This port creates a replica port of the event output port to coordinate multiple ADC modules with the PWM module.

Dependencies

To enable this port, set the Type parameter to ADC start or ADC start and PWM interrupt and the Number of replicas parameter to a value greater than or equal to 2.

Data Types: rteEvent

This port sends a message during each PWM output event that can connect to the Task Manager block to trigger other tasks in response to the PWM output update.

Dependencies

To enable this parameter, set the Type parameter to PWM interrupt or ADC start and PWM interrupt.

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: Switching

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

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 or 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.

Event

Specify the types of events on which to generate events. When the Typevalue is set to:

  • ADC start — Generate an event to trigger the start ADC conversion.

  • PWM interrupt — Generate an interrupt event to trigger the start of a task.

  • ADC start and PWM interrupt — Generate events for both ADCs and tasks.

Example: ADC start and PWM interrupt

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

Example: Mid or End of PWM period

Dependencies

To enable this parameter, the Type parameter must be set to ADC start or ADC start and PWM interrupt.

Specify to generate and output an ADC trigger event on the specified multiple of the PWM vent. For example, if Generate on is set to the 6th event, the PWM Interface block receives 6 messages updates the output 6 times before generating an ADC event message.

Example: 4th event

Dependencies

To enable this parameter, the Type parameter must be set to ADC start or ADC start and PWM interrupt.

Generate replica ADC event ports and events on the block. Use this coordinate the triggering of multiple ADCs modules from a single PWM Interface block.

Example: 4

Dependencies

To enable this parameter, the Type parameter must be set to ADC start or ADC start and PWM interrupt.

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

Example: Mid or End of PWM period

Dependencies

To enable this parameter, the Type parameter must be set to PWM interrupt or ADC start and PWM interrupt.

Specify the time required by the PWM hardware module from the completion of the output update to the generation of the interrupt in software.

Example: 0.00001

Dependencies

To enable this parameter, the Type parameter must be set to PWM interrupt or ADC start and PWM interrupt.

Specify to generate and output a PWM interrupt trigger event on the specified multiple of the PWM vent. For example, if Generate on is set to the 6th event, the PWM Interface block receives 6 messages updates the output 6 times before generating an PWM interrupt event message.

Example: 4th event

Dependencies

To enable this parameter, the Type parameter must be set to PWM interrupt or ADC start and PWM interrupt.

Extended Capabilities

Version History

Introduced in R2020b