Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Ltspice voltage controlled PWM

Status
Not open for further replies.

Sceadwian

Banned
Using spice I need to control the duty cycle of a PWM source at a fixed frequency from 0 to 100% with a scaleable voltage source, can anyone help with the ideal components and layout required?
 
OK, If I understand you correctly, this should work. I put in a ramp for the control signal to test it. You can change the frequency of the triangle wave by changing parameter "F". The comparator is the SW element, along with the 100k resistor.
Below is the .ASC file. Copy and paste it into Notepad and save it to the SWCADIII directory (or wherever you put your sim files) as PWM.asc (or whatever.asc). You will have to open the program AFTER you save the file.
Code:
Version 4
SHEET 1 880 680
WIRE 160 48 -160 48
WIRE -160 80 -160 48
WIRE 160 80 160 48
WIRE 448 128 320 128
WIRE 320 160 320 128
WIRE -160 176 -160 160
WIRE 160 176 160 160
WIRE 272 176 160 176
WIRE 160 208 160 176
WIRE -32 224 -160 224
WIRE 112 224 -32 224
WIRE 112 272 32 272
WIRE 272 272 272 224
WIRE 320 272 320 240
WIRE -160 304 -160 224
WIRE 32 304 32 272
WIRE 160 336 160 288
WIRE -160 400 -160 384
WIRE 32 400 32 384
FLAG 160 336 0
FLAG 32 400 0
FLAG -160 400 0
FLAG -160 176 0
FLAG 320 272 0
FLAG 272 272 0
FLAG 448 128 out
FLAG -32 224 ctrl
SYMBOL sw 160 304 M180
SYMATTR InstName S2
SYMATTR Value comp
SYMBOL res 144 64 R0
SYMATTR InstName R1
SYMATTR Value 100k
SYMBOL voltage 32 288 R0
WINDOW 3 -31 147 Left 0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName Vtriangle
SYMATTR Value PULSE({Vlow} {Vhigh} 0 {Tr} {Tr} 0 {2*Tr})
SYMBOL voltage -160 288 R0
WINDOW 3 -80 149 Left 0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName Vctrl
SYMATTR Value PWL(0 0 100u 5)
SYMBOL battery -160 64 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName Vcc
SYMATTR Value 5
SYMBOL e 320 144 R0
SYMATTR InstName E1
SYMATTR Value 1
TEXT -56 528 Left 0 !.model comp sw (ron=10 Roff=1e8 Vt=0 Vh=0.1)
TEXT -56 560 Left 0 !.param F=100k Tr={0.5/F} Vlow=0.1 Vhigh=4.9
TEXT -58 604 Left 0 !.tran 0 100u 0 10n
Hope it works for you!

Ron
 

Attachments

  • PWM.PNG
    PWM.PNG
    12.2 KB · Views: 6,696
Exactly what I was looking for, thanks tonnes Ron.
 
Nice work. I did some simplification, now uses only 3 components - added bonus: better rise times.
1588424038908.png
 

Attachments

  • pwm_generator.asc
    1.1 KB · Views: 415
Status
Not open for further replies.

Latest threads

Back
Top