simulation of a RLC circuits source code

Jan 04, 2008 8 Replies

Hi



Does anyone know of some code or a program that I can use to simulate a really simple RLC circuit (2 network). I know that I can use one of the freely available programs to do this, but I want to be able change the input voltage arbitrarily with my own code using feedback from the output of my circuit.



It seems like spice variants cannot do this, and I do not know how to create the differential equations to write my own code.


What r-l-c topology did you have in mind? It's not hard to program the incremental difference equations.

But Spice program can do most anything.

John

I need to do something like this:

[Input]-|-[coil]-----|-----[output] | | | | [cap] | | | | -------|-------------- | [ground]

I hope this is readable.

No resistor?

OK, assume a time step DT.

FOR T = 1 TO 1/DT

IL = IL + (Vin-Vout) * DT / L

Vout = Vout + IL * DT / C

NEXT

That's it. It simulates 1 second of real time, in steps of DT. Set DT small enough that things don't change a lot in each pass through the loop.

John

Oops, make that first line

Hi

Wow that is great, is there a textbook somewhere that covers this technique?

How would it change if I add a resistor?

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

This is just crude time-incremental expression for the way the parts behave. And it uses "rectangular integration", the simplest way to express the dynamics. More sophisticated algorithms converge better for larger DT's in more complex circuits.

John

John....BASIC? How TRS-80 of you!

(Surely you know indents are four spaces, anyway... ;o)

Tim

-- Deep Fryer: A very philosophical monk. Website @

formatting link

PowerBasic, actually.

Tabs are 8 spaces, as the goddess Teletype intended.

John

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required