• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Electronics calculations using C

 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
sany
Asked:
sany
  • 2
1 Solution
 
rmichelsCommented:
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
 
rbrCommented:
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
 
rbrCommented:
If you need wires this is just a dummy element which as many nodes as you need.
0
 
sanyAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now