PWM
Generate pulse width modulated signal on analog output pin
Add-On Required: This feature requires the Simulink Support Package for Arduino Hardware add-on.
Libraries:
Simulink Support Package for Arduino Hardware /
Common
Description
The PWM block generates square pulses of varying duty cycle depending on the input value sent to the block on the Arduino® hardware pin. This block enables a digital output to provide a range of different power levels, similar to that of an analog output.
For more information on how to select pins when you Simulink® model contains PWM, Standard Servo Read, Standard Servo Write, Continuous Servo Write, and Input Capture blocks, see Conflicting Pin Configurations on Arduino Timer.
Maximum Achievable PWM Frequency
This table specifies the maximum PWM frequency that can be generated on the digital pins of the following Arduino boards.
Arduino Board Type | Maximum Achievable PWM Frequency |
---|---|
Uno, Nano 3.0, Mega 2560/ADK, Leonardo, Robot Control Board, Robot Motor Board, Micro | 4 MHz |
Nano 33 IoT, MKR Zero, MKR 1000 | 24 MHz |
Due | 21 MHz |
Arduino compatible ESP32 WROOM and WROVER | 31.25 KHz |
Limitations
If you use the PWM block along with the Serial Receive and Serial Transmit blocks in a Simulink model, use longer sample times to avoid overruns.
This table specifies the upper limit of the output frequency that can be generated on the digital pins of the following Arduino boards.
Arduino Board Type Arduino Pin Number Generated PWM Output Frequencies (Hz) Uno, Nano 3.0 5
,6
980.4
3
,11
31372.55
,3921.16
,980.4
,490.2
,245.1
,122.55
,30.64
Mega 2560/ADK 4
,13
980.4
9
,10
31372.55
,3921.16
,980.4
,490.2
,245.1
,122.55
,30.64
Leonardo, Robot Control Board, Robot Motor Board, Micro 3
,11
980.4
Ports
Input
Parameters
Version History
Introduced in R2012b
See Also
Install Support for Arduino Hardware | Pin Mapping for Arduino Timer Dependent Blocks | Conflicting Pin Configurations on Arduino Timer | Model Configuration Parameters for Simulink Support Package for Arduino Hardware | Standard Servo Read | Standard Servo Write | Continuous Servo Write | Supported Default PWM Frequencies and Pins on Arduino Compatible Teensy Boards