Discrete-Time PWM Voltage Source
This example shows how the discrete-time Simscape™ Foundation Library PS Counter block can be used to build components with more complex behaviors. The model implements a controllable PWM voltage source where the PWM on-time (the duty cycle) is proportional to the physical signal input u.
For an alternative asynchronous implementation, see the Asynchronous PWM Voltage Source example, ssc_pwm_asynchronous. The discrete-time version is better suited to fixed-step solvers and hardware-in-the-loop applications, whereas the asynchronous implementation is better suited to fast desktop simulation using variable-step solvers.
Discrete PWM Voltage Source Subsystem
Simulation Results from Scopes
Simulation Results from Simscape Logging
These plots show the output voltage of the Discrete PWM Voltage Source as well as the step size used during simulation. Because a fixed-step solver is used, the step size remains constant during the simulation. The step size used must be small enough to capture the duty cycle variation with an acceptable resolution.
These plots compare the results of ssc_pwm_discrete and ssc_pwm_asynchronous. The models produce nearly the same voltage signal, but the asynchronous model can run with a variable-step solver and can take larger steps. This can result in faster simulations.