Simulating simple electric circuits

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Mon May 7 14:05:28 EDT 2007


Hello all,

I'm trying to simulate simple electric logic (asynchronous)
circuits. By "simple" I mean that I only want to know if I
have "current" or "no current" (it's quite digital) and the only
elements need to be (with some level of abstraction to my specific
problem)

- sources (here begin currents)
- ground (here end currents)
- joints
- switches (which are able to let current pass or not, depending on
  outside influence)
- loads (which can signal change in current flow to the outside --
  just like a light bulb)

Is there any library for this? I couldn't find one.

I tried to implement this using objects that are two-way linked;
every object has "ports". For every port, there is 

- an input function (that is called by the neighbour if "current"
comes in)
- a reference to the neighbour's input function, to be able to let
current flow the other way

There is a master "current controller" object which tells
the "source" object to start a "current" by calling its neighbour.
The calls traverse the network until they reach a "ground" object.
Specifically, the source passes a "telegram" instance with these
calls, and everyone it passes through "registers" himself with it
(telegrams are duplicated at joints). Then, the ground object calls
back to the controller with all received telegrams. Like this I'm
already able to get all possible ways through the network. 

But that's where my ideas go out. Let's assume there is a load in
the middle of such a current, e. g. a light bulb. So if the current
flows through it it gets notice of this because there is a telegram
passing through it. But what if a contact before it now "cuts" the
current, how could I notify all objects behind the cut? I tried
several ways the past few days, but all lead to confusing (and
non-working) code. (I'm sorry I can't provide any working code yet)
Often it boils down to the need to check all possible ways in the
entire network with every change. This shouldn't, in perfomance
terms, be a big problem for me here, but it feels very dirty, and I
smell inconsistencies.

Another way I thought of is

- to let load objects have a timer that resets their state to "no
  flow" after ~ 200 ms
- "pulse" the network every ~ 100 ms from all sources to ground
- and reset all load timers on the way.

This feels even more dirty.

There are several professional-grade simulation tools that track
many other parameters, how do they work in general, is there a
different strategy? I wonder if I'm making it too complicated or if
I'm seeing problems where there really aren't any. I also looked at
NetworkX, but I can't see how it might be of use yet. I appreciate
all suggestions.

Thanks for you consideration.

Regards,


Björn

P.S.: This is no homework, it's pure hobby ;)

-- 
BOFH excuse #70:

nesting roaches shorted out the ether cable




More information about the Python-list mailing list