Solved

Electronics calculations using C

Posted on 1997-12-11
4
195 Views
Last Modified: 2010-04-02
 I am looking for an appropriate data-structure to represent and calculate the values of electronic components that connected (wired) in a circuit.
Questions:
 - How do I resolve data storage for components that have  many values (transistors) and for components that have a  only a few (resistors, capacitors, yet don't end up with a dozen different "typedef struct"?
 - How do I represent nodes -e.g. wires - connecting each  components, since the components are
 - not limited only to 2 nodes (transistors has 3 nodes)
 - not limited to 2 wires (from a node any number of wires can origin)

  If you have no idea, please answer these:
 - Is it the problem that I am thinking too pictorically, and problems of this nature should be derived into equations and solved algebrically?
 - Wouldn't be better to use C++ and create classes of components to pass data between components to simulate voltage/current/resistance values through the circuit?
 - Am I have gone nuts?
0
Comment
Question by:sany
  • 2
4 Comments
 
LVL 3

Expert Comment

by:rmichels
ID: 1256620
I would much rather use C++ as a solution.  You can create electronic objects that have their behavior programmed in. Each component would have relationships to other components (representing the connections).



 I don't remember enuf about electronics though to give you much further advice though..
0
 
LVL 10

Accepted Solution

by:
rbr earned 200 total points
ID: 1256621
Use a dynamic Structure.

struct element {
    unsigned node_anz;
    struct **ppnodes;
... + any other info you need
}
/* Create a new element
 * Returnvalue is pointer to the element */

struct element *create_new_element(int node_anz)
{
     struct element *p;
     p=(struct element*)calloc (sizeof(struct element),1);
     p->node_anz = node_anz;
     p->ppnodes = (struct element **)calloc (sizeof(struct element *),p->node_anz);
       return (p);
}
/* Connect to elements at node1 of first element p1 and at node2
 * of second element p2 */
void connect_elements (struct element *p1, struct element *p2,
                       unsigned node1, unsigned node2)
{
   if ((node1 < p1->node_anz) && (node2 < p2->node_anz)) {
        p1->ppnodes[node1]=p2;
        p2->ppnodes[node2]=p1;
   }
}

0
 
LVL 10

Expert Comment

by:rbr
ID: 1256622
If you need wires this is just a dummy element which as many nodes as you need.
0
 

Author Comment

by:sany
ID: 1256623
A linked list provides only a partial solution, and I'll still end up with all those struct for different components. Traveling a list even more difficult, but this is the only solution I have found so far, and have to consider...
Thanks -san
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question