Main Content

Asynchronous PWM Voltage Source

This example shows how the Simscape™ Foundation Library PS 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.

The PS Asynchronous Sample & Hold block enables accurate capturing of the PWM signal edges and faster simulation speed than a discrete implementation. This model should be run using a variable-step solver so that equations are solved at exactly every PWM switching event. This gives perfect resolution of the desired duty cycle. Running fixed step would require running the entire simulation at a step size equal to the desired duty cycle resolution.

For an alternative discrete-time implementation, see the Discrete-Time PWM Voltage Source example, DiscreteTimePWMVoltageSourceExample. The discrete-time version is better suited to fixed-step solvers and hardware-in-the-loop applications.

Model

Asynchronous PWM Voltage Source Subsystem

Simulation Results from Scopes

Simulation Results from Simscape Logging

These plots show the output voltage of the Asynchronous PWM Voltage Source as well as the step size used during simulation. Because a variable-step solver is used, large steps can be taken until the start or end of a PWM pulse is reached.

These plots compare the results of DiscreteTimePWMVoltageSourceExample and AsynchronousPWMVoltageSource. 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.