LTspice - Take Voltage and Convert to PWM

Thread Starter

mriksman

Joined Aug 31, 2010
65
Hi,

In LTspice, I have a voltage. I want to convert it to a PWM. This is only for LTspice - it doesn't have to be a something that can be realised.

Tperiod is 10ms.

So if the measured voltage is 2.3V, and my reference is 3.3V, then I want a PWM to have a duty of 69% (2.3V/3.3V). So Ton 6.9ms.

The start of the PWM must be on 0, 10ms, 20ms, 30ms, 40ms etc. The reason I say this is, I used a Sawtooth and a comparator to do it, but the PWM doesn't align to those times and I need it to.
 

Thread Starter

mriksman

Joined Aug 31, 2010
65
hi m,
Look at this option.
E
I can't work out how to apply this to my scenario. I don't need to sweep. I need to set {period} based on a voltage.

How can I remove the sweep part? When I set sweep to 0, then it's just ON. And when I remove everything after the >, I get a sawtooth...
 

Thread Starter

mriksman

Joined Aug 31, 2010
65
dim is red. It is the control voltage.
I then use a Sawtooth function and a comparator, to work out how long the pulse should stay on for.
As shown, this works well.

BUT.

I need the purple line to turn on at the same time as the green line. It MUST be aligned to 80ms, 100ms, 120ms etc. The sawtooth is causing it to be shifted.

1599843567700.png
 

Thread Starter

mriksman

Joined Aug 31, 2010
65
What happens when it gets to 100%? Stay at 100%? Or back to 0% and start the cycle again?
Happy for it to stay at 100%. I'll set .tran accordingly stop time accordingly.
But either is fine. Whatever is easier.

I fixed Q1
V=9*((time/period-int(time/period))<if(v(dim,gnd_a)<40m,0,v(dim,gnd_a)/2.5))
 

Alec_t

Joined Sep 17, 2013
11,640
I think if you use that Q1 equation for your BV, in conjunction with your stepped PWL source as the Dim voltage, that should answer Question 2.
 

Thread Starter

mriksman

Joined Aug 31, 2010
65
Yeah nice. This works
V=3.3*((time/period-int(time/period))<v(step)/3.3)

Any ideas on how to avoid that? Have it so that it automatically steps down based on time?
 
Top