Electronic – way to sweep duty cycle over time in LTspice

duty cycleltspice

I can sweep the frequency in time by using modulate, but I couldn't find any example on creating a varying duty cycle or a duty cycle is swept from zero to 100% at a given frequency f in a time interval.

Is there a way/workaround to sweep duty cycle over time in LTspice?

Edit:

I have the following timer circuit which can do that.
But that wasn't I was looking for, since this type of solution slows down the simulation a lot. I was wondering is there a fast way to do that with a single special function or SPICE command.

enter image description here

Please left click on the below plot to enlarge and be able to see the duty cycle variation:

enter image description here

Best Answer

I am not quite sure if this is what you really want, but lets try anyways. First we create a sawtooth ramp with a certain frequency by using our own defined modulo function with the time (green trace):

.function mod(x,y) { (x/y)-int(x/y) }

Then we use the actual time and the if function as a cutoff point for creating a square wave with an arbitrary voltage source:

V=if( (mod(time*10,1)) > time, 1, 0 )

enter image description here

This should give you a good starting point to tinker around and adapt to your needs.