All pastes #439616 Raw Edit

tomp

public text v1 · immutable
#439616 ·published 2007-04-14 12:23 UTC
rendered paste body
component compEqu "Two input comparator with hysteresis and equality test";
pin in float in0 "Inverting input to the comparator";
pin in float in1 "Non-inverting input to the comparator";
pin out bit out "Output of the comparator.";
pin out bit equ "Equal within hysteresis band.";

param rw float hyst=0.0 """Hysteresis of the comparator (default 0.0)

With zero hysteresis, the output is true when in1 > in0.  With nonzero
hysteresis, the output switches on and off at two different values, 
separated by distance hyst around the point where in1 = in0.
The equ output is true when the difference between the 2 inputs 
is inside the range of +/- 1/2 hysteresis""";

function _ fp "Update the comparator";
;;
MODULE_LICENSE("GPL");
FUNCTION(_) {
    float tmp = in1 - in0;

    equ=0;
    if(tmp >= -hyst/2.) or (tmp <= hyst/2) ) {
      equ = 1;
    }

    if(out) {
      if(tmp < -hyst/2.) out = 0;
    } else {
      if(tmp > hyst/2.) out = 1;
    }
}