Debounce routine comments?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    18

    Default Debounce routine comments?

    I needed to have some short of debouncing of an input in order to accept it in my program.
    In my program I am looking if the input has a High(+5V) or Low(0V).
    The input is driven by the contacts of a relay which cannot oscillate.(If this happened I believe this could cause the program to hang)

    INPUTPORTBIT VAR PORTx.x
    COUNTERA VAR BYTE
    INPUTPORTBITFLAG VAR BIT
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' subroutine CHECKINPUTPORTBIT
    CHECKINPUTPORTBIT:
    COUNTERA=10
    CKCK:
    Pause 100
    IF INPUTPORTBIT=0 Then
    COUNTERA=COUNTERA+1
    IF COUNTERA=20 Then WAYOUT1
    Else
    COUNTERA=COUNTERA-1
    IF COUNTERA=0 Then WAYOUT2
    EndIF
    GoTo CKCK
    WAYOUT1:
    INPUTPORTBITFLAG=1 ''OK OUR INPUT WAS STABLE FOR AT LEAST 1 SEC
    GoTo WAYOUT3
    WAYOUT2:
    INPUTPORTBITFLAG=0 ''NOT OK
    WAYOUT3:
    Return

    I used this routine(it is working for me Ok since yesterday) which ,I think, has some nice features like making the debouncing ''light'' or ''heavy'' by altering the PAUSE and/or the COUNTERA start and limit value.
    Perhaps someone can improve it or make it with less code?
    Please comment
    Bill

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Question Reinventing the wheel ...

    Why not simply use the BUTTON Command ??? ... even in a loop for long debouncing times ...

    Alain
    Last edited by Acetronics2; - 20th February 2008 at 15:05.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Bill,
    I agree with ACETRONICS about the button command, I have a thought about making it easier to follow your code, instead of all caps you might try InputPortBitFlag or Input_Port_Bit_Flag.
    Ultimately only you have to look at it, I just thought it might be easier.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Oct 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Joe S your suggestion will be given a trial because it started annoying me also having only capitals but sometimes habits are difficult to change.
    The reason for reinventing the wheel ,as you put it, is that from the very early days of PicBasicPro ther were some bugs and problems with this Button command and I was avoiding it to the point I realize now that I forgotten all about it.
    Having a look though in the manual I think it is not providing the same things as the "wheel".
    It is also peculiar that the manual ''prompts'' you not to use it but use an IF THEN instead.
    Now that I "apologized" I am waiting for the verdict.
    Bill

Similar Threads

  1. Matrix Keypad routine
    By mister_e in forum Code Examples
    Replies: 134
    Last Post: - 18th September 2022, 20:30
  2. Replies: 4
    Last Post: - 17th December 2009, 00:29
  3. Darrel's latest 16 bit averaging routine?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th October 2009, 01:57
  4. PIC16F84A Tachometer LED routine
    By ThaSanta in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 24th July 2009, 02:58
  5. Software Driven Reset Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th April 2005, 00:53

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts