Continue to Site

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.

  • 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.

Dedicated PIC Debouncer

Status
Not open for further replies.
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.
 
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.
 
I know you are probably laughing at my naivety, Nigel, but I have less confidence than you do in 8 bit micro-controller efficiency. So, let me enjoy this brief respite from the learning curve still looming over me, grin. If anyone is considering code for an encoder, I highly recommend trying this code out-

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.
 
Gary, what type of rotary encoders are you using? Is it the type with detents? Those usually produce all four phase changes between detents as you rotate it and they're relatively easy to debounce.

Regards, Mike
Happy to hear you got it going, Gary.
 
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:
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.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top