Resolving a DC circuit.

Discussion in 'Programmer's Corner' started by axl-cbgb, May 2, 2006.

  1. axl-cbgb

    Thread Starter New Member

    May 2, 2006
    3
    0
    hell o.

    i have to resolve a DC circuit composed of only resistors and voltage sources. and by that i mean find the values of the currents flowing through each branch. the grapical modelling and calculations must be done with the aid of a C code programme. the only difficult part is that i haven't the slightest idea how to do it!

    does anyone here have an idea? i mean writing a C/C++ programme that would allow me to graphically insert - with the aid of a keyboard and mouse - resistors and voltage sources in a circuit and then by using the circuit created, the programme itself would then calculate the values of the current in the branches? without me having to provide any data at all, just by using the graphical model of the circuit.

    for example, if i have drawn two resistors in parallel and a voltage source connected to them, the programme would already know what happens there and would return the values of the current, without me having to tell it what i have in the sketch.

    well...ideas, anyone? or at least an example on-line? because i couldn't find ANY. ohm and borland pascal is accepted also. i just need a starting point, an example that's already been solved or something..anything.
     
  2. skypher

    Member

    Apr 16, 2006
    16
    0
    First, try to develop a program that reads in a text file where your circuit is described and knows Kirchhoff's and Ohm's law.
    When this works, add a GUI with a nice toolkit, like Trolltech Qt and Gtk.
     
  3. axl-cbgb

    Thread Starter New Member

    May 2, 2006
    3
    0
    maybe i didn't express myself clearly. we have to use only the C language and nothing else. but still, nice idea with the text file. but i was thinking of a more complex and elaborate example, if anybody has one. like the actual source code for resolving dc circuits or something like that.
     
  4. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    3
    Well... I've worked with such thing before, but I don't think obtaining the actual source code is the best way to go for you. If you are interested in learning the approach on how to do this task, then I would gladly discuss it with you.

    BTW, what platform are you working on?
     
  5. axl-cbgb

    Thread Starter New Member

    May 2, 2006
    3
    0
    well, Windows XP Media Center Edition. but don't think of a super-project or something like that. just a simple, plain, 2D representation of a circuit which is then resolved using a loop current or a node voltage method. i know how to do the mathematical part but when it comes to putting the graphical form in mathematical language it all comes to an end. a sad end, actually. i really have no idea how to do it and i learn better on examples, and not on theory. that's why i asked for an example, if anybody has one.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    9,900
    1,723
    Processing a textfile as input was suggested for a very good reason. It is about the easiest way to process information into a data structure that represents a circuit. If you want to ask for advice and then ignore it, be my guest.

    BTW, LTSpice from Linear Technology, represents it's schematics as ASCII text files. You might want to download it, just to look at the format of the schematic file. If you take a small subset, or better yet adapt the format to your purposes, you will have taken a giant step toward the solution. As a side benefit you can check your results agains the SPICE simulator. It will give you all the information you need.

    On second thought here is a file with two resistors in parallel with a voltage source.

    [attachmentid=1409]

    Let me know what you think.
     
  7. chesart1

    Senior Member

    Jan 23, 2006
    269
    1
    Hi,

    I worked as a software engineer designing and modifying software applications. I have no experience with windows API. I also tried to learn windows programming by simply reading text and studying examples. So I'm speaking as a person with experience. Studying other programs is not enough. You need to gain experience designing software programs. This is an excellent exercise. It previews the responsibilities of a software engineer.

    I agree with Papabravo. The LTSPICE from linear technology is an excellent starting point. I've downloaded LTSPICE and have used it. Good documentation is provided with the free software. You can learn the portions of the LTSPICE syntax needed to perform your task. Once you understand LTSPICE, you can start thinking about a program that will read an LTSPICE text file and perform the calculations. Most important: Using LTSPICE will give you excellent insight into the software project you are starting.

    You wrote and I quote "writing a C/C++ programme that would allow me to graphically insert - with the aid of a keyboard and mouse - resistors and voltage sources in a circuit and then by using the circuit created, the programme itself would then calculate the values of the current in the branches? without me having to provide any data at all, just by using the graphical model of the circuit."

    Designing software that allows the user to draw a circuit is not a small task. In the 1990's, the old Borland C++ provided an easy way to enter graphics mode in a DOS environment. But that implementation may not be provided with the latest C++ compilers. DOS is fading in the background. The old DOS application is now called a Console application. Microsoft VC++ has little support for DOS graphics applications.

    I am a beginner at windows programming. If you have not programmed in C/C++ and are not familiar with the windows programming environment, then perhaps someone with experience could advise you on that topic.

    I heard that Visual Basic is a good starting point for learning Windows programming but I don't know if that is true in this case.

    John
     
  8. chesart1

    Senior Member

    Jan 23, 2006
    269
    1
    Hi,

    Before concluding that you cannot use an LTSPICE text file, read this message and download LTSPICE.

    Using the C language does not prevent you from creating a syntax for describing a circuit. You would not be using LTSPICE as a programming language. LTSPICE defines a syntax for describing a circuit in a text file. It provides your program with an easy method of visualizing a circuit. The C language would be used to read the LTSPICE text file, interpret it and perform all functions the software project requires.

    Using a text file is much easier than trying to analyse lines drawn on a screen. And if you have the user draw the circuit, you can create the text file while the user is drawing the circuit. Then you can use the textfile to determine what calculations your C program must perform.

    John
     
  9. Papabravo

    Expert

    Feb 24, 2006
    9,900
    1,723
    Thanks for the supportive comments. There are several additional points in this thread that I had not considered. After 30 years in the software business, I too gave up trying to write software for the windoze environment. Too much haslement and too much dinero for the tools. I much prefer the hardware business.
     
  10. Powermos

    New Member

    May 20, 2006
    3
    0
    Hi,

    I've written some years ago a simulator in C language able to solve power electronics circuit by discrete time modeling of the reactive elements (discretization of the constitutive element equation by the trapezoid rules, then a first order approximation of the derivative), the a PWL modeling for the reactive element and also for the circuit switch. In my approach, the circuit description was trough a input text file write like the PSpice .cir approach.
    With this approach I can also build for my simulator custom subcircuits like Flip-Flop or other elements. The simulation engine was based on the MNA approach, Modified Nodal Approach method and by using some matrix elaboration to solve the matrix every simulation stesp.
    The main difficult in settings this simulator was found a efficient way to collect and simulate the state variable for each element into the circuit. After some time my idea was to build a element vector which have to be scanned for the simulation. In other word, during the input file scanning I can build the nodal matrix for the circuits and also for each element I have to fill a vector of function pointer every pointer is related to a function with the purpose of keep the current element constitutive equation which I've to evaluate during the simulation step. Well, this may b e appear not clear at first, some year have passed :), but if you like I can give more info about how set a simple simulator, I've also some good reference to classical text book on numerical simulation of electronics circuit also where you can keep some basic knowledge about nodal approach and matrix computation.

    May be also useful keep in touch with this paper:

    C. W. Ho, A. E. Ruehli, and P. A. Brennan, "The modified nodal approach to network analysis," IEEE Trans. Circuits Syst., vol. CAS-22, pp. 504--509, Jan. 1975

    Link where you can download it:
    http://www-cse.ucsd.edu/classes/fa04/cse245/Reading/MNA.pdf

    Cheers
    Powermos
     
Loading...