PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2] 3

Author Topic: resistance is futile  (Read 1392 times)

Eddy Van Esch

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 237
  • FF3 User
    • DevOTechS
Re: resistance is futile
« Reply #15 on: March 16, 2017, 06:38:18 PM »

Here it is.
Let's look at the circuit in the picture.
We see a number of components (resistors and voltage sources in this case) that are connected together.
The points where a number of components (1 or more) are tied together, we call 'nodes'.
In this pic, they are colored blue. We see nodes 11, 1, 2, 22 and 0.

When a circuit is 'stable' or 'in balance', following node criteria are fulfilled:
a) A node can only have one voltage, so all pins of the components connected to this node have the same voltage.
b) Every node obeys Kirchhoff's first law: The sum of the incoming currents equals the sum of the outgoing currents. Logical, because a node can't

'store' current.

Okay, we are going to focus on the voltages of the various nodes.
Regarding to voltages, we have 2 different types of nodes:
- Nodes with a fixed voltage
- Nodes with a 'self-balancing' voltage.

In our case, nodes 11, 22 and 0 are fixed voltage:
* Node 0  = 0 V (could be another voltage though... It is all relative)
* Node 11 = +10 V
* Node 22 = -4 V

That leaves nodes 1 and 2 to be self-balancing. They will adjust themselves so that the whole system is in balance.
If we can determine these 'stable' voltages on these nodes, we have the system completely defined and can calculate every current.

How can we determine these stable voltages?

We start with a completely fresh or unstable system. For example, the voltage on every 'self balancing' node can be 0 V.
We leave the 'fixed voltage nodes' alone. Nothing to be done there.
We are going to iterate through the self-balancing nodes. That means, we are going to do the balancing ...
How are we going to do that?
By simply working with our node criteria.
- We optimise (vary) the node voltage to try and fulfill Kirchhoff's law.
You will increase or decrease the voltage to make the sum of all the node currents as small as possible.
Now, during the first iterations, we will not be able to get the sum of the currents to zero, because the system is still much too unbalanced.
Instead, we will settle for making the error minimal. So the (absolute) sum of the currents in the node has to be minimal.
When we have found this (currently) optimal voltage we will go to the next self-balancing node and do the same.
- Keep doing this over and over again until you notice that the voltages do not change anymore. That's when you have a stable system and you have all the currents and voltages solved.

In this system, you can use voltage sources and current sources.
You can also include the time component for C (capacitors) and L (coils).
Logged
Eddy

raymw

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 64
Re: resistance is futile
« Reply #16 on: March 16, 2017, 07:10:59 PM »

Maybe a bit too soon, but I've put some answers below to the three circuits, and hopefully an explanation as how to get there.

I mentioned that assumptions have to be made, - here's a few - where nodes are joined to a solid line (a busbar) then the voltage at each such connected node will be the same. The sum of currents entering and leaving a node/busbar is zero. All power supplies are of infinite capacity, and are completely stable. Any measuring equipment does not impact on the components being tested.

The series one. The total resistance of the 3ohm and 2ohm resistors is 5ohms (for series resistors you sum the individual resistors). From V=I*R , the current through each one is 10/5 = 2 Amp, since 10V is applied across the terminals of that equivalent resistor. The voltage at the bottom terminal of the 5 ohm resistor is maybe a bit of a puzzle, but as that resistor does not have a potential difference across its terminals (the bottom terminal is not connected to anything), no current flows through that resistor, so the voltage will be the same as that at the connected end, in this case 0V.

The parallel circuit. We have 10 - 2 volts (8V) applied across the terminals of the 5 ohm resistor, so the current through that will be 8/5 Amp, or 1.6A . Since the bottom terminal of the 2 ohm resistor is not connected, the voltage there will be the same as at the connected end, and will be 10V.

Now for the headache just for the sake of it, I guess.

By inspection, it can be seen that there are a number of series connected and // connected resistors, so we can simplify the circuit to fewer resistors. So, doing the series ones first- from top left, the 2 + 3 become 5 ohm, below them the 4 + 5 become 9ohm. Now, what about that 21 ohm one in the middle? Well, both terminals of that resistor are connected to the same node, the resistor is 'shorted out', it will carry no current, since each terminal is at the same voltage, so it can be removed from the circuit. We can now see which of the resistors form parallel circuits, and combine them, ending up with four resistance values only. So first, the top row of resistors, the new 5 with the 17 and 6 ohm are equivalent to 1/((1/5)+(1/17)+(1/6)) = 1/(0.2+0.059 +0.167) = 1/(0.426) = 2.347 ohms, and the second, for the bottom pair the new 9 and the 2 become 1/((1/9)+ (1/2)) = 1/(0.111+0.500) = 1.637 ohms but this still has in parallel, the right hand 4 and 8 ohm, which we can not simplify because between the 4 and 8 is a 4.5V supply point. If you are interested, redraw it and recalculate.

It can be simplified, wrt the voltage calculations, if we add 9V to each voltage, (and remember to subtract 9V at he end), thus the top voltage becomes 18V, the bottom 0V, and that between the 4 and 8 ohm resistors, 13.5V. Now, we can see that across the terminals of the bottom right 8ohm resistor is 13.5V, giving a current through the 8 ohm resistor of 1.688A. The same current must also flow through the connected 4 ohm resistor, since it is connected in series to the 8 ohm, and there is no other resistor connected. Therefore we can calculate the voltage asked for, since the voltage across the 4 ohm must be 4*1.688 = 6.752V, giving the voltage at V? of 6.75 + 13.5 = 20.25V (-9V) = 11.25 V.  **BANG** -This is clearly wrong, since the maximum voltage in the circuit can not be more than 9V. Where is the error? Well, the node between the 4 and 8 ohm resistor is connected to a 4.5V power supply, and that feed may source or sink current, so although the two resistors are connected in series, the fact that there is a power connection at that node, although it is still true that the sum of currents at a node equals zero, i.e. what goes in must go out, we have no idea as to the current flow from the power supply. Hence we can't say, from the calculations so far, that the current through the 8 ohm resistor will be the same as through the 4 ohm. You will have this problem, wherever there is more than one power feed, in many cases. More generally, interfaces are always a problem, from sea shores to usb connectors/whatever.

What to do? Well, the manual way would be to use some theorem, by Kirchoff, Thevenin, Maxwell, whoever, but we could also have a guess. Our first guess will be most likely wrong, but with a bit of skill and luck, after a few iterations, and applying a suitable algorithm we can get near enough. We can test our guessing, by using a spread sheet, say, but any solution using manual means will need a new set up each time the resistor values change, or more awkwardly if the circuit layout changes. 

So, in guessing/iterating/monte-carlo, whatever you want to call it, the first guess is perhaps the tricky part, and then we make sure that subsequent guesses head towards the solution, and not away from it. we can check our guessing, by verifying against the two rules we have. Given that we know the resistance values, the supply voltages and connections, first- the current at each node must sum to zero, second the voltage across each resistor is equal to the current * resistance.

Are we having fun yet?
Logged

Barry Gordon

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 21
Re: resistance is futile
« Reply #17 on: March 16, 2017, 08:48:44 PM »

Crikey - this has taken me back a bit. 

I think I still have one of those identical IBM plastic template somewhere - and I even have a mechanical (yes mechanical) Hexadecimal calculator.

I vaguely remember when I started in computing a long long long ... long while ago - there was a program called the IBM Electronic Circuit Analysis Program (ECAP) - which did what it says on the tin (even if electronics was a bit cruder in those days).   I never actually used it - but I notice that if you do a Google search for 'IBM ECAP' it comes up with some info and a few references to methodology.

I don't if this is of any help - but its worth mentioning in case it is.

Barry
Logged

raymw

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 64
Re: resistance is futile
« Reply #18 on: March 16, 2017, 10:05:11 PM »

Eddy's post crossed with mine, and has explained, probably more clearly, the same method of calculating the voltages, etc. as  I will be attempting to repeat in ff/fb, so hopefully we can now leave the fundamental description of the problem, and progress towards an ood based solution, or at least my attempt at one... If there is something not explained too well, or you just do not understand then ask.  In no way am I suggesting that the proposed solution is ideal, but hopefully it is interesting, and the principles can be adapted to other problems. By selecting a decent design, then we can experiment with other solutions, perhaps by training a neural net, or similar. One thing to remember, is that the 'real world' is analogue, and we are working digitally, but even digital is analogue, or worse, depending on your viewpoint.  (its a bit late over here for such philosophical thoughts, maybe.)

Best Wishes,
Ray
Logged

David Warner

  • FireFly3 Registered User
  • Junior FireFly Member
  • *
  • Posts: 110
Re: resistance is futile
« Reply #19 on: March 17, 2017, 01:48:28 AM »

...its a bit late over here...

Or (also depending on your viewpoint) a bit early. Either way, it's the night-owl or the early bird that catches the worm. :)

Your photo post also made me dig around to find my old IBM flowchart stencil. It's identical to yours and I was given it nearly thirty years ago. I haven't used it for years but it seeing it again brought back happy memories of documenting my COBOL data manipulation code with it.


Logged

raymw

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 64
Re: resistance is futile
« Reply #20 on: March 17, 2017, 05:18:22 AM »

I never did commercial/business oriented language. Initially it was a few variants of IBM Formula Translation, then a tad of Programming Language 1 (I think that's more or less the correct acronyms) wrt the flow chart template I noticed on mine I'd 'snowpaked' a corner and written on it 'this way up'. Must have been pulled up for producing erroneous looking printout symbols/whatever...iirc, the total cost of a program was guesstimated to be about £5.00 per fortran statement.
Logged

Eddy Van Esch

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 237
  • FF3 User
    • DevOTechS
Re: resistance is futile
« Reply #21 on: March 17, 2017, 11:34:02 AM »

I don't want to spoil anybody's fun. Just make my iteration algorithm more clear.
I have attached an Excel file that defines the shown resistor network.
By changing the 2 node voltages (in the yellow cells) until the error values (the green cells) are as close to zero as possible, you can solve this network.
You can also use Excels Solver add-in for this.

Can't directly attach the Excel file, so download here:
https://apps.memopal.com/e/24H9FJASWM


Logged
Eddy

raymw

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 64
Re: resistance is futile
« Reply #22 on: March 19, 2017, 11:45:14 AM »

Something has gone wrong... There's actually a smidgen of code in here (which may be of no use whatsoever)...

Let’s consider the problem by trying  to identify objects. Not too difficult in this case. Objects are usually nouns, and so far I’ve talked about resistors, power supplies, nodes, terminals, bus-bars, amps, ohms, volts, current and other items. Not all of these are necessarily objects, but it can depend on the view point we want to take. For example, earlier I mentioned that a node in this electrical example, could be considered as being similar to a branch of a bank, and cash flow equivalent to current. If we were doing a high level accountancy summary for the whole banking corporation, then we may not be interested in whether the cash flow consisted of credit transfers, cheques or hard currency. However, if we needed to also use the data as a means of calculating the frequency of the cash delivery vans, or knowing how many new coins would be required, then maybe it would be worth while looking at the detail of the ‘cash object’ to include a few more attributes, other than merely its value, and direction of flow (debit/credit). Deciding on the granularity of the system, in the real world, can require a fair amount of effort.

As this simple resistor problem is merely a test piece, then I can decide on my own level of detail, and by isolating the calculations and fundamental attributes from the I/O it becomes fairly easy to make later changes.

I’ve decided, for the moment that there are only three main objects – the circuit, resistors, power supplies. If it is decided to add other components, such as inductors, capacitors, diodes, etc., then they will most likely be ‘sort of’ resistors, but it should be straightforward to include them later.

Now, unless at more or less absolute zero, or by other means of obtaining superconductivity, most electrical components exhibit some resistance to electrical current. Electricity power lines, house wiring, etc., but for the sake of simplicity, I’ve decided to base this problem on the sort of resistor that is used in electronic circuits, purchased from Farnell/wherever. This is so that I can possibly add in a few other attributes, to demonstrate what happens if a resistor is overloaded, or has a wider tolerance than perhaps was originally specified. If we proceed to perhaps producing a suitable printed circuit board layout, then physical dimensions may be needed too, so I’ve  defined our resistor object/class/type whatever we call it, as shown in the attached fb code.
Code: [Select]
    Type   Resistor
      Public:
     
          id as String*8
          resistance as Double
          Rating as Double
          VA as Double     ' voltage at A terminal
          VB as Double     ' voltage at B terminal
          CurrentAB  as Double      'current A to B
          PowerLoss as Double    ' =I*I*R
          Size as Double  ' distance in mm 'twixt terminals A & B
          material as String*8  ' type - ceramic, ww, etc
          overloaded as boolean  ' if current exceeded, set to true
          Declare Sub current() 
          Declare Sub voltage()
         Declare Sub calc_overloaded()
      End Type
       
       
       
'--------------------------------------------------------------------------------
      Sub resistor.current()
       this.currentAB = this.resistance/(this.va - this.vb)
   
      End Sub
       
' --------------------------------------------------------------------------------
     Sub resistor.voltage()
      this.voltage = this.resistance * this.currentab
      Return this.voltage
     
      End Function
     
'----------------------------------------------------------------------------------
     Sub resistor.calc_overloaded ()
      If this.currentab > this.rating Then
          this.overloaded=True
        Else
          this.overloaded = False
      End If
       
      End Sub
'--------------------------------------------------------------------------------
 
I’m hoping that the free basic ‘type’ can be used in a similar way as a class, and we can create new instances from it. If not, then we’ll most likely be able to find some work around. I’ve shown the required calculations that each resistor needs to make, as subroutines. The power supply object has not yet been defined. By adopting the mvc paradigm, I do not need to be too concerned at the level of detail required for the model at this stage, it merely puts down a marker so that other aspects of the program can be studied.

Now, the resistors and power supplies are  connected together at nodes on the circuit. I’m assuming that these nodes are some standard connector that matches the terminals of the resistors and power supplies, so no need to specify if solder pads, dil, screw terminals, whatever. If we needed that level of detail, then within the circuit object, I would probably add that attribute, and check that the type of node matched the type of component terminal.

The proposed circuit object will be basically a list of nodes, with associated connected component terminals. Examining the circuit diagrams, we see that for each node, there is no more than four terminals connected. In practice, there could be many more, but in the diagrams we show that by drawing in solid lines, representing bus-bars. So, I have to make a choice, in how to describe these node and terminals connections.

If the number of terminals associated with a node is unlimited, as it would be in the original circuit that the schematic diagram represents, then for each node, there will be an attached unknown length  list of terminals, and if we are working from a schematic diagram, then some interpretation will need to take place, it is not a case of simply looking at the diagram, and making a node for each ‘blob’. The schematic diagram represents a single node with a multitude of connections by a number of nodes and connecting bus-bars. If we decide to represent the schematic diagram, but not the physical network it represents, it will be easier to annotate the diagram with the calculated results, and we can restrict the list of terminals attached to a node to no more than four, but we need to add a bus-bar component.

A bus-bar can be considered as a resistor with a resistance value of zero, and the voltage at each end is always equal. I could either set up a resistor instance as a bus-bar, when needed, or create another bus-bar object.  However, I imagine a bus-bar as being perhaps a part of a node, or more realistically as a connection between nodes. At the moment, my preferred method is, for each node to have up to four associated terminals, any or all of which may or may not be a bus-bar, or other component.

I’m now trying to decide on ‘the best way’ of storing this detail within the circuit object, whether to have say, an intermediate ‘node object’ or just a linked list/whatever. Maybe have a particular terminal for a resistor specified by a comma separated string, e.g. r5,t1 or store the whole node connections as comma separated strings, e.g.  r2t1,r3t2,pt2 or have attached to each node, separate variables for each component type and terminal number.

 
Logged

TechSupport

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 7913
  • Windows 10
    • PlanetSquires Software
Re: resistance is futile
« Reply #23 on: March 21, 2017, 02:36:39 PM »

Hi Ray, I am only now getting to look at your post. There a few changes I'd make to the class but I will post them once I get a better opportunity to analyze the situation.  :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

raymw

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 64
Re: resistance is futile
« Reply #24 on: March 22, 2017, 01:44:48 PM »

There’s no rush, Paul, plenty of other stuff to think about, but it would be nice to mock up a bit of code to prove the possibility of creating new instances of a class, and to be able to iterate through them. This is possible in firefly, using forms and a list of hwnd’s, as you answered in one of my previous questions on this forum, but it needs to be done in the model, whereas the form is a view – at least in my way of thinking.

Concerning the circuit model, I think that will be just a linked list of nodes, and connections to each node. There has to be a simple way of manually putting that information into the model, working from a schematic diagram, a method that preferably uses no manual calculation or interpretation. Perhaps a few rules have to be obeyed. If we label each node with an integer, then we will not need to store a list of node names, and if the nodes are numbered sequentially, then it will simplify it even more. If we define that each resistor terminal must have a number or letter, unique to that resistor, and that each resistor name is unique, then a terminal can be r111, or res5a, whatever, and the terminal can be extracted as the last character of the string – e.g. resistor r11, terminal 1 and resistor res5, terminal a in previous example. Some neat data entry verification could take place – check that for each resistor the terminal numbers are different, that each resistor name in the list of terminals only appears twice, say. The model has to be an accurate representation of reality, else we will get an answer to a question that has not been asked, when we run the calculations.

If we make another rule, such that a power supply terminal is entered as a number followed by V, e.g. -5.6V, 0V, then we can note that the node number to which that is listed, will have all terminals connected to that node as having a fixed voltage at the numeric value (e.g. -5.6, or 0 Volt in the examples). 

Initially, I’m thinking I will use windows forms for data entry and display. Although it could make sense to treat each node as an instance of a node class within the circuit, I’ve a feeling that the screen would get cluttered, and it may be better to just have a single form with a list box to enter in a comma delimited string on each line, to represent the terminals on each Node. I’ve not decided anything yet, but whatever method of data entry is used, it will not (or should not) effect the underlying model.

I can’t remember the detail of my previous solution from 20 years ago, and do not want to look it up, but the next consideration, is finding a suitable way of deciding the initial values before carrying out the iterations around the circuit. One method, would be to set the current through each resistor, to one amp, say. This may take a few more iterations before we arrived at a more stable solution, compared to making some other guess. I’m thinking we should be able to make some better guess. Perhaps if we assumed all the resistors were in series, and the software calculated the current if we assumed the maximum voltage was applied across the equivalent terminals, or perhaps we considered the resistors in parallel, possibly we do both calculations, and take the mean current. Initially, whatever we decide on, we can terminate the calculation iterations when the voltage differences at the connected terminals is less than 1%, or after 20 iterations, for example, then decide later. The controller part of the mvc, is where those arguments take place.
Logged

raymw

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 64
Re: resistance is futile
« Reply #25 on: March 27, 2017, 12:24:14 PM »

Having thought a bit more on how to initially enter values into the circuit model, I’ve decided on a form, shown in the screen grab. If I need more than 16 nodes, then I’ll open another form. For proving the concept 16 nodes should be adequate. I found it a bit tricky lining up the textboxes – an ‘undo’ option would be useful… The method I used, to get them arranged in a grid was to create a row of 6 boxes, name them , remove the initial ‘text1’, then copy and paste the row a number of times down the form. Had to make the form  well oversize, since the pasting was not too precise. Anyway, I then aligned the bottom row, then column by column equally spaced the boxes, and shrunk the form to suit. I will have forgotten this before I need it again. I expect there is most likely some neater way, but this worked well enough.

I intend only using ff as a means of entering data to the model (and presenting the results) I could equally as well have simply used the dos window and ignored firefly completely. Whichever method is used for the view, then the controller chooses.
Logged

TechSupport

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 7913
  • Windows 10
    • PlanetSquires Software
Re: resistance is futile
« Reply #26 on: March 28, 2017, 04:36:34 PM »

Hi Ray, such a form cries out for an editable grid of some sort. Too bad that we don't really have one that works in FF/FB. Another idea would be to make a scrollable form because I imagine that your data entry screen must be very large and may exceed the screen real estate of some users. Jose has posted examples of scrolling forms using his CWindow class. Also on your resister form, it looks like in a couple of cases that the control heights for your labels may be a little large because they are bleeding into the border of the textboxes underneath them.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

raymw

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 64
Re: resistance is futile
« Reply #27 on: March 28, 2017, 07:07:11 PM »

Yes, agreed on all counts. It would be nice, if also we could have a text box with integrated label. I think it would be useful in many cases, but sometimes you'd need to have a longer label/whatever. wrt the grid, I was considering writing a single row, in ff, then editing the generated form code (copy and paste with a few calculations). It could be done as a separate program. (in c#, M$ comments chunks of the form code saying 'do not alter this code' - guess who goes in and alters it? I vaguely remember I made a form generator for quick basic - typed the text I wanted to be shown on the 80 column screen, with values like xxx.xx for the position to enter values. It was then parsed and the correct basic input statements generated (possibly before your time, and most likely not on your side of the pond, but there was a piece of software, hyped up for a year before release, named 'The Last One' (TLO). It was a software generation system, and was meant to be the last software anyone would need to buy... innovative at the time.)

edited to add -1981 -  TLO wiki link https://en.wikipedia.org/wiki/The_Last_One_%28software%29  I still have the original documentation, floppies, and some example code, somewhere, fwiw
« Last Edit: March 28, 2017, 09:11:59 PM by raymw »
Logged

raymw

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 64
Re: resistance is futile
« Reply #28 on: April 07, 2017, 06:55:25 AM »

I've not had much time to continue with this, as quickly as I would have liked. It's suddenly got to be Spring over here, and outside stuff calls. I will probably 'cheat' by not using oop for the resistors, maybe store their details in lists within the circuit, instead of creating individual instances of the resistor object. By separating the view from the model, it allows either to be readily changed at any stage, so I/you can  alter it later on, if we feel like doing so. In the same way, it will be relatively easy to add in other components, diodes, caps, inductors, etc., or change the calculation to something other than using monte-carlo, to perhaps a small trained neural net. (I've a reasonable document on using c# and neural nets which possibly could be plagiarised)
Logged

TechSupport

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 7913
  • Windows 10
    • PlanetSquires Software
Re: resistance is futile
« Reply #29 on: April 07, 2017, 09:20:59 AM »

I wish it was spring here. We just finished two late winter snow storms! Ugh! Sorry I haven't been much help on this project, mostly because engineering topics are not my specialty and my interest them is marginal at best :)

Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor
Pages: 1 [2] 3