debouncing switches with a timer interrupt?


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Mike,

    I would suggest delegating switch debounce/management to the ISR
    With his switch inputs on RB7-RB4, how would you go about that without waiting for a switch release, and then clearing the int-on-change flag bit?

    Wouldn't releasing the switch re-trigger the interrupt?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Mike,

    With his switch inputs on RB7-RB4, how would you go about that without waiting for a switch release, and then clearing the int-on-change flag bit?

    Wouldn't releasing the switch re-trigger the interrupt?
    Oh no, I wouldn't use IOC interrupts in this application Bruce. Bouncing would be problematic. I would use periodic timer interrupts and poll the switches as in the example in post #15. And since OP is going to include RTC or Stopwatch functionality, periodic timer interrupts make sense.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Oh! I see what you meant now. Good idea.

    Newer types like the 16F193x series IOC are a lot easier to use. These don't require reading the port to clear IOC flag bits, and they can be set to trigger on any edge..
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42


    Did you find this post helpful? Yes | No

    Default yes, success at last.

    thanks guys, all this ideas work! now, all i have to do is implement the rtc and beeper, which are ready to be merged with this code.

    once again, thanks.

    ps; not that im complaining, but is there any other menu builder app in picbasic?
    NAG CON WIFE!
    WIFE VAR MOOD

  5. #5
    Join Date
    Aug 2010
    Posts
    4


    Did you find this post helpful? Yes | No

    Default antirrebotes

    yo he implementado esto y funciona correctamente
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    hi, again, im trying this piece of code, from a previous post
    Code:
    RB_SUBMenuLoop:
    ' BTN_PLUS is the Next Choice button
       IF BTN_PLUS=1 THEN
          BTN_PLUS=0
          ...
       ENDIF
    ' BTN_PREV is the Exit button
       IF BTN_PREV=1 THEN
          BTN_PREV=0
          RETURN
       ENDIF
    ' BTN_NEXT is the Goto SubMenu Choice button
       IF BTN_NEXT=1 THEN
          BTN_NEXT=0
          ...
       ENDIF
    GoTo RB_SUBMenuLoop
    then i have this code scanning port b, through a 1ms interrupt:
    Code:
    Changed = PortB ^ OldPort
             IF Changed.4 = 1 THEN     ; Pick your pin
             OldPort = PortB
             BTN_PLUS = 1
             ENDIF
    this code is incrementing one at a time, which is what i want, but the only problem is that it is incrementing on a rising and falling edge of a button push. so if i push the btn_plus, bmenupos increments by 1, and if i release it, bmenupos increments again.

    i want it to increment only on the rising edge, not on the falling edge. any ideas?
    NAG CON WIFE!
    WIFE VAR MOOD

  7. #7
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    When you exclusive-or "new" and "old" a resulting 1 bit indicates a change of state (either a new hi or new press, or a new lo or new release). You need to filter these "change" bits. If you AND the "change" bit with the "old" bit you filter out the "new press" bits and you're left with "new release" bits. If you AND the "change" bit with the "new" bit you filter out the "new release" bits and you're left with the "new press" bits.

    Hope this helps.

    Cheerful regards, Mike

    Code:
    '
    '  swnew  ____-----_____-----_____   new switch sample (positive logic)
    '  swold  _____-----_____-----____   switch state latch
    '  delta  ____-____-____-____-____   changes, press or release
    '  newhi  ____-_________-_________   new press bits
    '  newlo  _________-_________-____   new release bits
    '
        swnew = PortB                  ' sample active hi switches
        delta = swnew ^ swold          ' changes, press or release
        newhi = delta & swnew          ' get "new press" bits
        newlo = delta & swold          ' get "new release" bits
        swold = swnew                  ' update switch state latch
        IF newhi.4 = 1 THEN            ' 
          BTN_PLUS = 1                 '
        ENDIF

Members who have read this thread : 0

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