1
\$\begingroup\$

I'm playing around with some wheel encoder sensors and an Arduino. The sensor needs a bit of debouncing, so that got me wondering how the microcontroller core is seeing the input. That is, what does the input signal look like after going through the Schmitt trigger and the synchronizer in the GPIO input path?

Is there any way of looping two GPIO pins directly, one as an input and the other as an output so I can see what's the signal looks like at the other end of the synchronizer?

As I see it, if I try a read/write in software, I'll lose information if the program is any longer than one instruction. True?

\$\endgroup\$
  • \$\begingroup\$ The synchronizer is on the input path. What would the output be doing? \$\endgroup\$ – Ignacio Vazquez-Abrams Aug 3 '14 at 22:39
  • 1
    \$\begingroup\$ I want to wire the output of the GPIO pad I've configured as an input to another GPIO configured as an output :) I want to see what the input path does to my messy signal! \$\endgroup\$ – Marty Aug 3 '14 at 22:43
  • \$\begingroup\$ When you say "wire", you mean perform an internal loopback? \$\endgroup\$ – Ignacio Vazquez-Abrams Aug 3 '14 at 22:46
  • \$\begingroup\$ I think that's what he means. And @op, that's not possible if not via software, losing some clock cycles. If you want to know how your signal looks inside the micro you should find everything you need on the datasheet. \$\endgroup\$ – Vladimir Cravero Aug 3 '14 at 22:48
  • 1
    \$\begingroup\$ No, you can't do that. But debouncing can be easily accomplished by simply ignoring an input for some short time after seeing a transition of interest. Debouncing is distinct from noise filtering, in that bounces always follow a true transition; if you have actually noise/glitches where you need to ignore excessively short pulses (even the first one), that is a different problem. \$\endgroup\$ – Chris Stratton Aug 4 '14 at 0:07
2
\$\begingroup\$

Debouncing idea is not good if you need use quadrature encoder. Even the max. theoretical frequency (counted from max. RPM) is low you can see high frequency flickering at one channel which is plus one, minus one, etc. When you miss some edge (e.g. handled by external interrupt), you see shift. If you need count up/down pulses, you can reuse an external clock for two AVR counters. MCU supports some simple debouncing and bandwidth is high enough. It on-loads MCU as well. I found that evaluating quadrature A-B signals in code is useless, i.e. not reliable enough for high precision systems and rather using external quadrature counters LSI.

Some issues related to connecting two port are in AVR ATMega I/O pin overcurrent protection thread.

\$\endgroup\$
1
\$\begingroup\$

In debouncing you generally have two options: a hardware fix, or a software fix. Depending on the application either could be preferable.

The fewer inputs that need debouncing the more a software fix becomes preferable, particularly on low powered micro controllers. A software fix would be to use interrupts that run whenever the input state changes and then have some sort of variable keep track of when the last state change or 'bounce' occurred. If it's in the single digit millisecond then it's probably a bounce, and you would want to reject that value. A lot of it will be trial and error to see what's an acceptable time between presses, but 100ms is a good starting point because it's highly unlikely a human can press a button faster than 10 times per second and it's even less likely that that was their intention, and it's almost impossible that a button bounce could happen in over 100ms unless it's disfunctional.

As for a hardware fix, this can add to the amount of circuit elements your board will have to use so there's that drawback. But if you're limited by the power of the microcontroller you're using and you need a lot of debounced switches it might be the only feasible option. But if you can manage to tune and solder the right RC circuit to your input you can have 'smoothing' circuit that will reject quick changes to your input signal before it is sent to the micro controller input. Simple RC Debouncing Circuit

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.