LTspice current injection - Page 1
Forum section: electronics / projects

author: Gaktyt
author_rank: Regular Contributor
timestamp: May 29, 2020, 02:29:08 pm
content: Hi,I made the following simulation in LTspice in an attempt to simulate current injection.I do not understand why the voltage DC level of the left circuit (with *2 current injected) is equal to the initial capacitor voltage but with opposite sign? Any thoughts on that would be appreciated.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 29, 2020, 04:31:40 pm
content: I've used '.ic' spice directives on LTSpice schematics, but never the individual "IC" parameter for a given component that you seem to be using. I haven't even seen how to set them in LTSpice. What version are you using?Also, why is B3 dependent on I(C2)?

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: May 29, 2020, 05:01:57 pm
content: Hi,Please add your .asc file to your post.When I run this model I get a similar result to what you are reporting.The reason for this is I rotated C2 180 degrees when I drew the schematic.If you look at the SPICE netlist you can see this:Code:C1 v_c1 0 1u IC=1C2 0 v_c2 1u IC=1R1 v_c1 0 1MegR2 v_c2 0 1Meg.tran 3 uic* Intial Conditions.backannoThe IC has a sign, it assumes that the first node is the positive node.C1 node_1 node_2 1u IC=1Means node_1 is 1V with respect to node_2It is the same for currents.Regards,Jay_Diddy_B

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 29, 2020, 05:38:11 pm
content: Quote from: Jay_Diddy_B on May 29, 2020, 05:01:57 pmI didn't know about this IC parameter and never used it.But given what it does, I think that's one more reason to stick to .ic directives.You'd add the following on the schematic instead:Code:.ic V(v_c1)=1 V(V_c2)=1Unambiguous and doesn't rely on any particular orientation of the parts (which I think is nasty.)

author: engrguy42
author_rank: Frequent Contributor
timestamp: May 29, 2020, 05:44:25 pm
content: Yeah, if you CTRL-RT CLICK on a capacitor, for example, you can set initial conditions by doing a "IC=0" on the SpiceLine. But it sucks that you have to do that. Who the hell thought that one up? They should all default to zero. Geesh. That messed me up just the other day doing a time controlled switch closing into a capacitor.

author: Gaktyt
author_rank: Regular Contributor
timestamp: May 29, 2020, 06:20:34 pm
content: Quote from: SiliconWizard on May 29, 2020, 04:31:40 pmXVII(x64)Quote from: SiliconWizard on May 29, 2020, 04:31:40 pmBecause otherwise I can not get it to converge, I guess due to the infinite feedback it would create if I used I(C1).Quote from: Jay_Diddy_B on May 29, 2020, 05:01:57 pmYes I see that, but I didn't rotate any capacitors according to my netlist (.asc file)Code:C1 v_c1 0 1.2n IC=100L1 0 N003 1µR3 N001 v_c1 14C2 v_c2 0 1.2n IC=100L3 0 N002 1µR1 N002 v_c2 14B3 N001 N003 I=-I(C2)*2.tran 1u* RLC circuit* Mirror circuit.backanno.endSo could could the difference in dc level have something to do with inductor BEMF?Quote from: SiliconWizard on May 29, 2020, 05:38:11 pmGreat tip, thank you.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: May 29, 2020, 06:58:46 pm
content: Hi,You get two different answers if you add 'uic' to the simulation statement..tran 1u uicIf you don't have UIC I(L1) starts at 7.14A which is 100V/14If you have UIC the inductor current I(L1) starts at 0.Regards,Jay_Diddy_B

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: May 29, 2020, 07:12:11 pm
content: Hi,Consider this model, it is a simpler version of your model:The capacitor current will flow in the circuit on the left till the capacitor is discharged to zero volts.In the circuit on the right the current is forced to be twice the circuit on the left so the capacitor on the right is charged to -100V then the current stops.Jay_Diddy_B

author: Gaktyt
author_rank: Regular Contributor
timestamp: May 29, 2020, 07:45:01 pm
content: Quote from: Jay_Diddy_B on May 29, 2020, 06:58:46 pmYes you are right because the initial conditions are different, so they yield different results.Why would you use the .uic directive instead of letting LTspice calculate/resolve the DC operating point?Quote from: Jay_Diddy_B on May 29, 2020, 07:12:11 pmYes it's simpler, but it is also a RC circuit, my circuit is a RLC circuit, so I would say they are different - not only simpler.But it makes me think, how do I put an initial condition on the inductor so that it starts at zero current? (I found out .IC I(L3)=0)

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 29, 2020, 10:36:23 pm
content: Quote from: Gaktyt on May 29, 2020, 07:45:01 pmAs you saw, LTSpice in particular and Spice in general need explicit initial conditions in somes cases. In particular, if you don't do so, initial voltage across capacitors (and current through inductors) is not guaranteed to be zero. And yes, it can be confusing.

author: Gaktyt
author_rank: Regular Contributor
timestamp: May 30, 2020, 07:57:14 am
content: Quote from: SiliconWizard on May 29, 2020, 10:36:23 pmYes I can understand that. But even with.ic I(L3)=0 I(L1)=0the DC voltage level of the left circuit (with *2 current injected) is still equal to the initial capacitor voltage but with opposite sign, and I still can't understand why/how it is so, and I would very much like to learn which mechanism in the circuit that is responsible. I'm still guessing it has something to do with inductor BEMF though.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: May 30, 2020, 11:18:34 am
content: Quote from: Gaktyt on May 30, 2020, 07:57:14 amThis is not really a SPICE or LTspic, it is an analog circuit design question.First you have to remember that a current source has infinite impedance. Obviously if the current is zero there is no movement of charge.SecondCV=ItIn the master circuit the capacitor is discharged from 100V to zero.In the controlled circuitthe current is doubleso the change in voltage is double.200V instead of 100Vsince you start at 100V and the current direction is negative you end up at -100V.Consider this model:A parameter called multiplier is being stepped through the values 1, 2 and 3These are the results:Thechangein voltage on C1 is equal to the change in voltage on C2 x the multiplier.Jay_Diddy_Bwith multiplier.asc(1.19 kB - downloaded 59 times.)

author: Gaktyt
author_rank: Regular Contributor
timestamp: May 30, 2020, 11:46:53 am
content: Quote from: Jay_Diddy_B on May 30, 2020, 11:18:34 amSorry about that, I was not sure what to call it.Quote from: Jay_Diddy_B on May 30, 2020, 11:18:34 amSo a "B" source in LTspice has infinite impedance? Does that infer e.g. if I hypothetically made the circuit and injected the current with a BCI probe I would not see the same result as in the simulation?Quote from: Jay_Diddy_B on May 30, 2020, 11:18:34 amCheck, got it, thank you very much for clearing that up for me.Quote from: Jay_Diddy_B on May 30, 2020, 11:18:34 amI'm sorry, I don't understand that part of negative current, I mean it do make sense to me, but it's negative in relation to what? I only put a (-) minus in front because otherwise the current wave form of the controlled circuit would be inverse, so my confusion is that in both circuits the current wave form is the same (except for amplitude obviously) but you talk about negative current? Could you please elaborate on that?

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: May 30, 2020, 12:10:15 pm
content: Hi,In SPICE a BI is a Behavioral current source. The current is described by an expression.It is not that it is behavioral or in SPICE, but any true current source has an infinite output impedance.Similarly any voltage source has zero impedance.Consider this:If you look at the current in R3 or L3 it is always equal to 1A. The current source I1 is forcing the current to be 1AThe voltage across the current source is equal in value and opposite in sign to all the other voltage is in the loop. This is Kirchhoff's voltage law.Current flow has direction. Take a rechargeable battery, during discharge you can say you have positive current, current is flowing out of the battery. During charging you have current flowing into the battery you can call this negative current.You have positive and negative currents, just like you have positive and negative voltages.Regards,Jay_Diddy_B

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 30, 2020, 02:47:52 pm
content: A related note regarding current sources in Spice.By default, they are ideal current sources. So the simulation will "force" the set current through the circuit, even if that would be physically impossible (in other words, it has no notion of voltage compliance). That can lead to very weird results in some cases.LTSpice has an interesting option for current sources: you can set them as "active loads". They will then act more or less as you would expect a current source in a real physical circuit.

author: SilverSolder
author_rank: Super Contributor
timestamp: May 30, 2020, 03:54:07 pm
content: Quote from: SiliconWizard on May 30, 2020, 02:47:52 pmInteresting, how do you do that? I don't see "Active Load" in Help

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: May 30, 2020, 03:59:16 pm
content: Hi,You check this box:Regards,Jay_Diddy_B

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: May 30, 2020, 04:06:09 pm
content: Hi,This is how it behaves:It is useful in modelling power supplies, because it doesn't pull the output negative.Regards,Jay_Diddy_B

author: Gaktyt
author_rank: Regular Contributor
timestamp: May 30, 2020, 04:46:43 pm
content: Quote from: Jay_Diddy_B on May 30, 2020, 12:10:15 pmYou say "forcing", could the current source be placed differently so that it "adds" current instead of "forcing"?Quote from: Jay_Diddy_B on May 30, 2020, 12:10:15 pmCheck, and thank you for making that clear to me, I appreciate it.I'm still not completely sure that I understand the voltage in the circuit because; after the current is zero the voltage remains -100V (current*2) forever, so I'm in doubt if -100V is the new 0V? And if it is the new 0V, then what is the initial capacitor voltage? or when in time does -100V become the new 0V? Or maybe I should make a new post for this question?

author: Gaktyt
author_rank: Regular Contributor
timestamp: May 30, 2020, 05:04:42 pm
content: Quote from: SiliconWizard on May 30, 2020, 02:47:52 pmThe Behavioral Current Source doesn't seem to have this option, or maybe it is set somewhere else?

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 30, 2020, 05:55:35 pm
content: Quote from: Gaktyt on May 30, 2020, 05:04:42 pmYes, it doesn't. It directly maps to a Spice 'B' source, whereas I suspect that the more basic current source is an improved model in LTSpice.So if you're using that, I guess the only way you can add that feature is to include it in the formula expressing the current. Read LTSpice's help on "Arbitrary Behavioral Voltage or Current Sources". You'll find out there's quite a lot you can use for expressing the current.