[:de]LTSpice kennt verschiedene Signalquellen. Eine modulierbare PWM ist leider nicht dabei. Dieser Beitrag zeigt, wie man ganz schnell selbst eine spannungsabhängige PWM erzeugt.
[:en]LTSpice knows different signal sources. Unfurtunately there is no modulated PWM. This article shows how to generate a voltage controlled PWM.
[:][:de]
Zuerst brauchen wir zwei normale Spannungsquellen „voltage“. Eine Spannungsquelle gibt die Modulationsspannung aus, die andere Spannungsquelle erzeugt den Takt für die PWM.
Für dieses Beispiel wollen wir eine PWM mit 20 kHz Grundtakt mit einer Sinusschwingung von 2000 Hz modulieren.
Als Modulation ist natürlich jeder andere Spannungsverlauf ebenso verwendbar.
Dazu wird die Spannungsquelle, die die Sinusschwingung erzeugen soll, entsprechend eingestellt.
Die PWM soll eine Spitzenspannung von 5 Volt haben und „single-ended“, also auf Masse bezogen sein. Deshalb stellen wir für den Sinus einen Offset und eine Amplitude von 2,5 Volt ein. Damit hat die PWM einen Mittelwert von 50%. Die maximale Modulation der PWM hängt dann nur von der Amplitude der Sinusspannung ab. Bei 2,5 Volt Amplitude ist die Modulation dann 100%.
Die zweite Spannungsquelle erzeugt die PWM-Grundfrequenz. Damit es auch wirklich eine PWM wird, muss diese Spannungsquelle eine Dreieckspannung erzeugen. Für 20 kHz ist die Periodendauer 50µs, eine Flanke dauert damit 25µs. Als Amplitude wird ebenfalls 5V eingestellt.
Bisher ergibt das noch keine PWM. Jetzt müssen die beiden Spannungen mit einander verknüpft werden.
Dazu muss ein einheitlicher Massebezug hergestellt werden und den Spannungen jeweils ein eindeutiger Name gegeben werden.
Die Spannungsquellen werden mit ihrem „−“ Anschluss mit einem Masse-Symbol verbunden.
Der „+“ Anschluss wird jeweils mit einem kurzen Stück Leitung verbunden. Die Leitungen bleiben an ihrem anderen Ende offen.
Jeder Leitung wird dann ein eigener Name gegeben. In unserem Beispiel heißen die beiden Spannungen „sine“ und „ramp“.
Jetzt fehlt nur noch die Verknüpfung der beiden Spannungen zu einer PWM.
Dazu verwenden wir eine so genannte „arbitrary behavioural voltage source“, grob übersetzt „eine Spannungsquelle mit programmierbarem Verhalten“. Diese Spannungsquellen geben eine Spannung aus, die über Formeln und Funktionen beschreibbar ist.
Für unseren Zweck reicht eine einfache IF-Funktion: Wenn der Wert der Sinusspannung höher als der Wert der Dreieck-Spannung ist, soll eine Spannung ausgegeben werden. Wenn der Wert kleiner ist, soll 0 ausgegeben werden.
In unserem Beispiel wählen wir 5 Volt als den Spitzenwert der PWM.
Damit das Ganze funktioniert muss auch diese Spannungsquelle mit Masse und einer Signalleitung verbunden werden.
Damit die PWM nicht so ganz allein für sich steht, ist am Ausgang der Spannungsquelle noch ein einfaches RC-Tiefpassfilter angeschlossen.
Im letzten Bild sind als Ergebnis die unterschiedlichen Spannungen zu sehen.
- Rot: die Sinus-Spannung,
- Blau: die Dreieck-Spannung,
- Grün: die PWM und
- Gelb: die Spannung aus der PWM nach dem RC-Tiefpass
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 ?