Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Electrical (http://www.chiefdelphi.com/forums/forumdisplay.php?f=53)
-   -   Toggle switches to Analog board? (http://www.chiefdelphi.com/forums/showthread.php?t=90235)

Alan Anderson 04-02-2011 11:38

Re: Toggle switches to Analog board?
 
Switch bounce would affect switches connected to a digital input at least as much as it would analog inputs. Most of the time, the programming is going to be such that it simply doesn't care whether the switch gets detected several times in quick succession.

For reading a switch on an analog input, the WPILib "analog trigger" function is what you want. That rejects glitch-type noise as part of its implementation.

JamesBrown 04-02-2011 11:38

Re: Toggle switches to Analog board?
 
Edit: Looks like I need to type faster if I am going to post in the same threads as Al and Alan. But what I posted may still be usefull so I will leave it up.


Quote:

Originally Posted by Al Skierkiewicz (Post 1015491)
Yes, You guys are right. I have to stop answering these questions while I am working on interfaces here. Alan, can you add something about programming so that switch bounce doesn't confuse the readings?

I am not Alan but I should be able to help here any way. To debounce a switch in software what you want to do is ensure that the press that was detected was a true press, not just noise or bounce. The easiest way to do this is once a press is detected start a counter, if the counter reaaches a certain value (10ms is probably acceptable for FRC Applications) then acknowledge that the switch is pressed. If the switch is released before counter times out the reset the counter and ignore the bounce.

Psuedo Code
Create Counter- Initialize to Zero

Assuming Switch sampling occusr every ~1ms

If (Software_representation of switch = not-pressed)

If switch is not pressed
Reset Counter
Set Software representation of switch to not-pressed
else (switch is pressed)
increment counter
end if

if counter > 10
Set software representation of swtch to pressed
end if

Then you can reverse the switched/not-switched cases for then the butto is pressed if you need to detect the release as well.

sircedric4 04-02-2011 17:58

Re: Toggle switches to Analog board?
 
Cool discussion, I am happy I can use my SPST switches. I already had a bunch purchased and laying around. I also appreciate the pseudocode. Thanks again.

Al Skierkiewicz 04-02-2011 18:23

Re: Toggle switches to Analog board?
 
Darren,
Sorry I led you down the rosy path earlier.


All times are GMT -5. The time now is 07:07.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi