This example shows how the discrete-time Simscape™ Foundation Library 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. To view the implementation, select the PWM Voltage Source block, and type Ctrl-U to look under the mask.
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.