1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Real Time Analogue Circuit Simulation C++

Discussion in 'Circuit Simulation & PCB Design' started by NIDALAP, Jul 3, 2017.

  1. NIDALAP

    NIDALAP New Member

    Joined:
    Jul 3, 2017
    Messages:
    9
    Likes:
    1
    Hello! I'm wondering how would I go about creating a real time simulation of an analogue circuit in C++? I spent a couple of days searching google, but couldn't find anything. The only thing I've realised in that SPICE seems to be the go to in terms of circuit simulation. Question is, where can I get libraries for it and can it do real time simulation?
     
  2. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,139
    Likes:
    566
    Location:
    AZ 86334
    What do you mean by "real time"?
     
  3. NIDALAP

    NIDALAP New Member

    Joined:
    Jul 3, 2017
    Messages:
    9
    Likes:
    1
    Well, my understanding is that MATLAB for example, you create a model in simulink, then you specify the duration of the simulation and the result is all the data from t=0 to your specified time limit. This is a passive simulation. You let it run and it does so. What I'm after is a simulation where it's like having the physical circuit in your hands - so you can turn various components on and off, use various components thereby changing their power consumption etc... so basically I want to have a virtual model that you can play with.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ronsimpson

    ronsimpson Well-Known Member Most Helpful Member

    Joined:
    Apr 17, 2007
    Messages:
    7,370
    Likes:
    974
    Location:
    Loveland, CO USA

    What is wrong with using SPICE?
     
    • Like Like x 1
  6. NIDALAP

    NIDALAP New Member

    Joined:
    Jul 3, 2017
    Messages:
    9
    Likes:
    1
    Sounds like I'm not seeing something very obvious. This may sound obtuse, but I didn't find any info related to c++/c etc libraries to use SPICE in my program hence my question.
     
  7. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    470
    Likes:
    37
    can you be more specific - as it must be obvious - you can not simulate complex/fast/event-dense circuits in real time - what exactly you have to collate from your intended experiment
     
  8. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    There are numerous programmes that already do exactly what you want - and you don't want 'real time' - as it would be far too fast for you to see any results.
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    There will be.. BUT!! If I made a simulator in C++ to do all the stuff you want, I wouldn't post my code.. Proteus uses C++ to run all the spice models in their software.. If you subscribe you are given a C++ skeletal program to design your own models, you have to sign a waver saying that you will not disclose!! But! Yes there are C++ libraries..
     
  10. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,325
    Likes:
    1,231
    Location:
    Cardiff, Wales
  11. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,623
    Likes:
    479
    Location:
    L.A., USA Zulu -8
    It's not possible to simulate analog circuits in real time, unless it's a simple circuit and you happen to have a super computer at your disposal. :rolleyes:
     
  12. NIDALAP

    NIDALAP New Member

    Joined:
    Jul 3, 2017
    Messages:
    9
    Likes:
    1
    Well, I managed to find the SPICE library on the Berkeley website - go figure. Since spice is so old, I didn't even think of going straight to the source but it exists. The rest of your comments are not very endearing :). I'm not sure whether my circuit can be classified as big, so I guess I'll have a poke around and see whether I can get performance that I need out of it. First step is to figure my way around the library and figure out how to use it. That might take some time.
     
  13. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    470
    Likes:
    37
    that time may be 10-s of years or a few clicks if there's an example avail of similar to what you intend
     
  14. cowboybob

    cowboybob Well-Known Member Most Helpful Member

    Joined:
    Oct 22, 2011
    Messages:
    3,052
    Likes:
    479
    Location:
    James Island, SC
    Welcome to ETO, NIDALAP.
    What, exactly, is the analog circuit you wish to simulate and what sort of timing is involved?
     
  15. NIDALAP

    NIDALAP New Member

    Joined:
    Jul 3, 2017
    Messages:
    9
    Likes:
    1
    A simplified aircraft electrical circuit. By simplified I mean, I'll be approximating instruments by resistors, other than that, all the buses and all the switches need to be there. My biggest concern are the circuit breakers. I have over 300 of them, but they are simple switches so not sure how that's going to affect performance. All I'm doing is probing the circuit at every refresh cycle. I think maximum of 60hz. Whatever the values are is what they are. So having said all that, perhaps it's not as simple as I at first thought.
     
  16. ronsimpson

    ronsimpson Well-Known Member Most Helpful Member

    Joined:
    Apr 17, 2007
    Messages:
    7,370
    Likes:
    974
    Location:
    Loveland, CO USA
    Looks like you want to do this on a "PC".
    Search for "PC i/o board". You can get a plugin board that has up to 144 inputs/outputs.
    You can also get a USB I/O board. I used one with 32 inputs/outputs.
    This can take care of your 300 breakers.
    You can also scan the I/O like a keyboard encoder.

    Don't know what you are really doing but I think a DAC board will give a voltage output that can drive meters directly. (instruments)
    Many of these boards output 0 to 5 volts in 256 steps.

    Driving instruments might be hard. You can use a monitor and just put up a "picture" of an instrument and make the meter move in graphics.

    I have had some problems with a PC in real time. "60hz" Some times Windows just goes away for a period of time.
     
  17. NIDALAP

    NIDALAP New Member

    Joined:
    Jul 3, 2017
    Messages:
    9
    Likes:
    1
    Yep, interfacing the circuit breakers will need some sort of IO board, haven't figure out which one yet.

    It's for a flight simulator. Just trying to model the electrical system. Specifically, I was thinking along the lines of trying to figure out how much power consumption the electronics would be drawing for a realistic battery drain. But I think I might simplify and just turn everything off after a certain time limit instead. I think modeling the whole system the way I initially envisaged would be too arduous and the benefits would be marginal.
     

Share This Page