I finally got this to work as I like it.
Here's the the relevant part of my HAL file:
Code:
#*********Feedrate Override********
#analog knobs are used for setting override, which needs to fall on
#numbers that are multiples of 10. Additionally, to prevent low-amplitude analog noise
#from causing erratic switching between quantized values, the logic
#needs to incorporate a deadband. This is accomplished with a
#pair of comparitors and an updown counter component
#set feedrate override scale for 200% at 20 counts
#raw voltage is 3.3v to 0v; invert, scale, and offset to zero
setp scale.0.gain -6.2
setp scale.0.offset 20.2
net vin1 hm2_7i96.0.7i73.0.0.analogin0 => scale.0.in
#feed scaled voltage into two comparitors
#offset the input using sum2 instead of hysteresis beacuse hysteresys has on behavior
setp sum2.0.in0 -1
setp sum2.1.in0 1
net vin1scaled scale.0.out => sum2.0.in1 sum2.1.in1
net vin1highoffset sum2.0.out comp.0.in1
net vin1lowoffset sum2.1.out comp.1.in0
#comparitors are each (and)combined with a clock pulse
#and fed respectively into the countup and countdown inputs of an updown counter
#clock signal established elsewhere
net clock => and2.21.in0 and2.22.in0
net upcomp1 comp.0.out => and2.21.in1
net downcomp1 comp.1.out => and2.22.in1
net uppulse1 and2.21.out => updown.0.countup
net downpulse1 and2.22.out => updown.0.countdown
#The output of the counter is converted to float
#and fed back into the other input of each comparitor
net feedoverridequant updown.0.count => conv-s32-float.0.in
net feedoverride conv-s32-float.0.out => comp.0.in0 comp.1.in1
#counter output is also our final output
setp halui.feed-override.scale 0.1
net feedoverridequant => halui.feed-override.counts
Along with that, here's a screen shot of the halscope output:
The smooth trace represents the scaled voltage input, and the quantized trace is the desired output. I created this by setting up the traces and manually turning the the potentiometer knob with the run mode set to Roll.
Note that there is a hysteresis; at any given point, on the slope, the required change in input to effect the output is 1. This means that so long as the analog noise is less than +- half of a "step," the output will be stable.
I would be interested in learning if there is an easier way of accomplishing this. After I was all done I saw the wcomp component, which seems to be at least slightly neater.
For comparison, here's the an illustration of the original problem. When the input sits at the threshold, a small amount of noise or even adjusting one of the nearby potentiometers causes a jump in the output.