Generate pulse width modulated signal of digital output pin
Simulink Support Package for Raspberry Pi Hardware / Basic
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.
In — Input value that determines width of square pulses
positive scalar in the range [
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
1 (from 0% to 100% of
the duty cycle).
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
1.2, output minimum or maximum power.
Board — Raspberry Pi hardware board
Pi 2 Model B (default) |
Model B Rev1 |
Model B Rev2 |
Model B+ |
Pi 3 Model B |
Pi 3 Model B+ |
Pi Zero W |
Pi 4 Model B
Select your Raspberry Pi hardware board. You can find this information on the target hardware, product packaging, or product documentation.
Pin — PWM pin number
21 (default) |
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.
Do not assign the same pin number to multiple blocks within a model.
Frequency — PWM output frequency
500 (default) |
Select the output frequency of the PWM signal.
Introduced in R2016b