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

LTspice frustration: voltage-controlled switch

Discussion in 'Circuit Simulation & PCB Design' started by carbonzit, May 17, 2011.

  1. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    Failing to find a model for a momentary-contact pushbutton switch, I tried to see if I could use LTspice's voltage-controlled switch. (See attached .asc file.) I failed.

    Problems:

    1. The VCS seems to be undefined when plopped down in my circuit. When I try to run the simulation LTspice complains that it "Can't find definition of model "SW". Select OK to continue the simulation with the default model or Cancel to quit now." OK, fair enough; I click OK.

    It runs, but I get an error message:

    Error on line 2 : s1 n003 n001 n002 0 sw
    Unable to find definition of model "sw"
    WARNING: Node N002 is floating.

    Per .tran options, skipping operating point for transient analysis.


    I'm puzzled about node 2: why does it say it's "floating"? Because it's got a capacitor connected to the input of a DC device? When I plot the voltage I get a flat line at 12 volts; shouldn't I see an exponentially-decaying voltage through C1?

    Color me confused.
     

    Attached Files:

    • vc sw.asc
      File size:
      715 bytes
      Views:
      1,354
  2. ronsimpson

    ronsimpson Well-Known Member Most Helpful Member

    Joined:
    Apr 17, 2007
    Messages:
    7,253
    Likes:
    961
    Location:
    Loveland, CO USA
    .model SW1 SW(Ron=10 Roff=10Meg Vt=1.1 Vh=0.1)
    You need some think like above.
    Ron is resistance when on 10 ohms.
    Roff is resistance when open 10 mega ohms.
    Use help on switch. You may have to add a resistor from the cap to ground so the input has a DC path to some supply. (gnd)
     
  3. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    OK, thanks. So where does the . model directive go: on the drawing sheet? (See further complaint below.)

    And why would I need a DC path to ground? that's not a path to a supply.

    Complaint: It seems a lot of stuff gets done by sticking dot commands onto the drawing sheet itself. I don't like this. Very messy.

    How does one do things like this so that all this messy stuff goes into a file somewhere? I wouldn't mind having an .include or two if it meant cleaning up this other crap.

    ----------------------------------------------------------------------------------------

    Attached is a new circuit. Sure 'nuff, placing a resistor to ground removed the "floating node" warning.

    Still complaining about no definition for SW, and the results (also posted) are screwy.

    ??????????
     

    Attached Files:

    Last edited: May 17, 2011
  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,253
    Likes:
    961
    Location:
    Loveland, CO USA

    "OK, thanks. So where does the . model directive go: on the drawing sheet?" Yes, push the .op button.
    I may have many different switches in a desing. With many .SW commands.
    A normally open switch and a normally closed switch only differ on the Ron and Roff resistance.
    You can set the on/off levels and the gain, etc.
    Many interesting functions can be made with a switch.

    When I started with spice:
    R1, 1, 2, 100ohms Resistor from net 1 to 2.
    C1, 2, 3, 100e-12 Cap from net 2 to 3.
    No pictures.
    The output was tables of numbers that needed to be plotted by hand.
    V1 10.095 I1 3.97
    10.878 3.78
    10.2 4.8
     

    Attached Files:

  6. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    I still don't get it.

    OK, when I open the attributes dialog (the "Component Attribute Editor") for my voltage-controlled switch, I see these attributes:

    • Prefix: S
    • InstName: S1
    • SpiceModel: SW
    • Value: sw1 (my name???)
    • Value2: <blank>
    • SpiceLine: <blank>
    • SpiceLine2: <blank>

    Prefix I get, that's Spice's letter assignment. InstName is the name of this instance.

    How do I connect the name on my .model directive to these attributes? What is "SpiceModel"? SW? Is Value where I put my name (the same name in the .model directive)?

    Nothing in the manual makes this clear at all. It's as if you have to be born knowing this stuff.

    By the way, I appreciate your comment on how things were in the Olden Days. But that doesn't make this any less frustrating, since nowadays we expect things like WYSIWYG interfaces, smart apps and the like.
     
  7. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    carbonzit, it's Spice, don't hate the makers of the software you're using, it's how the system is designed to work. LTSpice is NOT for people unfamiliar with spice, much to the same horror as you're going through I've had to claw my way through some nasty stuff and I'm still only half assed at it.

    Take a look in the help file at the General Attributes Editor, and possible look around the net for general spice netlist syntax.

    All the graphics and fluff you see are just that, fluff. The core of what is going on is the netlist itself, which is nothing more than a custom proprietary mathematical programming language designed around it's usefulness for circuit simulation.
     
  8. ronsimpson

    ronsimpson Well-Known Member Most Helpful Member

    Joined:
    Apr 17, 2007
    Messages:
    7,253
    Likes:
    961
    Location:
    Loveland, CO USA
    CARBONZIT,

    There are names like R1, R2, R3. In this case S1, S2, S3.
    For resistors you can set R=1k, or you can set R1=Rx, R2=Rx and then declare Rx=1k. This is done when you want to have 100 resistors with the same value then change all the values to a slightly different number to see what happens.
    For your switch S1 it can have a value of SW1.
    .model SW1 SW(Ron=10 Roff=10Meg Vt=1.1 Vh=0.1).
    So all switches that have a value of SW1 will act alike, and have the values of;SWITCH Ron=10 Roff=10Meg Vt=1.1 Vh=0.1
    If you are using only one switch this probably does not make sence. If you are using 20 switches and many different types then it works very well. See my example.
    See help on voltage switch!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    You want a on/off switch. I want a opamp, voltage comparitor, amp with gain, Buffer, inverter, with/without Hysteresis, current limit, delay, etc.
    You can make a oscillator with a Vswitch + cap + resistor.
    One of fun parts of spice is you can make up parts that do not exist. Voltage controlled current source with time. I can make a part that is a formula having many inputs, time, frequency, voltage, temp., current, etc and outputs almost anything.
     
  9. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    I think I got it.

    It runs. Now I'd like to find out why the results are so screwy. Or at least not at all what I expect.

    Current .asc file and output plot below. I'm measuring at the + input to the voltage-controlled switch. Why do I get this wave, which rises from 24pV to 24.02PV and then stays there? Shouldn't I be seeing a sharply-rising voltage to close to 12V through C1, followed by an exponential decline? What am I missing here?

    Also, when defining a switch, isn't there a way to make the Roff as close to infinity as possible (like "infinity minus one")?
     

    Attached Files:

  10. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    Well, I got it to work, all by my little 'ol self. The key was telling it to skip the initial operating point solution ("uic"f on the .tran statement). Now I get the trace I'm expecting (I changed the cap to 1 µF).

    I'd still like to know how to define a switch like a proper switch (~infinite R when open).
     

    Attached Files:

    Last edited: May 17, 2011
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,181
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Cz,
    I have noticed you are very critical of other OP Wanabees when they start asking questions that can be easily answered by reading the datasheet or manual, BUT you are doing exactly the same.

    In order to help Newbees/Wanabees like yourself, who cannot be bothered to read the manual, User groups are formed, JOIN the Yahoo LTspice user group and read thru the documentation.

    Its the only sensible way of trying learn a subject, all you are doing at the moment is a 'pick and mix' which will just cause you grief and frustration...:)
     
    • Like Like x 1
  12. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    Well, with all due respect, I have read the manual (the LTspice manual from Linear Technologies). Not the entire manual, of course. But in my defense, it's not very helpful.

    Sure, it's chock-full of information. It explains most, if not all, of the dot commands and model parameters.

    But it does not explain, in simple, clear language, how to use the program. (And I'm not just talking about the GUI aspects of the simulator, but the Spice core.) It does not explain the relationship between model parameters and other circuit specifications. It does not explain why one should or should not use the "uic" option, which as I discovered has a major effect on results.

    If you know of a good manual, tutorial or other document that explains this stuff (and which isn't just a stupid PowerPoint presentation that shows in agonizing detail how to construct a simple circuit), I'm all ears. I do want to learn how to use this tool properly.

    Regarding my criticisms of LTspice as pointed out by other respondents, don't get me wrong; I've got nothing against this application (especially considering that it's free!). It's not the software I have problems with: it's the documentation (or lack thereof). Having been a technical writer in a previous lifetime, I think I know whereof I speak in this regard.
     
  13. ronv

    ronv Well-Known Member Most Helpful Member

    Joined:
    May 30, 2010
    Messages:
    4,725
    Likes:
    488
    Location:
    Tucson, AZ. USA
     
  14. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    Thanks, Ron! Very nice. I've saved that as a PDF for future reference.

    I actually put some .subs into the main LTspice folder (LTspiceIV\lib\sub, instead of creating a "new" folder as you did.

    I'm still confused, though, about the exact relationship between subcircuit (.sub) files, model (.mod) files, and .asy files. It seems that LTspice doesn't recognize a part until you create a specific .asy file for it; is that correct? In other words, if you import a model for, say, a NPN transistor, it's not enough to put that file (.sub or .mod) into the right folder; you also have to create a xxxx.asy file for it.

    And what's the functional difference between .models and .subckts? I notice that some op amps are defined as one and some as the other. It seems rather arbitrary, though I'm sure that's just because of my ignorance.

    I have found a few places where one can find lots of Spice models for components; apparently, there's a ton of them out there. A lot of vendors have files for their products.
     
  15. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    carbonzit, you want a clear and concise owners manual to life and/or knowledge? Spice is nothing more than glimpse into the reality.
     
  16. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    OK, if you say so ... <raises eyebrows>
     
  17. ronv

    ronv Well-Known Member Most Helpful Member

    Joined:
    May 30, 2010
    Messages:
    4,725
    Likes:
    488
    Location:
    Tucson, AZ. USA
    I could be wrong, but if I am someone will correct me. I think .mod and .sub files are the same. The .sub file I look at as the functional parameters of the part. The .asm file is the symbol (picture) of the part. The names for a single part must match and be in the same directory so it can find both.
     
  18. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    I think I've figured it out. Even if you have a model or a subcircuit (.mod or .sub) file, LTspice doesn't let you pick the component from its list in the Select Component Symbol dialog until you add an assembly (.asy) file for that part. In fact, the title of the dialog ought to be a tip-off: it only displays existing symbols (assemblies). I believe this to be correct, unless told otherwise by someone who knows differently.

    There are of course lots of differences between models and subcircuits; however, you're partly correct, in that they have the same function in the program.
     
  19. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,592
    Likes:
    477
    Location:
    L.A., USA Zulu -8
    CZ, perhaps a tutorial such as this would help in your basic understanding of SPICE syntax. There are also numerous books on SPICE, although I am not familiar as to which may be best for your purposes. And there are a number of LTspice tutorials available. Have you looked at any of those?

    There are better and easier to use SPICE programs than LTspice but none are free, of course. I've used Electronic Workbench (part of Multisim) for many years and it's very intuitive and easy to use.

    But if you want to use a free program such as LTspice, then you have to tolerate it's quirks and the limited manual/instructions that come with it.
     

Share This Page