Searching \ for 'Switch Debounce Routine' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=switch+debounce
Search entire site for: 'Switch Debounce Routine'.

Truncated match.
PICList Thread
'Switch Debounce Routine'
2000\02\11@035923 by Longley, Jason

flavicon
face
Hi, has anyone got a Switch debounce routine for a PIC
16C84?
I also require help on a routine that makes sure a switch
is fully on for about 1/4 of a second before reseting a
count register to 0 other wise the switch is overlooked

----------------------------------------
Longley, Jason
Email: spam_OUTJason.LongleyTakeThisOuTspamuwe.ac.uk
"University of the West of England"

2000\02\11@041816 by Don McKenzie

flavicon
face
"Longley, Jason" wrote:
>
> Hi, has anyone got a Switch debounce routine for a PIC
> 16C84?
> I also require help on a routine that makes sure a switch
> is fully on for about 1/4 of a second before reseting a
> count register to 0 other wise the switch is overlooked

have a look at:
http://www.dontronics.com/see.html
this covers most of the more common routines used by these micros.

Don McKenzie    .....donKILLspamspam@spam@dontronics.com      http://www.dontronics.com

World's Largest Range of Atmel/AVR and  PICmicro Hardware and  Software.
Free Basic Compiler and Programmer http://www.dontronics.com/runavr.html

2000\02\11@043441 by Michael Rigby-Jones

flavicon
face
part 0 6247 bytes
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">You could either use a timer interrupt, or poll the switch in your main program loop.&nbsp; If the switch is pressed, decrement a counter. If it isn't reload the counter with a start value.&nbsp; When the counter reaches zero, set a flag that your main program can read.&nbsp; If you use this in a timer interupt you will need to choose suitable values for the TMR0 pre-scaler.&nbsp; The debounce counter will have also to be pre-loaded with a suitable value in order to get your 1/4 second interval.&nbsp; If your main loop is very fast, you may need to use a 16 bit counter.</FONT></P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">You may also need to change the logic of the switch test, depending on how you've wired the switch.&nbsp; This example assumes the switch grounds the port pin when pressed.</FONT></P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Haven't actually tested this, so usual disclaimers apply....</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">btfss&nbsp;&nbsp; PORTB,SWITCH&nbsp;&nbsp;&nbsp; ; obviously put your own port and bit number in here</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">goto&nbsp;&nbsp;&nbsp; pressed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; switch is pressed</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">movlw&nbsp;&nbsp; 127&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; switch is not pressed, reload counter with your value</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">movwf&nbsp;&nbsp; counter</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">bcf&nbsp;&nbsp;&nbsp;&nbsp; flags,SWITCH&nbsp;&nbsp;&nbsp; ; clear the switch flag</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">goto&nbsp;&nbsp;&nbsp; switch_done</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">pressed</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">decfsz&nbsp; counter &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; decrement the counter</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">goto&nbsp;&nbsp;&nbsp; switch_done&nbsp;&nbsp;&nbsp;&nbsp; ; not reached zero yet</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">bsf&nbsp;&nbsp;&nbsp;&nbsp; flags,SWITCH&nbsp;&nbsp;&nbsp; ; reached zero so set flag</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">switch_done</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">; rest of program&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Cheers</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Mike</FONT>
<UL>
<P><FONT SIZE=1 FACE="Arial">{Original Message removed}

2000\02\11@063715 by Scott Dattalo

face
flavicon
face
On Fri, 11 Feb 2000, Don McKenzie wrote:

> "Longley, Jason" wrote:
> >
> > Hi, has anyone got a Switch debounce routine for a PIC
> > 16C84?
> > I also require help on a routine that makes sure a switch
> > is fully on for about 1/4 of a second before reseting a
> > count register to 0 other wise the switch is overlooked
>
> have a look at:
> http://www.dontronics.com/see.html
> this covers most of the more common routines used by these micros.

After that, look here to see an extremely fast and efficient one:

http://www.dattalo.com/technical/software/pic/debounce.html

If you dig into the routine, you might be able to solve your 1/4 second
switch must stay down problem. 1/4 is a really long time; 250,000 uSec is
the way I prefer to look at. So you're probably going to want to sample at
a faster rate (than once every 250,000 uS) - 20 mS is not uncommon for
this application - and save intermediate samples. Since your looking for a
change of states over this period you can do something very simple like
this:

; first grab the initial (presumably debounced) state:

   movf  SW_PORT,w
   movwf initial_sw_state
   clrf  change_detected   ; assume no changes
...

then in the periodic routine sampling the switches:

; Read the switch and see if it has changed

   movf  SW_PORT,w           ;get the current state
   xorwf initial_sw_state,w  ;compare with initial state
   iorwf change_detect,f     ;save any changes

...


Then after the quarter second is up:

   btfsc  change_detect,MY_SWITCH_OF_INTEREST_BIT_POSITION
    goto  switch_changed_states

; fall through to here if the switch did not change states
; and clear the count register...



Scott

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...