This is not a fully perfected answer, but should give you a good starting point (I hope)
What I tried is using a arbitrary behavioral voltage source.
This is my netlist:
B1 NC_01 0 V=if((time/{period})-int(time/{period})<time*{ontime},{Von},{Voff})
.param period 1
.param ontime=1/100
.param Von 3
.param Voff 0
.tran 100
.backanno
.end
And the screenshot with the result:
Break down of the behavioral voltage source function:
First note that behavioral voltage sources have access to the simulation time using time
as parameter to functions. This is not available in .param
statements.
First we need some function which allows us to allow a PWM function based on the current time. For this the if(x,y,z)
construct is helpful. But a simple if(time<{ontime},3,0)
will not produce a recurring signal but only a pulse at the beginning.
This is where the next constructs comes in: (time/{period})-int(time/{period})
This is basically just time modulus period, but there is no modulus operator, so I have to go down the route to subtract the integer part of time divided by period from the division of time and period. Duh.
Then you have to vary the ontime with regards to time. In this example I simply used the time with a factor of 1/100. ...<time*{ontime}
Well ontime
is not the best name for that parameter probably - it's more like a scaling factor.