# LTSPICE - How to create PWM with rise time

A simple PWM circuit is simple to create using LTSPICE, such as:

VIN VSIN 0  SIN(0 1 10 0 0)
VP VTRI 0 PULSE(-1.5 1.5 0 9.998m 1u 1u 10m)
B1 VOUT 0 V=U(V(Vtri)-V(Vsin))*5


But voltage reflection simulations, i need the PWM rising edge to be more realistic, i.e. with a time delay on the rising edge like this:

I have tried using a PULSE, but its frequency and on-time is fixed.

What I need is something that activates a given pulse, or a behavioral voltage source that can create a pulse if a certain condition is true. The pulse has to be as long as the condition is true - as with conventional PWM.

An example of what I have tried, but which caused a syntax error:

The syntax error is that in the B2-element (to the right), cannot use "V1" as voltage output. It has to be 5 (volts) or something.

How to I solve this? I just started using SPICE two days ago, and I bet there is a few tricks I am not aware of yet

• I haven't tried this yet, but you probably need to write V(V1) in that expression/source on the left . – Fizz Nov 15 '15 at 14:01
• Thanks for your comment. It worked partially: It outputs the current value of the PULSE, but that PULSE still have a given on-time which does not adjust according to the desired pulse width. However, I did learn something new which can be useful later. – fluxmodel Nov 15 '15 at 14:20
• Well, I don't see why you expect that latter to work. Your V1 needs to be a triggered ramp. – Fizz Nov 15 '15 at 14:32
• Exactly, but i didn't realize that until seeing the results. Learning by failing – fluxmodel Nov 15 '15 at 15:07

This works for me.

I had to change the prefix to BV for [B]V4. And also use net names; it doesn't seem to take the voltage sources' names in those behavioral expressions.

What I need is something that activates a given pulse, or a behavioral voltage source that can create a pulse if a certain condition is true.

What you seem to actually want however is a PWL triggered ramp like so:

Also what you're describing is not actually called PWM. If you somehow need to modulate the width instead of triggering then see this solution.

Well assuming you only want non-zero rise (as in your graph) but zero fall time, and you want that combined with PWM, then you basically have to combine the above two solutions:

• First of all, thank you for your answer and your effort. I see that I have been unclear in describing what I need. It is in fact a PWM, but I need to be able to adjust the rate of rise of the PWM pulse so that it resembles a realistic voltage output from an e.g. IGBT to a long cable + motor. The width has to be dynamic according to the input sine and triangular wave as normal. – fluxmodel Nov 15 '15 at 15:12
• @fluxmodel: before I add 3rd solution/reply: adjust the rise based on what? – Fizz Nov 15 '15 at 15:15
• I am testing how different rise time affects the voltage reflection and filter parameters. So I have to be able to adjust the rise time before each simulation. during the simulation the rise time will be kept constant. And, once again i am very grateful for your contribution! – fluxmodel Nov 15 '15 at 15:31
• It seems as if your second solution is what i need. I will test it later tonight. – fluxmodel Nov 15 '15 at 15:33
• Works perfectly. Thanks for teaching my these nifty tricks :) – fluxmodel Nov 15 '15 at 21:39

Try using a piece-wise linear voltage source (in the advanced dialog).

This uses a time-value pair sequence and can be defined in the source dialog or from a file.

LTSpice will interpolate from a given pair to the next in a linear fashion.

If I start with time=0 and v=0 and the next pair is at time=1m with v=3, then you will get a rising signal at 3v/millisecond.

Add more points to get the precise wavrform you want.

This is incredibly useful when you have measured a waveform and saved it from a scope to do what-if analysis with a circuit in the simulator, to name at least one other application.

• Thank you for teaching me about PWL. I have tested it and it creates a shape that I want. How can I make the PWM-generator use this signal shape? – fluxmodel Nov 15 '15 at 13:58
• Use the PWLsource as the PWM generator to test the rest of the circuit. – Peter Smith Nov 15 '15 at 14:28

The proposed methods will work, but you're much better off using a dedicated element for this job: [Digital]/diffschmitt:

You can specify separate rise and fall times through trise and tfall. For more about it, see the help, LTspice > Circuit Elements > A. Special functions.