# Trying to simulate a PWM model of a boost converter in gnucap

There's a paper called "Simplified Analysis of PWM Converters Using Model of PWM Switch (part 1)" by Vatché Vorpérian which introduces a "PWM switch" to model the switch and diode in a switching voltage converter.

I'm following along happily while he derives its properties and then he uses the model to get DC characteristics for a boost converter. This is where I started struggling, so I thought I'd try to simulate the thing in SPICE (well, Gnucap) to see if I could spot what I was doing wrong. This didn't help much...

Here's a circuit diagram (which is correct, since it appears pretty much verbatim in his paper):

D is the duty ratio. Here is the netlist I was trying to use to simulate things:

* Boost converter with PWM model

.parameter D=0.6
.parameter vg=10

.subckt tx p1 p2 s1 s2 PARAM: N=10
FP p1 p2 VS {1/N}
ES s1 int1 p1 p2 {N}
VS s2 int1 DC 0
RLnk s2 p2 1M
.ends tx

Vg 1 0 DC {vg}
Rp 1 2 0.1
X1 2 3 4 3 tx N={D}
Vdummy 4 0 DC 0

RL 3 0 1k

.print dc v(1) v(2) v(3) i(RL) i(Rp) i(Vdummy)
.dc


The results are rather unexpected!

* Boost converter with PWM model
#           v(1)       v(2)       v(3)       i(RL)      i(Rp)      i(Vdummy)
0.         10.        10.004    -15.006    -0.015006  -0.037514  -0.022508


Can anyone spot something I've done wrong? In particular, the current seems to be flowing the wrong way, which seems pretty bizarre. I tried out the tx transformer subcircuit and convinced myself it worked, but I may have made a mistake.

-
For anyone coming across this question: as Art pointed out below, I have the wrong gain for FP (should be N, not 1/N). Also, the transformer gain is the wrong way round: for a boost converter as written here, I needed 1/D instead of D (otherwise the voltage just gets inverted and current flows backwards in the secondary loop!) –  Rupert Swarbrick May 13 '12 at 8:00
sigh No, in fact I was still being stupid. I misread Art's comment (which was correct). Es should have had gain 1/N to simulate an N:1 turn ideal transformer. (And then D rather than 1/D is correct) –  Rupert Swarbrick May 13 '12 at 8:14

I think the gain of Es should be 1/N, not N, to correctly model the N:1 "DC transformer". (The "reverse" current transfer ratio should be the same as the "forward" voltage transfer ratio.)

Also, although it doesn't matter in this case, in the SPICEs I've seen, your RLnk=1M would be a 1 milliohm resistor short from p2 to s2; a value of 1MEG would give 1 megohm. (Maybe your program uses a different convention?)

-
Oops. Also, thanks for the catch about RLnk: I'd used 1G and then wasn't concentrating when I went back to (not quite) 1Meg. –  Rupert Swarbrick May 13 '12 at 7:26

Christophe Basso is somewhat of a PSpice guru when it comes to power supply modelling.

He wrote a tutorial paper for Intusoft that covers how to use the models.

It looks to me like you're not doing the full converter simulation - just the DC-equivalent circuit. The complete PWM switch model looks like this:

.SUBCKT SWITCH 1 2 3 4 {D=0.45 VAP=11 IC=0.8}
* A P C Control
B1 7 1 V = { V(4)*(VAP/D) }
B2 1 2 I = { V(4)*IC }
B3 7 2 I = { I(Vd)*D }
B4 9 2 V = { V(7,2)*D }
Vd 9 3 0
.ENDS

-
Ok, in fact I've looked at his tutorial and that's what lead me to the original papers - I was trying to understand where some of the theory came from. I know I've only got the DC-equivalent part, but this should still behave correctly on a DC simulation, no? –  Rupert Swarbrick May 11 '12 at 22:38