Schmitt trigger

More
7 years 8 months ago #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
7 years 8 months ago #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
7 years 8 months ago - 7 years 8 months ago #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:
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.
Last edit: 7 years 8 months ago 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
7 years 8 months ago #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
7 years 8 months ago #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
7 years 8 months ago - 7 years 8 months ago #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: 7 years 8 months ago by Richard J Kinch. Reason: Add an implementation detail

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

Time to create page: 0.388 seconds
Powered by Kunena Forum