Two limit switch signals affecting each other

interruptsswitches

I'm trying to make circuit which will allow me to sense some platform presence at the ends of some rail.

I'm using the limit switches, here is schematic:

enter image description here

SENS-* signals connected to MCU pins, that is configured to trigger an interrupt on a rising edge of a signal. When I trigger manually only one of the switches – then both interrupts are triggered – right one first and wrong one second. It seems like signal from switches interfere each other through GND line, but I cant figure how exactly.

How to prevent triggering of a second interrupt? I feel, that there is some well known solution, but I could not find it.

Best Answer

Since you are trying to manage mechanical limit switches using interrupts generated from the edge of the signal be aware that you could get multiple interrupts when the switch first closes. This is caused by the bounce of the switch contacts.

Depending upon how the platform limit switches are used in your application you may want to consider a more robust solution that is commonly used in motion control systems. Each end of travel uses two sets of sensing. The first one that the platform would trigger near the end of travel would be one that does not use a mechanical switch. Instead it may be an optical interrupter or an indexing pulse of an optical encoder. Such signal is your logical end of travel and will be much more repeatable in terms of position detect. In fact with a controlled positioner this may be repeatable to the same position each time.

The second limit to be triggered would be the mechanical switches as you have now but connected is an emergency cutout. Such contacts would be wired directly to disable the drive signals to the platform positioner. Under normal operating conditions these contacts would never trigger and there would be some range of platform motion between when the logical trigger and when these emergency switches would engage.

Mechanical switches have a lot of hysteresis in them and will not give a repeatable end of travel position reading when you are using a servo or stepper to control the platform motion.

One final note on the emergency cutout switches. The limit cutout switch for the (+) direction wants to only cut out the drive control of (+) direction stepping. Likewise for the (-) direction of the platform. This is important because it still allows the control system to move the platform away from the emergency stop position to regain control of the platform in recovery positioning.