Maker Pro
Maker Pro

simulation of a RLC circuits source code

S

Scott Ronald

Jan 1, 1970
0
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.
 
J

John Larkin

Jan 1, 1970
0
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
 
S

Scott Ronald

Jan 1, 1970
0
John said:
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.
 
J

John Larkin

Jan 1, 1970
0
John said:
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
 
J

John Larkin

Jan 1, 1970
0
John said:
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.


Oops, make that first line
 
S

Scott Ronald

Jan 1, 1970
0
John said:
John Larkin wrote:
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.


Oops, make that first line
FOR T = 0 TO 1 STEP DT

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

Vout = Vout + IL * DT / C

NEXT
Hi

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

How would it change if I add a resistor?

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

John Larkin

Jan 1, 1970
0
John said:
John Larkin wrote:
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.


Oops, make that first line
FOR T = 0 TO 1 STEP DT

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

Vout = Vout + IL * DT / C

NEXT
Hi

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

How would it change if I add a resistor?

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


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
 
T

Tim Williams

Jan 1, 1970
0
John Larkin said:
FOR T = 1 TO 1 / DT
IL = IL + (Vin - Vout) * DT / L
Vout = Vout + IL * DT / C
NEXT

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

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

Tim
 
Top