LTspice voltage source with varying Ton / Tperiod
What you need is a variable duty cycle, which is part of the control loop. If you have that but don't know how to implement the PWM part, here's a start:

If you don't have the control loop, then you'll have to build one: voltage mode, current mode, karma mode, etc.