09 Feb 2017 15:35 #87665 by jensor
Can someone give me an example of a POSTGUI_HALFILE containing the debounce component for debouncing a switch input?
09 Feb 2017 16:07 #87672 by k-1
loadrt debounce cfg=5 (for 5 comp input declare in hal file)
addf debounce.0    servo-thread

setep debounce.0.delay 4 (for ex .... 4*servo-thread ... normally 1ms so 4ms)

(in your postgui)

net xxx-switch <= (your phisical pin) hm2_5i25.0.7i77.0.0.input-33
net home-xxx debounce.0.0.out => (your signal with filter-delay) joint.0.home

net morehot-switch <= .....
net veryhot-switch debounce.0.1.out => .....

I hope these help
09 Feb 2017 16:11 - 09 Feb 2017 16:13 #87673 by Todd Zuercher
It depends a bit. If you already have the switch connected else where in hal you will need to change that to insert the denounce between those connections.

Here is an example that would debounce the input from parallel port 0 pin then send that signal out to
loadrt debounce cfg=1

addf debounce.0 servo-thread

setp debounce.0.delay 10   # Sets number of thread cycles the input has to be true before the output changes.  (Has to be 2 or more to actually do anything.)

net debounce-in <= =>

net debounce-out <=  debounce.0.0.out =>
(I must type slow.)
Last Edit: 09 Feb 2017 16:13 by Todd Zuercher.
09 Feb 2017 19:47 #87695 by jensor
You are very informative. However more questions.
Can this portion be put in postgui file?:

loadrt debounce cfg=5
setp debounce.0.delay 4

Or must it go in hal file?

And would this be proper?:

loadrt debounce cfg=3 (assume used for 3 different switches)
setep debounce.0.delay 4

addf debounce.0 servo-thread
addf debounce.1 servo-thread
addf debounce.2 servo-thread

net A input.0.sw0 =>
net A1 debounce.0.0.out => whateverPin1

net B input.0.sw1 =>
net B1 debounce.0.1.out => whateverPin2

net C1 input.0.sw2 =>
net C1 debounce.0.2.out => whateverPin3
09 Feb 2017 20:09 - 09 Feb 2017 20:16 #87698 by Todd Zuercher
It can work in the post gui hal file, but it is the best practice to put all of your loadrt and addf lines in one place (at the beginning of the 1st hal file), because it makes it easier to keep track of them all and keep your addf lines loading in the necessary order, and because you can't loadrt any component more than once.

For debouncing 3 switches using the same delay timing, you would only addf debounce.0 servo-thread. Debounce.1 and debounce.2 would not be used.

If you needed 3 different time delays for your 3 switches you would use
loadrt debounce cfg=1,1,1
setp debounce.0.delay 4
setp debounce.1.delay 10
setp debounce.2.delay 20

addf debounce.0 servo-thread
addf debounce.1 servo-thread
addf debounce.2 servo-thread

(and the pins would be)

loadrt debounce cfg=1,1,1 (would give you 3 different debounces for debouncing 3 pins each with it's own debounce time.)
loadrt debounce cfg=5,3,4 (would give you 3 different debounces one for debouncing 5 pins with one time period, one for 3 and one for 4.)
Last Edit: 09 Feb 2017 20:16 by Todd Zuercher.
Time to create page: 0.132 seconds
Powered by Kunena Forum