LTSpice knows different signal sources. Unfurtunately there is no modulated PWM. This article shows how to generate a voltage controlled PWM.
At first we need two normal voltage sources “voltage”. One voltage source generates the modulation voltage, the other generates the clock for the PWM.
For this example we want to generate a PWM with 20 kHz clock that is modulated by a sine wave of 2000 Hz.
As modulation source every other voltage form is usable too.
The voltage source that generates the sine wave will be set acordingly to the requirements. The PWM shall be 5 V peak voltage and single ended (ground based). That’s why the sine gets an offset voltage of 2.5 V and an amplitude of 2.5 V. That causes the PWM to a middle value of 50%. The maximum modulation of the PWM depends only on the amplitude of the sine wave. At 2.5 V amplitude the modulation will be 100%.
The second voltage source generates the clock of the PWM. To achieve an actual PWM this voltage source must generate a triangular voltage. For 20 kHz the period duration is 50 µs, one ramp has a duration of 25 µs. The amplitude of this source is also set to 5 V.
Up to now this is not a PWM yet. Now both voltages need to be connected.
For this a common ground needs to be defined and each voltage needs a unique name. The voltage sources are connected to ground with their “-” terminal. The “+” terminal is connected to a short wire. These wires are open on the other end. Each wire is given a unique name. In our example they are named “sine” and “ramp”.
Now only the combination of both voltages to a PWM is missing.
For that combination we use the “arbitrary behavioural voltage source”. These voltage sources generate a voltage that is defined by formulas and functions.
For our use a simple IF-function will suffice: if the value of the sine wave is higher than the triangular voltage a voltage will be put out. If the value is lower 0 will be put out. For our example we choose 5 V for the peak value of the PWM.
This voltage source must be connectet to ground too. That the PWM does not stand for itself the output is connected to a simple RC low pass filter.
The last figure shows all voltages as the result.
- Red: the sine wave,
- Blue: the triangular voltage,
- Green: the PWM and
- Yellow: the voltage from the PWM after the low pass filter
Hy,
thanks for this small tutorial
very usefull for me to simulate an DC/AC converter with a MOSFETs bridge
Sincerely
Thomas
please you have compltet simulation of pwm inverter
@lacen no, this is only a simple tutorial. the simulation of complete pwm inverters is for more complex than the focus of this little tutorial.
Unusual this post is totaly unrelated to what I was searching google for, but it was listed on the 1st web page. I guess your doing something proper if Google likes you sufficient to put you on the 1st page of a non related search.
Perfect for what I needed. Thanks! And it worked the first time! I’m passing a very small slow analog voltage through a very noisy environment so I will pass the very small voltage over a BIG PWM signal. This generator will allow me to simulate the receiving end. Perfect for what I needed. Thanks! Good tutorial too, loved it! – Mike Colley
Hi Guys,
I am novice in this field. I tired to do as it is given here but its not working. Please help me out with the complete solution.
Thanks in advance.
This is just too awesome to create a PWM pulses, particularly thanks for introducing “arbitarary voltage”. I was able to get different waveforms combine with this.
Thank you very much.
It helps me a lot.
This was an excellent tutorial.
I see you have not updated your site for a while which is a shame. I hope you find some time to share more knowledge. There are many like me who could use some basic lessons in LTSpice like this.
Hallo! Ich möchte diese Sache machen, aber bekomme ich dieses Fehler:
Circuit: * C:\Program Files (x86)\LTC\LTspiceIV\Draft1.asc
Error on line 4 : v§b1 pwm 0 v=(v2(sine)>v1(ramp),5,0)
Unknown parameter “v”
WARNING: Less than two connections to node RAMP. This node is used by V1.
WARNING: Less than two connections to node SINE. This node is used by V2.
WARNING: Less than two connections to node PWM. This node is used by V§B1.
B1: Missing value, assumed 0V @ DC
Direct Newton iteration for .op point succeeded
Was ist los?
How to put that IF function.
The one in the last circuit diagram ?
@Mike Barrow
I really would like to post here more often, but this is only a “side-Blog” for me…
Life has its own plans. 😉
@akshay:
You just right-click on the “Arbitrary behavioral voltage source”(BV) and enter the formula into the field “Value” of the attribute “Value”… sounds confusing, but they are named that way. 😉
Or you right-click on the “V=F(…)” at the BV and enter there the formula.
I hope this helps.
Thank you for sharing this. As a newcomer to SPICE, it is exactly what I needed to start working on a PWM-to-analog circuit project.
Is possible simulate the frequency response ?