Having had Paul’s approval, I’ve decided to document on here the steps involved in my latest project, since as I’m a newbie on here, I’ll always being asking for your help, and thought you may as well understand where I’m try to go with freebasic and firefly. This may involve more than the usual sparse background discussion, but that is one of the advantages of a forum such as this, I think. I no longer write software for others, but find it to be interesting, and a reasonably safe mental exercise.

So, some background.

20 years or so ago, I decided to get a software related qualification. At that time I was involved with OS2, and I decided to use IBM visual Age Smalltalk, to devise what I thought was a unique method for solving current flow in a network of resistors. There were other methods around at that time, but I wanted to demonstrate the application of object oriented design and programming. I had considerable help from a couple of folk at IBM, and was told it would take a year for me to unplug my brain, and plug it in sideways to get into the oo way of thinking. They were right, in what they said. 30 years before that, I was operating, for a few months, a large network analyser, a sort of network simulator/analogue computer, programmed by plugging leads, and setting values by dials, analysing current flow in cable networks for an electricity supply company – any calculations were undertaken by using a slide rule.

If you don’t understand electrickery, there are only a few basic principles you’ll need to know. The first is to learn a bit of Latin – Vir – which translates to ‘man’, as I recall from my school days.

It is just one short step to then remember that V=I*R where V is volts, I is current, and R is resistance. This is a fundamental principle in any electrical calculation for a direct current system. (For alternating current, other characteristics come into play, such as inductance and capacitance, but we can go into that later, if necessary, but let’s keep it simple.)

So, VIR is stating, that for any resistor, the current flowing through the resistor depends on it’s resistance value, and the potential difference (voltage) at it’s two terminals. The units are Volts, Amps and ohms. There are standard values for these, and the standards change every few years, voltage used to be standardised to a particular type of chemical primary cell, and current, iirc depended on the force exerted by a current flowing through a conductor, but you can find more precise definitions, most likely on the ‘iso standards ‘pages, but for the purpose of my puzzle, V=I*R is all that is needed.

Now, it is not often that a circuit consists of just one resistor, but it is relatively easy, for simple networks consisting of say, half a dozen resistors, to calculate the current flow through each resistor and the voltages, given the supply points and the supply voltage. For each resistor in series (that is connected end to end, in a long string), the total resistance is the sum of all the individual resistances, the circuit then behaves as one resistance from the point of view in calculating the current, which will be the same for each resistor. For resistors in parallel, the sums are bit more complex, in as much as 1/rt = 1/r1 +1/r2 +1/r3 +1/r… where rt is the total resistance value, and r1, r2, etc are the individual resistances. Are you with me so far? There are plenty of references on the web referring to series // connections, but just concern yourself with the basic V=I*R.

However, in a complex network, back then, with maybe 50 or so resistors, connected in any fashion, it was necessary to manually go through the various branches at each node, and simplify the network by converting the sub-nets into series and parallel connections, until you had one equivalent resistance value, and then if the supply point moved, you had to go through the whole thing again – hence the use of the network analyser. This machine filled a room, and it would take a week to set it up (but it was an analyser for ac currents, so somewhat more complex.) Other than that, you would attempt, by inspection, to reduce the circuit to a stage such that you could apply rules, such as those devised by Maxwell, Kirchoff or Thevenin. Generally you would get the answer wrong, more often than right, and the best guess in three seemed to be most popular.

So, having spent six months or so, trying at different analogies , water flowing through pipes, crowd management, herding sheep, fishing (all of which are similar problems) I decided to analyse the fundamentals of what was actually happening in electrical circuits, at almost a molecular level, but I then threw out all those ideas, and decided to go back to guessing, in a sort of more controlled way.

So, breaking the problem down, the fundamentals become fairly simple. We have three types of components – a resistor, a power supply and a circuit. We needn’t constrict ourself to any specifics, but a single circuit can consist of any number of resistors and any number of power supplies, connected in any way you like. These connection points we can call nodes, and they are not part of the resistors or power supplies, but are, if you like, the circuit.

We can connect the resistor terminals to nodes in the circuit, and connect the power supplies to any nodes. The problem becomes how to calculate the voltage at each node, and the current flow through each resistor.

All we know is the value of each resistor, the voltage at the power supply terminals, and the circuit nodes to which they are connected. We also know that the current through the resistor depends on the voltage across it’s terminals and its resistance value, and the voltage across the terminals depends on the current through the resistor, and its resistance – chicken and egg, which comes first – hence my explorations at the molecular level. We also know, that for each circuit node, since we can not have more than one voltage at each node (since we assume it is a perfect connection – well you have to assume some things to get started), that the sum of currents flowing into any given node equals the sum of currents leaving said node. If you can’t visualise this, think of folk arriving at a railway station, say (Not Southern in UK) folk arrive and depart, but at the end of the day, hopefully they’ve all cancelled each other out – the station is the circuit node.

Hopefully you have an idea of the problem, if not I’ll have to sort out some way of showing it in a diagrammatic form.

It is useful to be able to separate the calculation side of things from the data I/O, and if we can apply the model view controller paradigm (MVC), once we have really drilled down to the essential nub of the problem, we can more readily add different user interfaces, including the usual windows form type of interface, or more graphical representation of the resistors (including the colour coding if you really enjoy this sort of fun) which will mean getting into fb graphics, I guess.

I’m sorry if it appears that I am a bit inebriated in the exuberance of my own verbosity, but you can get your own back by explaining in great detail the succinct coding that hopefully you will be writing for this.

(to be continued)