This example shows how the Simscape™ Foundation Library Asynchronous Sample & Hold 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. To view the implementation, select the PWM Voltage Source block, and type Ctrl-U to look under the mask.
For an alternative discrete-time implementation, see the Discrete-Time PWM Voltage Source example, ssc_pwm_discrete. 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.