Feature request: TANH(x) function please

One of the most useful functions for behavioural modelling. Hyperbolic Tan is a very good function to represent bjt longtail pair transfer functions and can be used as the core of an arbitrary opamp model.

It allows very simple modelling of comparators, limit functions and clamping circuits. The same things can be done using the ATAN(x) function but are much less elegant. Functions using ATAN(x) end up more unwieldy and less intuitive.

In my experience, TANH(x) tends to converge better than ATAN(x).

I have a huge library of SPICE behavioural models, many of which use the TANH(x) function but which I can't port to CircuitLab because (a) there's no TANH(x) function and (b) there's no equivalent of the SPICE arbitrary functional B source to use them in.

A few examples:

Comparator with 0 - 1V output: V=0.5(TANH((V(IN1)-V(IN2))gain)+1)

Ideal opamp with +/-5V output swing: V=5(TANH((V(INP)-V(INN))1k)+0)

An ATAN(x) version of the same thing: V=2/pi(ATAN((V(INP)-V(INN))10k)+0)

Ideal opamp with 0V to +5V output swing: V=2.5(TANH((V(IN)-V(OUT))gain)+1)

non-inverting schmitt with 0 - 1V output V=0.5(tanh((V(in)-lothresh+(V(out)-1)(hithresh-lothresh))*1k)+1)

inverting schmitt with 0 - 1V output V=0.5(tanh((hithresh-V(in)+(V(out)-1)(hithresh-lothresh))*1k)+1)

A bit more exotic ....

A window comparator: V=0.5(tanh((V(in)-winlo1)1k)+1) * 0.5(tanh((winhi1-V(in))1k)+1)

Very simple 3 terminal linear regulator/reference reference voltage = vref and with dropout voltage = vdo: V=0.5vref(tanh((V(vcc,refn)-vdo-V(refp))*1k)+1)

Latching current_ramp generator. Has a capacitor from OUT to ground (with a 1G in parallel to provide a ground return) Put in voltage pulse in of >10mV and a duration long enough to cause VOUT to ramp up to > VMIN and o/p will ramp to VSTOP at rate governed by IOUT/C1 (From CV = IT) IOUTTANH((V(OUT)-V(IN)0.5(TANH((VMIN-V(OUT))1k)+1)-VSTOP0.5(TANH((V(OUT)-VMIN)1k)+1))1k)

An open loop function that limits output voltage to VLIM. Does not require the closed loop technique of using an opamp with a limited output voltage swing. Therefore, this function can be built inside other functions. Note that the G parameter may need to be adjusted to minimise under/overshoot. 0.5(V(IN)(TANH((VLIM-V(IN))G)+1)+VLIM((TANH((V(IN)-VLIM)*G)+1)))

A track and hold: Requires a capacitor from OUT to ground. V(track) = 1 => V(OUT) tracks V(IN) V(track) = 0 => V(OUT) held at value when V(track) 1 => 0 edge. I=V(track)Iout/2TANH((V(IN)-V(OUT))*1k)

Big ask?

Big please!

:)

by signality
March 26, 2012

Many of these should now be possible with our new support for arbitrary behavioral sources. See the blog post announcement.

by mrobbins
April 13, 2012

Fantastic!

It's like Christmas on Friday the 13th!!

I am that kid in a sweet shop ...

p.s. sorry about the formatting hell in my original post: Markdown mangled some of the "*" symbols in my expressions.

So, now that we have behavioural sources, is there a way to post expressions into the forums without Markdown mangling them but which preserves them so that they can be cut and pasted straight into a behavioural source in a schematic?

:)

by signality
April 14, 2012

Post a Reply

Please sign in or create an account to comment.