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 and 1) we have to scale the output signal back to [0..1].
This block has been tested successfully with Matlab R2016a (Simulink 8.7).