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 CCS Technical Support

how to implement debounce using Timer0

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



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

how to implement debounce using Timer0
PostPosted: Wed Jun 18, 2014 2:22 pm     Reply with quote

I have searched this topic in the forum but did not find a reasonable thread.
I implemented Interrupt-on-change #INT_RA routine on PIC16F688 and detect changes on three tac switches. The routine works, I am able to distinguish which switch was pressed.

The problem is one Tact switch I am setting a flag but it keeps getting reset.
So, the flag is to determine if the Temp is Deg C or Deg F. And as the switch is pressed I toggle the flag. But it seems its getting toggled once when I push and another time when I lift my finger from the tac switch.

Can you please give me some thoughts on how to implement this?
Thank you all.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 2:50 pm     Reply with quote

See this thread on the Button command and a link to a Timer interrupt version:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 3:08 pm     Reply with quote

Also, this thread has tips on how to distinguish between pressing and
releasing a switch, when using #int_ra or #int_rb interrupts:
http://www.ccsinfo.com/forum/viewtopic.php?t=51383
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 3:13 pm     Reply with quote

PCM Programmer Thanks, but as I mentioned I am already using #INT_RA (interrupt on change) to detect changes to Port A so looping in While will not work. Is there a thread where timer is used for debouncing the switch?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 4:04 pm     Reply with quote

I don't use the int on change timers.

I simply use any one of the built-in timers to generate a (say) 1ms tick.
On each tick, poll the switches, use that to decide on switch state and implement debounce.

Mike
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 4:43 pm     Reply with quote

PCM Programmer once more you amazed me, thanks so much.
Mike Walne, I will try your method once I am done with this approach, thanks so much for the suggestion. Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 5:14 pm     Reply with quote

The button command (interrupt version) polls the switches in the timer
interrupt at at 10ms interval. This inherently debounces the switches.
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