All pastes #439740 Raw Edit

Rugludallur

public c v1 · immutable
#439740 ·published 2007-04-14 14:23 UTC
rendered paste body
component comp "Two input comparator with hysteresis";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.";param rw float hyst=0.0 """Hysteresis of the comparator (default 0.0)With zero hysteresis, the output is true when in1 > in0.  With nonzerohysteresis, the output switches on and off at two different values, each offset by distance hist from the point where in1 = in0.Keep in mind that floating point calculations are never absalute and it is therefor wise always set hist if you intend to use equ """;function _ fp "Update the comparator";;;MODULE_LICENSE("GPL");FUNCTION(_) {    float tmp = in1 - in0;    if(tmp < -hyst) {	out = 0;	equ = 0;    } else if(tmp > hyst){	out = 1;	equ = 0;    } else {	equ = 1;    }}