1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Dedicated PIC Debouncer

Discussion in 'Microcontrollers' started by Mogs, Aug 19, 2017.

  1. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    As I state in post #9 there is no need to debounce and it looks like you have finally got it working without.

    Nicely done.

    Mike.
     
  2. atferrari

    atferrari Well-Known Member

    Joined:
    Oct 8, 2003
    Messages:
    2,816
    Likes:
    121
    Location:
    Buenos Aires - Argentina
    For debouncing a signal from an optical encoder going into a counter IC 74c925, I used the most simple, crude circuit of a Schmitt trigger (Wikipedia). It worked flawlessly.

    For all my button/key debouncing routines in a micro I simply use one dedicated counter for each button/key which is loaded with a certain value, the 1st time it is detected as "pushed down". Succesive ISRs, every 1 or 5 ms, decrement that value. Up to now, tiny code is involved.

    Since main looop insists in reading the button/s, it simply verifies that the specific counter came down to zero. If not, it repeats the reading once more. Tiny code involved again.

    When the counter is finally found =0, the "pushed down" condition is verified once more. If so, the key related routine is executed.
     
  3. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    I'm still somewhat bemused why you just didn't use one of the existing Arduino libraries for encoders?, for using more than one encoder they usually use interrupts for one, and software for the second.

    I've used timer interrupts on a PIC 24F for reading encoders, and it's easy to read multiple ones in that way in the interrupt routine.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Mike - K8LH

    Mike - K8LH Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    3,642
    Likes:
    109
    Location:
    Michigan, USA

    Happy to hear you got it going, Gary.
     
  6. Mogs

    Mogs New Member

    Joined:
    Aug 19, 2017
    Messages:
    13
    Likes:
    0
    Location:
    whidbey island
    You were right, Mike, and thank you.

    Thanks atferrari, you are right as well, I am just too cheap.

    Nigel, I didn't use the library because I am stubborn and don't want to use one of the only two external interrupts, or constantly poll a stupid encoder that sits there idle for 99% of the time. But, I am laughing with you at myself, and thanks for your input. Your pensive bemusement comes off way better than mine.

    Mike, thank you very much, and if a 4 transition per detente encoder is relatively easy, I'm sure glad I didn't try some other cheap encoder, grin, because until I stumbled upon this look up table method, it sure didn't seem easy to me (at least without throwing some serious hardware conditioning at it). Delay polling and timed interrupts sucked, for me, at least.

    Thanks all, for your help, and now onto the hard stuff...

    Gary
     
    Last edited: Aug 27, 2017
  7. Mogs

    Mogs New Member

    Joined:
    Aug 19, 2017
    Messages:
    13
    Likes:
    0
    Location:
    whidbey island
    Thanks, Kiss, for the heads up on the code tags. I was struggling with the code insert icon which wasn't doing anything, and then I messed around with forcing comments to be italicized. One PITA gone, thanks to you.
     

Share This Page