I needed a Simulink block that generates a PWM with variable frequency and duty cycle. The toolboxes I have don’t contain a suitable block and therefore I had to create my own one. I’d like to share the result here in case of anybody else has the need for such a block. Feel free to use this information for whatever you like. Just note that I won’t be responsible for anything.
The block consists of a ramp generator and a comparator. The ramp generator has been realized with a wrapping integrator and the comparator in form of a
sum– and a
sign-block. However, as the
sign-block doesn’t have configurable outputs (it’s fixed to the output values of
1) we have to scale the output signal back to
It’s important that you enable the
Wrap state feature of the integrator. This causes the integrator to reset back to
0 once it hit the upper limit which we set to
This block has been tested successfully with Matlab R2016a (Simulink 8.7).