I want to have a pair of simple 3-pin limit switches that connect to my Teensy 4.0, that would be used in conjunction with a stepper motor assembly, to detect when the stepper motor reaches a certain angle and prevent it from rotating further than desired.
The limit switch would be only used for triggering a flag upon the stepper motor shaft extension hitting it. Someone recently mentioned the fact that a de-bouncing circuit would be required for limit switches to operate properly. As far as I understand, when a limit switch is pressed, for a brief amount of time the switch may alternate between it's digital readings, allegedly resulting in incorrect readings.
Is my understanding of the requirements for a de-bouncing circuit when working with limit switches correct? Does my requirement for the limit switch require a de-bouncing circuit? Is there a specific example of de-bouncing circuit that my limit switches would work best with?
Thank you for reading my post, any guidance is appreciated.
Maybe it adds confusion.... For highest safety such limit switches should be connected in such a way that the switch allows motion when not mechanically activated. When the swich brakes the circuit, it means "stop". That way a broken limit switch cable will make the logic stopping the movement.
That's the standard in industrial machines.
Stop means Stop, no reason to run in the same direction any more.
If the limit switch disables motor power directly then another µC controlled relay may break power definitely on the first contact, if a bouncing limit switch seems to cause problems.
Limit switches should be used "normally closed". The motor should stop on opening of the switch, also for added safety. Then bouncing also becomes less important.
Leo..
That is true, but don't forget that "bouncing" also occurs when the switch is opened (un-pressed).
However, if your code is properly structured, de-bouncing in a limit switch application is not necessary.
@Railroader's suggestion is probably the safest solution since there is only one point of failure, the limit switch.
For accurate positioning, you move the stepper to the limit until the switch opens,
then slowly step back until the switch just closes again. If you do that with a step rate slower than debounce time, there is no bouncing problem.
Leo..
So does a "properly-structured" code in this context entail setting up appropriate delays after each reading of the switch status, in order to ensure that the bouncing is over? As far as I understand, the "bouncing" of a switch occurs when, for a very brief period of time, the connection point inside the switch is very close to being connected, and the electricity arcs a little between the two points (feel free to correct me if my understanding is incorrect).
Debounce is not needed as you'll not care after the leading edge trigger. Your sw will either stop immediately, or will reverse off the sw. Either way, bounce is a non-issue.
But you can sense bounce-free using light, capacitance, magnetism and sound. With a piezo disk, you can tell about how hard it hit and when it lets up, release or not. Piezo disks are freaking cool! Think of a capacitor that you can charge by squeezing!
Does the exact placement of the capacitor matter here, in relation to the switch? Can the capacitor be positioned in front of the switch, instead of behind it? My intution would tell me that the positioning does not matter, but I want to be sure.
That's what that website that @GoForSmoke linked goes into detail about. It covers both software and hardware de-bounces, hence why I marked it as the solution. I was just asking because I was curious.
Exactly. In a design 2 buttons starts a several seconds long activity, go forward resp. go backward. By the time the triggered motion is finished, bounces are dead since long.
Contrary to popular belief, putting a capacitor across a switch does not provide de-bouncing, it will only damage the switch contacts and the arduino I/O.
Not what I was trying to say.
I meant that if you write the stepper code correctly,
then you don't need hardware debounce or software debounce code.
Leo..