simulation of a RLC circuits source code

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.

Reply to
Scott Ronald
Loading thread data ...

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

Reply to
John Larkin

I need to do something like this:

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

I hope this is readable.

Reply to
Scott Ronald

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

Reply to
John Larkin

Oops, make that first line

Reply to
John Larkin

Hi

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

How would it change if I add a resistor?

Reply to
Scott Ronald

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

Reply to
John Larkin

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

Reply to
Tim Williams

PowerBasic, actually.

Tabs are 8 spaces, as the goddess Teletype intended.

John

Reply to
John Larkin

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.