1
\$\begingroup\$

Below is my schematic for a relay SPDT symbol I’m creating. I've posted this question in the Digikey forums, but I am not sure they actually answer LTSpice questions

Relay-SPDT

You may notice I’m not yet very proficient with LTSpice. Getting past that, You’ll notice the spice directive on the top right corner. What I’m trying to do is this:

  1. Regardless of what voltage POS is, V4 = 5 unless POS=<0

:: Here I thought the expression u(POS) * 5 would work because u() returns 0 or 1 depending if the parameter is 0 or > 0

  1. Since it is SPDT both electronic switches (ADG1201) have the same input COM1 but each has a different Output. The switch turns on when Mom = 5. So U1[In] =0 and U2[In]=5 when Mom = 5. Also, U1[In]=5 and U2[In]=0 when Mom=0

:: Here I tried to modify the expressions with the .func statement along with If statements.

In my test Circuit, the Spice Error log reads:

Questionable use of curly braces in “v4 n004 0 {z}”
Error: undefined symbol in: “[z]”
Questionable use of curly braces in “v5 n006 0 {y}”
Error: undefined symbol in: “[y]”
Questionable use of curly braces in “v6 n005 0 {x}”
Error: undefined symbol in: “”
Questionable use of curly braces in “v4 0 {fnvoltmod(v(pos))}”
Error: undefined symbol in: “(if((v)>0,z=u((v(pos)))*5))”
Questionable use of curly braces in “v5 0 {fndecy(mom)}”
Error: undefined symbol in: “(if(([mom])>0,y=0,y=5))”
Questionable use of curly braces in “v6 0 {fndecx(mom)}”
Error: undefined symbol in: “(if(([mom])>0,x=5,x=0))”
Fatal Error: Multiple instances of “V:x1:4”

How do I accomplish what I am doing using Spice directives?

I wouldn’t ask this question if I hadn’t already searched the web for an answer. I think I don’t understand how to use Spice Directives on a schematic properly. I’ve read the LTSpice help and expanded help on the wiki site - but I can’t seem to find schematic rules with spice directives.

In short, please help me understand.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ There's a lot wrong here, and it's consistent with assuming how the software should work instead of reading up how it actually works. I suggest studying the B. Arbitrary Behavioral Voltage or Current Sources section of the help. Using B-sources (in this case the bv symbol when selecting parts), you should be able to build the circuit without any of that SPICE directive junk you have in the corner. Also, check that same help page on the proper syntax of the if(x,y,z) command. Lastly, if you're having trouble with IFs, then use actual comparators to implement the logic instead. \$\endgroup\$
    – Ste Kulov
    Mar 28, 2021 at 4:10
  • 1
    \$\begingroup\$ @SteKulov 's comment and Ernesto's answer are what you're looking for, but I would stress to use the digital logic whenever possible for boolean math, unless you have simple checks that don't go inside a loop (e.g. checking that a voltage reached a limit). \$\endgroup\$ Mar 28, 2021 at 8:40

1 Answer 1

3
\$\begingroup\$

I'm sure there is better way to achieve your goal of modeling switching behavior, but here is an example of using behavioral voltage, "bv", with output dependent on the voltage of another node and dependent on custom function.

Example Schematic

\$\endgroup\$
3
  • \$\begingroup\$ Thank you to both other replies. I am 'fairly new' at electronics; that is I've been re-learning analog electronics from over 25 years ago (whew!) and I have since become disabled with both physical and cognitive issues. I only mention this because, often, I need to read and re-read everything. Please know I have read the LTSpice help several times trying to grasp how to use the 'language'.I will definitely investigate BV a lot more and really examine @Ernesto 's illustration. Hopefully one day soon I'll learn digital electronics. Thanks for your help! \$\endgroup\$
    – RobMcN
    Mar 28, 2021 at 16:40
  • 1
    \$\begingroup\$ @Starblazer There are several additional resources such the LTwiki website (annoying ads.) and the LTspice groups page link. Additionally, there are some good free courses online (just make sure to "audit" when it prompts purchasing) link \$\endgroup\$
    – Ernesto
    Mar 28, 2021 at 18:02
  • \$\begingroup\$ Thanks @Ernesto. You've been great... But I have more questions which I'll post in a moment. \$\endgroup\$
    – RobMcN
    Mar 28, 2021 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.