View previous topic :: View next topic |
Author |
Message |
CMatic
Joined: 11 Jan 2012 Posts: 69
|
how to implement debounce using Timer0 |
Posted: Wed Jun 18, 2014 2:22 pm |
|
|
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
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
CMatic
Joined: 11 Jan 2012 Posts: 69
|
|
Posted: Wed Jun 18, 2014 3:13 pm |
|
|
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
|
|
Posted: Wed Jun 18, 2014 4:04 pm |
|
|
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
|
|
Posted: Wed Jun 18, 2014 4:43 pm |
|
|
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. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 18, 2014 5:14 pm |
|
|
The button command (interrupt version) polls the switches in the timer
interrupt at at 10ms interval. This inherently debounces the switches. |
|
|
|