View Single Post
  #8   Spotlight this post!  
Unread 04-02-2011, 11:38
JamesBrown JamesBrown is offline
Back after 4 years off
FRC #5279
Team Role: Engineer
 
Join Date: Nov 2004
Rookie Year: 2005
Location: Lynchburg VA
Posts: 1,280
JamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond repute
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 View Post
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.
__________________
I'm Back


5279 (2015-Present)
3594 (2011)
3280 (2010)
1665 (2009)
1350 (2008-2009)
1493 (2007-2008)
1568 (2005-2007)