Main Content

PWM

Generate pulse width modulated signal of digital output pin

Add-On Required: This feature requires the Simulink Support Package for Raspberry Pi Hardware add-on.

  • Raspberry Pi PWM block icon

Libraries:
Simulink Support Package for Raspberry Pi Hardware / Basic

Description

Use the PWM block to vary the power output of a digital output pin. This block enables a digital output to provide a range of different power levels, similar to that of an analog output.

During simulations without the hardware, this block does nothing. See Block Produces Zeros or Does Nothing in Simulation.

Ports

Input

expand all

The block input inherits the data type of the upstream block, and internally converts it to double. The value sent to the block input determines the width of the square wave, called duty-cycle, that the Raspberry Pi® hardware outputs on the specified PWM pin. The block input accepts a range of values from 0 to 1 (from 0% to 100% of the duty cycle).

For example:

  • The maximum input value, 1, sets the duty cycle to 100%, or full power.

  • The minimum input value, 0, sets the duty cycle to 0%, or no power.

  • An intermediate input value, such as 0.333, sets the duty cycle to 33.3%, or 1/3 power.

  • Out of range input values, such as -0.2 or 1.2, output minimum or maximum power.

Data Types: double

Parameters

expand all

Select your Raspberry Pi hardware board. You can find this information on the target hardware, product packaging, or product documentation.

Select the Raspberry Pi hardware board pin number to which the PWM input signal is connected. To open the pin map of the Raspberry Pi board, click View pin map.

Note

Do not assign the same pin number to multiple blocks within a model.

Select the output frequency of the PWM signal.

Version History

Introduced in R2016b