S
Scott Ronald
- Jan 1, 1970
- 0
Hi
To continue this discussion about simulation of incremental difference
equations, I was wondering how you could add a power source to the code
that John Larkin came up with.
I have been experimenting with this and I found that merely adding the
voltage like
//FOR T = 0 TO 1 STEP DT
// IL = IL + (Vin-Vout) * DT / L
// IR = Vout / R
// IC = IL - IR
// Vout = Vout + IC * DT / C +myVoltage
//NEXT
causes problems because the voltage accumulates in the Vout variable and
the voltage quickly goes very large. Do I need to subtract the previous
voltage before I add the new voltage like:
//FOR T = 0 TO 1 STEP DT
// IL = IL + (Vin-Vout) * DT / L
// IR = Vout / R
// IC = IL - IR
// Vout = Vout + IC * DT / C +myVoltage-lastvoltage
// lastvoltage = myVoltage
//NEXT
Would this be remotely accurate?
Here is the circuit I am looking at:
[Input]--[coil]---|-------|----[output]--|
| | | |
| [cap] [resistor] [voltage]
| | | |
|---------|-------|--------------|
|
[ground]
Scott
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.
To continue this discussion about simulation of incremental difference
equations, I was wondering how you could add a power source to the code
that John Larkin came up with.
I have been experimenting with this and I found that merely adding the
voltage like
//FOR T = 0 TO 1 STEP DT
// IL = IL + (Vin-Vout) * DT / L
// IR = Vout / R
// IC = IL - IR
// Vout = Vout + IC * DT / C +myVoltage
//NEXT
causes problems because the voltage accumulates in the Vout variable and
the voltage quickly goes very large. Do I need to subtract the previous
voltage before I add the new voltage like:
//FOR T = 0 TO 1 STEP DT
// IL = IL + (Vin-Vout) * DT / L
// IR = Vout / R
// IC = IL - IR
// Vout = Vout + IC * DT / C +myVoltage-lastvoltage
// lastvoltage = myVoltage
//NEXT
Would this be remotely accurate?
Here is the circuit I am looking at:
[Input]--[coil]---|-------|----[output]--|
| | | |
| [cap] [resistor] [voltage]
| | | |
|---------|-------|--------------|
|
[ground]
Scott
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.
HiIt 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
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]