Hello analogspiceman
These following functions are intended to be used in b-sources. The first
two replicate edge triggered logic such as is used in the a-device DFLOP
clock input. The last function is more complicated as it includes three
behavioral integrators to provide a running integrated average of x
(starting on the falling edge of sampling pulse s) that is then held until
the next rising edge of sampling pulse s. In normal use, x would be an
analog input and the sampling pulse s would be a series of very narrow 1
volt positive digital pulse.
.func up(s) buf( ddt(s)) ; generates pulse on rising edge of s
.func dn(s) buf(-ddt(s)) ; generates pulse on falling edge of s
* The following averages x between sample pulses s
.func ave(x,s) sdt(0,sdt(x,0,dn(s))/sdt(1,0,dn(s)),up(s))
B1 1 0 V= ave(V(x),V(s)) ; source for x and s not shown
It's a nice example on how to use idt() as idt(0, x, y), instead of
the more usual idt(x, 0, y). Still, because we're dealing with
B-sources, I noticed that the output is sensitive to the sampling
clock's time resolution. I tried using a current source with Rpar=1
Cpar=1n to smooth the flow, but apparently I stumbled across a bug:
the simulation won't start and LTspice throws an "Unknown parameter
'1n' [...]". If I don't use the custom function, it works. I tried
with some quick bogus custom functions, and it seems that this only
happens with these, even if the function is x+y. Using any builtin
arithmetic works. Does this happen to you, also? I am using the latest
update (23 oct).
--
Vlad
______________________
ltspicegoodies.ltwiki.org -- holding, among others:
a universal analog/digital filter, block-level models
for power electronics (and not only), math blocks
with a more stream-lined approach, some digital
ADC, DAC, (synchronous-)counter, JKflop, etc.