Maker Pro
Maker Pro

OT? Volt/Amp/Watt fundamentals (and simulator issues).

BGB

Nov 30, 2014
154
Joined
Nov 30, 2014
Messages
154
in my electronics-simulator sub-project, stuff seemed to be ok when it only had wires.
I could make wires, and short things between Vcc and Gnd, and saw plausible looking voltage drops and amperage values.

then went and added resistors, which sort of work, but a bit of problem emerges:
current values are not really all that consistent.

for example, there is *less* current reported flowing through resistors than through the wires connected to the resistors, ... (resistor says 0.01A, wires say 0.2A).


I am not actually sure I am even approaching things correctly.
as-is, the simulation is driven internally almost entirely off voltages.

yes, in reality, there are volts, amps, watts, ... but my thoughts end up going in circles, and it seems like "volts" is the more fundamental property, and amps is based mostly on a voltage difference and on ohms and time. the amps mostly seem to essentially fall out of the calculations, leaving it mostly a matter of volts, ohms, and time (but, then straightforward application of ohm's law is no longer really doable, as mostly one is calculating amps merely to do something with it).

for example, ohms law seems good for describing the circuits, but problems start popping up when trying to apply it to a simulation.


for example, as one side of the circuit tries to pull the voltage down, the other side tries to push it back up again (so, 1 volt over 1 ohm per second, aka, the amp). but, then, voltages end up taking an unreasonably long time to propagate across resistors, and trying to make this faster seems to increase instability and significantly increases the amount of current "leaked" across the resistor (hence the wires seemingly reporting a higher current-flow than the resistors, and the voltage drops in the wires and similar seemingly implying a much lower resistance in the resistors).

similarly, it takes a bit much from the CPU to try to run the tick loop much higher than 10kHz (tried 100kHz, but then it started lagging pretty bad). but, it also seems a bit questionable that it should take 1000s of iterations for a voltage to make it across a resistor.

as a result of all this, the amps values diverge from sanity, and general intuition would imply watts as a more fundamental property, except there doesn't seem to be any real way to calculate everything else simply knowing the watts value at each point (seemingly, you need either volts or amps).

or, at least, it would be good if all the amperage values added up and there was a more consistent current reported from different locations in the same circuit.

a case could be made for amps as the fundamental value, but then things like batteries would no longer make sense, and the math doesn't really seem to hold up so well.

I don't necessarily need high precision, but answers "in the general area of being correct" would be nice.


it seems like I may be missing something fairly fundamental in all this...


in other notes: I got my "alternator converted into a motor" to turn (albeit slowly and very weakly) while running off of a variable/lab power supply. disturbingly, the MOSFETs seemed to get very hot at only a few amps, and I am not sure what to make of this (or if I can actually run them safely at higher power levels, but they are 30A MOSFETs and in other tests could run 5A with very little heat). I also have doubts about the flyback diodes (I observed notable heating in these diodes, and around 3 amps of flyback current, despite only seeing around 0.4v across the phase coils). in contrast, I had around 1.5v across the field coil.

nevermind, in an earlier test, the field-coil had managed to blow-up a TIP127, but I mostly fixed this issue with some external flyback diodes.


thoughts?...
 

Attachments

  • wiresim0.png
    wiresim0.png
    40 KB · Views: 142

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,727
Joined
Nov 17, 2011
Messages
13,727
it seems like "volts" is the more fundamental property
Imho a question of taste. Some prefer to see a current through a resistor as a consequence of the voltage applied, others see the voltage as a result of the current flowing through the resistor. I belong to the first group (and i justify this by looking at various power supplies like batteries, mains etc. where we can measure voltage without current but not vice versa). Mathematically it doesn't matter at all since by V=R*I both quantities are linearly related.

Do I get this right: You're building a circuit simulator (similar to e.g. SPICE) in software yourself as part of a project?

As long as you use only linear elements, this is rather straightforward: set up Kirchhoff's equations for all nodes and solve the resulting system of linear equations. If you have time-variant sources (e.g. an AC voltage source), do this for each timestep.

If you have non-linear elements, you need to find the operating point for each timestep, linearize the characteristic of the component and again solve the system of linear equations for this timestep.

If you have elements with "memory" (e.g. capacitors, inductors), the behavior of the circuit will at each timestep depend on the previous computations (as e.g. the voltage across a capacitor depends on the prior charging and discharging). This is expressed by differential equations and you need to solve them numerically. Have a look at the SPICE code and descriptions for more detailed information how this can be done rather effectively.
 

BGB

Nov 30, 2014
154
Joined
Nov 30, 2014
Messages
154
Imho a question of taste. Some prefer to see a current through a resistor as a consequence of the voltage applied, others see the voltage as a result of the current flowing through the resistor. I belong to the first group (and i justify this by looking at various power supplies like batteries, mains etc. where we can measure voltage without current but not vice versa). Mathematically it doesn't matter at all since by V=R*I both quantities are linearly related.

yeah.

though, voltage by itself makes more sense in many cases.

say you have a battery:
you have a certain voltage at the terminals, and for sake of simplicity can be assumed to be constant (and/or, we can assume a fixed-voltage difference with an implicit series resistor);
the amperage depends almost entirely on the load.

if you had a constant current source, then the voltage on the terminals in the case of an open would either tend towards infinity, or randomly become 0v (if current became 0), so implicitly such a battery would need an internal leakage resistor and a certain minimum current, in addition to dynamically changing the current value to maintain the target voltage.

voltage seems just a little more sane here, and more directly reflects normal circuit behavior.


Do I get this right: You're building a circuit simulator (similar to e.g. SPICE) in software yourself as part of a project?

... sort of ...

unlike SPICE, I am using a grid-cell based design rather than a point-to-point netlist, and each cell updates itself on a timestep in real-time (rather than in an offline process). so, basically, an interactive real-time simulation is the goal (rather than being strictly accurate).

at present, cells only directly interact with adjacent cells, but there is a plan to make some components depend on a "root" cell which implements the component's behavior, with the other cells existing more as terminals and/or no-op placeholders for rendering purposes.

as-is, resistors already use root cells in premise, though each grid cell in the resistor updates itself independently (it is basically exists as two modified "wire" cells and 3 "resistor" cells).

so, it is technically closer to being a 2D version of Minecraft's "redstone" system than it is to SPICE.


As long as you use only linear elements, this is rather straightforward: set up Kirchhoff's equations for all nodes and solve the resulting system of linear equations. If you have time-variant sources (e.g. an AC voltage source), do this for each timestep.

possibly, except as-is I am not actually using a solver.

as-is, each cell updates itself, and things like voltages and current propagate during each tick and then stabilize over a period of multiple ticks (they will tend to converge towards the answer).

things like wire cells mostly update themselves by looking at their edges, then recalculating based on the observed values and on their internal properties.

as-is, it works solely based off of voltages, but I may also make wires track and propagate amperage as this could help stabilize things better, and also probably eliminate some ugly kludges currently used in the math (and also make resistors a lot more responsive to changes as a result).

basically, as-is, components intentionally under-predict their values (pulling them towards their local center) in order to help voltages propagate across them.

if amperage values are also propagated, then voltages and amperage should be out of phase when the things are unstable, and then should converge towards a consistent output without the use of this kludge.


If you have non-linear elements, you need to find the operating point for each timestep, linearize the characteristic of the component and again solve the system of linear equations for this timestep.

my thinking for transistors is probably to make them behave like several resistors which dynamically update themselves based on their terminal values.

for example, for a BJT, Vbe will control Rce and Rbe.
a similar idea could be applied to MOSFETs and IGBTs.

the current-controlled behavior of the BJTs would then be mostly because of Rbe and feedback between Vbe and Rbe.


If you have elements with "memory" (e.g. capacitors, inductors), the behavior of the circuit will at each timestep depend on the previous computations (as e.g. the voltage across a capacitor depends on the prior charging and discharging). This is expressed by differential equations and you need to solve them numerically. Have a look at the SPICE code and descriptions for more detailed information how this can be done rather effectively.

I prefer to avoid differentials and integrators and similar as these tend to be a fairly expensive, and most things can be sufficiently approximated by a linear system if your time-step is small enough.


my thinking here would be that capacitors would likely keep track of their present charge voltage, and will know their Farad value and similar. they would then gradually update their terminals and charge and similar in response to the applied voltages.

inductors would be similar, just with amperage (they would only slowly update their amperage, and update their terminal voltages in accordance with their present amperage).


I had also considered possibly supporting motors, but these would likely be seriously hand-waved and fake.
 
Last edited:
Top