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

Modeling a switch in LTspice

Discussion in 'Circuit Simulation & PCB Design' started by carbonzit, Aug 5, 2011.

  1. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    Sometimes it seems the simplest things are the hardest to deal with ...

    I'd like to model this circuit in LTspice:

    [​IMG]

    In order to test it, I need to be able to "throw" the switches. How do I do that? For instance, I'll run the simulation for one second, and I want to throw the "set" switch half a second after starting.

    I'm guessing this falls under the heading of "behavioral" circuit elements, but I have no clue as to how to implement it. Any (hopefully) simple way of doing this?
     
  2. Mikebits

    Mikebits Well-Known Member

    Joined:
    May 24, 2008
    Messages:
    6,214
    Likes:
    174
    Location:
    San Diego, Ca
    ONLINE
    I use voltage controlled switch. See asc file for example.
     

    Attached Files:

  3. Mikebits

    Mikebits Well-Known Member

    Joined:
    May 24, 2008
    Messages:
    6,214
    Likes:
    174
    Location:
    San Diego, Ca
    ONLINE
    Here is a switch model I found on the net. Have not used it, but I am sure it will work.
     

    Attached Files:

    • 1P3T.ZIP
      File size:
      671 bytes
      Views:
      1,917
  4. dave

    Dave New Member

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


     
  5. Mikebits

    Mikebits Well-Known Member

    Joined:
    May 24, 2008
    Messages:
    6,214
    Likes:
    174
    Location:
    San Diego, Ca
    ONLINE

    Oh, I see what your asking. Right click the switch in LTspice, in the component attribute editor in the value box you can set switch to on/off eg. value SW1 On
    For real time control, I dunno.
     
  6. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    No, actually your first idea what what I needed, something that can be automagically switched during the simulation. I tried it and it works fine. Thanks.

    Pretty clunky to implement on the schematic, though. What I'd really like would be a SPICE subcircuit, called "switch" that just appears on the schematic as a single 2-terminal component and which I can set to close (or open) at some specified time. I hate having to include all those stray .model directives and such on a nice neat schematic. So I'll play around with this. (Any advice how to do this appreciated.)
     
  7. simonbramble

    simonbramble Active Member

    Joined:
    Nov 22, 2010
    Messages:
    430
    Likes:
    63
    I have designed a switch circuit that I have stored in a file called 'switch'. I then just copy and paste it into any circuit I need. Yes it is a pain to implement everytime. Alternatively, you can do the same above with MOSFETs - one of the internal models in LTSpice. The ON resistance is so low, it can be assumed to be as good as a switch. Control it with a Pulse voltage source. I use a MOSFET when I can get away with it purely for simplicity
     
  8. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,592
    Likes:
    477
    Location:
    L.A., USA Zulu -8
    Electronic Workbench from Multisim has a simple switch that can be controlled from a keyboard key while the simulation is running, which is very handy. Unfortunately LTspice does not seem to support such a feature.
     
  9. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    Yes, it is. But I believe LTspice gives you all the "hooks" one needs in order to implement this in a neat package that could actually be chosen from the "component" menu, by building a .subckt and attaching it to an .asy symbol. Anyone know enough about this program to tell us how to do that?
     
  10. simonbramble

    simonbramble Active Member

    Joined:
    Nov 22, 2010
    Messages:
    430
    Likes:
    63
    Hmmm. I've had a think about this... How would making it into a subckt make it any simpler? You still need a switch input and output and I/O to provide a drive signal to activate the switch. The only thing you can simplify is the ON resistance. Regardless you would still need a .subckt command to specify it, so you might as well import your own library part... Attached is the file I use if it helps (just remove V1)
     

    Attached Files:

  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,178
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi simon
    I also use a 'master' asc on which I have common components with their includes. Arranged such that they can be copied and pasted in a couple of seconds, to a new asc file.

    I would say that its important that the components used should be kept as standard as possible if its intended that the asc files be shared with other LTS users.
     
  12. Mikebits

    Mikebits Well-Known Member

    Joined:
    May 24, 2008
    Messages:
    6,214
    Likes:
    174
    Location:
    San Diego, Ca
    ONLINE
    Eric, that sounds really handy.
     
  13. simonbramble

    simonbramble Active Member

    Joined:
    Nov 22, 2010
    Messages:
    430
    Likes:
    63
    You can always open up 2 schematics - one with the library part (switch.asc) and one with the schematic you are editing, then use <F6> to copy from one to the other. it is clunky, but I use this every time
     

Share This Page