CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Debounce routine -

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alm1006



Joined: 12 Jul 2005
Posts: 5

View user's profile Send private message

Debounce routine -
PostPosted: Tue Mar 07, 2006 11:52 am     Reply with quote

I would like to know if someone has a routine capable of debouncing any switch.
I've enclosed my jungle version of a debounce routine that's clearly not working. The routine && a 1 with FF then shifts << debounce until it equals 0. Your thoughts would be greatly appreciated.
Regards,
Albert



void TIMER2_isr(void)
{

cnt++; // cnt every 10ms

if (!input(pin_a4))
{
if (test_a4 == 0) //initialized in main
{
set_a4 = 1; // set_bita4 = input(pin_a4)
debounce = (set_a4 && 0xFF); // AND input(pin_a4) && 0x01
test_a4 = 1;
}

if (!input(pin_a4))
{
if (test_a4 == 1)
{

if (debounce >= 0x01)
{
1<<debounce;
output_high(pin_b2); // test bit
delay_cycles(2);
output_low(pin_b2);
}
else
{
a4_debounced = 1;
test_a4 = 0;
}
}
}
//---------------------------------------------------------------------------//
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 07, 2006 12:38 pm     Reply with quote

Quote:
I would like to know if someone has a routine capable of debouncing any switch.

http://www.ccsinfo.com/forum/viewtopic.php?t=19874
http://www.ccsinfo.com/forum/viewtopic.php?t=23837
http://www.ccsinfo.com/forum/viewtopic.php?t=17189

Also use the forum's search engine to search for: debounce
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Thu Mar 09, 2006 1:08 am     Reply with quote

One method of switch debouncing simply involves reading the switch at a slow enough rate that any bouncing will be over and done with between tests. If you happen to check the switch during bouncing, it either will or won't be found in the new state, but this doesn't matter: if you catch it in the new state, it'll be steady by the time it's next checked and you see the new state a second time. The same is true if you fail to catch it; it'll be steady in the new state by the time the next check is done, so the only effect is to delay recognition of the new state by one cycle. There are times where you may need to have an exact timestamp for when the first transition in the switch state occurred, but if it's just a question of reading a pushbutton operated by a human, there's no need to work hard to get the data. If timing is crucial, use an optical or magnetic switch instead!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group