Re: Simulating an RL circuit



On Wed, 05 Mar 2008 04:27:34 GMT, Scott Ronald <scottm361@xxxxxxxxx>
wrote:

Hi

I am trying to simulate a boost converter like this:


[Vin]-------[inductor]---|----------[diode]----|-------[output]
| | |
| [control]--[mosfet] [capacitor]
| | |
|----------------------|---------------------|


So I was thinking of splitting into 2 sections: one for the on state and
one for the off-state.




On State:
[Vin]-------[inductor]-----|---------------------|------------|
| | | |
| / [capacitor] [Load]
| / | |
|------------------------|---------------------|------------|


I can use this algorithm for the on state ( I got it here from John Larkin)

FOR T = 0 TO 1 STEP DT
IL = IL + (Vin-Vout) * DT / L
IR = Vout / R
IC = IL - IR
Vout = Vout + IC * DT / C
NEXT


So now I just need to do the off state.

Off state:

[Vin]-------[inductor+inductorResistance]-----|
| |
| |
|-------------------------------------------|

where the inductor charges for the time the switch is closed. What I
need to figure out is the voltage at top of the load/cap is the moment
the switch is opened. The only way i know how to do this is use the
exponential charging function.Vf=Vi(1-e^[-t/T]) Can anyone here write
the fancy algorithm like above that makes it more efficient for code?

I would love to see a text or something on how to write my own code like
this, anyone know of one?

Scott

There's no "fancy algorithm" involved. For a time interval dt,

for a resistor,

I = E / R



for an inductor,

I2 = I1 + E * dt / L for an inductor, where
I2 = new current, I1 = previous current

and for a capacitor,

V2 = V1 + I * dt / C



And the rest is algebra.

This is simplistic rectangular integration. There are better ways to
do it, but this isn't real bad if you keep dt small.


It's interesting to play with stuff like this. I used to simulate
steamship control systems like this [1], drive train and hull dynamics
included, first on an HP 9100 programmable calculator, then on a PDP-8
running FOCAL. But once you get a feel for the basics, and the
mathematical pathologies [2], you may as well cut over to LT Spice.


John

[1] Most big ships are direct-drive diesels these days. Steam plants
can be very efficient, but are complex and hard to maintain at sea.

[2] Almost anything, like a parallel RC, can be made to oscillate if
you pump up dt. You can do that in Spice, too.


.


Quantcast