Weird SPICE conditional expression syntax a?b?c:d -- what does it mean?

I'm trying to use a SPICE model for the MC34063 that I downloaded from ON Semi

formatting link
in LTSPICE.

I'm running into problems with the syntax of this file.

First, I had to deal with the missing bitwise negation operator (~); this was easy enough to do.

But then I was stumped by a syntax that I didn't recognize, and I wasn't able to find any explanation in 5 or 6 different SPICE variants' manuals that I was able to find on line.

There are a couple of lines in this file that use (what appears to be) the ternary conditional operator strangely:

B3 9 0 V=(v(6,90) > 3) ? v(diff,90) > 1 ? 0 : v(vdd) B1 4 90 V=(v(6,90) > 3) ? (v(diff,90) > -1) ? v(vdd) : 0

That is, there are more '?' than ':' characters. I've always used these in pairs, but then I'm familiar with them from C and other languages.

This syntax is not acceptable to LTSPICE, and I haven't been able to find any of the many SPICE manuals available on line that actually discuss variations on the normal

cond ? a : b

syntax.

Could anyone here tell me how to rewrite the above two expressions using a "normal" syntax for the conditional operator?

As an aside, can anyone think why the author of this file didn't bother to clarify the meaning of lines like the following by throwing in a few extra parentheses:

B7 16 90 V=V(vdd,90)-1.5 > 1.25 ? 1.25 : V(vdd,90)-1.25 < 0 ? 0 :V(vdd,90)-1.25

Perhaps they were being charged for each character?

Thanks, Ned Konz

Reply to
Ned Konz
Loading thread data ...

"Ned Konz" schrieb im Newsbeitrag news:Ab6dnZ5pDKlsLazYnZ2dnUVZ snipped-for-privacy@wavecable.com...

Hello Ned,

You will find here examples for a translation of the IF-statements to PSPICE. LTspice correctly runs most of the PSPICE netlists.

formatting link

This model has been written for ICAP/4 SPICE from Intusoft. You can download a manual from their web page.

formatting link

No. Every SPICE has its own syntax for behavioral models. You can see similar differences between the many programming languages.

There is more you have to take care about. The default logic levels are 0.3V and 3.5V in ICAP/4. In LTspice they are 0V and 1V.

I wonder that you haven't heard of the LTspice Yahoo group.

formatting link
Files > Examples > SMPS Take a look to the example with the MC34063 in this folder.

Best regards, Helmut

Reply to
Helmut Sennewald

Thanks! I have his book. Though I believe that LTspice has the ?: operator. What is causing the problem is that some of the '?' are not matched with the ':' in the given expressions.

Ah... Reading the manual you pointed to (thanks!) I see that the original:

B3 9 0 V=(v(6,90) > 3) ? v(diff,90) > 1 ? 0 : v(vdd)

would be translated as:

B3 9 0 V={ if ((v(6,90) > 3) & (v(diff,90) > 1)), 0, v(vdd)) }

is this right?

Ah. I didn't know that.

Thanks for the pointers and the tips. I'll use the model there instead of banging on this one.

Ned Konz

Reply to
Ned Konz

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.