Schmitt trigger

More
09 Feb 2019 03:29 #126029 by thadwald
Schmitt trigger was created by thadwald
I would like a Schmitt trigger or hysteresis component for taming some analog inputs. Does the LinuxCNC HAL have anything like this?

I have a row of potentiometers on a control panel that I am re-purposing for LinuxCNC and I want to use these to control feedrate override, rapid override, spindle override, and jog speed. Due to the noisy nature of analog signals, I am adding a lowpass filter (either with a physical capacitor or with the ilowpass component. I also plan to make them fairly granular, so as to settle on nice, round numbers, such as 100%, 110%, and so on.

I anticipate that when the potentiometer sits near the middle of any two of my nice, round numbers, the output will inevitably oscillate between these numbers. To solve this, I would like to have a schmitt trigger switching behavior between the output values.

For example, as the user turns a pot from 100% towards 110%, the output should remain fixed at 100% until the input is at 110%. conversely, as the user then turns the pot back down to 100%, the output should remain fixed at 110% until the input is at 100%

Any ideas on how to implement this?

Please Log in or Create an account to join the conversation.

More
09 Feb 2019 11:55 #126050 by pl7i92
Replied by pl7i92 on topic Schmitt trigger
You can use
Debounce or Oneshot

look here
linuxcnc.org/docs/html/man/man9/

Please Log in or Create an account to join the conversation.

More
13 Feb 2019 05:51 - 13 Feb 2019 14:04 #126326 by thadwald
Replied by thadwald on topic Schmitt trigger
I finally got this to work as I like it.
Here's the the relevant part of my HAL file:
#*********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.
Attachments:
Last edit: 13 Feb 2019 14:04 by thadwald. Reason: added second image
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 00:50 #126419 by andypugh
Replied by andypugh on topic Schmitt trigger
This sounds like a job for a specially written HAL component.

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 03:08 #126430 by thadwald
Replied by thadwald on topic Schmitt trigger
I agree.

Feel free to this route until someone does.
:)

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 07:48 - 14 Feb 2019 07:55 #126436 by Richard J Kinch
Replied by Richard J Kinch on topic Schmitt trigger

I would be interested in learning if there is an easier way of accomplishing this.


Your application of filtering and hysteresis is the best you can do in theory, given the poor signal source you've got.

Carbon pots are the neurotics of electronics. If you can, you should use classic wirewound type of industrial grade. On these the wiper spans several wirewound turns and averages them. You still have a slight hysteresis, but no hammering jumps. This avoids the dirty characteristic of carbon pots which read a point contact on a noisy surface. Eventually you will regret factoring unpredictable inputs into a machine.

The wirewound will provide some small but reliable basic "steppy" form of hysteresis. Set the hysteresis in the HAL filtering to some larger value, and you will have a reliable and stable control characteristic.

My go-to is the CTS 026TB32R103B1B1, which is 10K ohm linear, and about 8 bucks at digikey.com .
Last edit: 14 Feb 2019 07:55 by Richard J Kinch. Reason: Add an implementation detail

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 13:56 #126455 by thadwald
Replied by thadwald on topic Schmitt trigger
You are correct in that the carbon pots are a cheap part and probably not best suited for controlling large industrial motors. When I began retrofitting this control panel, every one of them was so noisy they were unusable; a bit of sideways pressure on the stem would cause up to 30% noise. I washed them out with alcohol and now they are actually quite good in therms of noise. I am guessing that 10 years down the road they will be bad again, which, as you pointed out, simply isn't the case for wire-wound pots.

One issue that wire-wound pots won't solve, though, is the fact that similarly to carbon pots, they can be positioned near a switching threshold. Say for example you scale a 3.3v output by a factor of 10 and quantize that by converting to integer, getting 34 discreet steps. If the scaled input voltage from the pot is at 9.99 it will inevitably cause erratic switching between 9 and 10 because there is always some noise in the circuit and the logic has zero hysteresis.

An ideal solution to this would actually be a rotary selector switch with as many switch positions as you want the control to have in the first place.

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 14:25 #126457 by rodw
Replied by rodw on topic Schmitt trigger
Consider replacing the pots with binary coded switches.
www.jaycar.com.au/4-pole-sealed-pcb-rotary/p/SR1216

You can decode the outputs with one of the mux components and 4 input pins will give you up to 12 different discrete values on each switch.

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 20:35 #126492 by thadwald
Replied by thadwald on topic Schmitt trigger
I am considering doing just that... I would need one with a 5 bit output and more positions, though.

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 21:20 #126493 by rodw
Replied by rodw on topic Schmitt trigger
The one I posted had 12 positions.
Surely a 16 position switch would be enough? That only needs 4 outputs.
www.mouser.com/ProductDetail/NKK-Switche...YrFeQ53PNxELVP6Jw%3d

Please Log in or Create an account to join the conversation.

Time to create page: 0.141 seconds
Powered by Kunena Forum