Need troubleshooting help

I have a Mega that is providing signals for a stepper driver and receiving feedback from a limit switch.

The sketch controls the stepper to drive until it reaches the limit switch and then reverse slowly until it just breaks continuity with the limit switch and then stops.

The problem I have is that once the stepper reaches the limit switch it does sporadic things.
-Sometimes it drives past the limit switch as if it did not see it, but then stops shortly after on its own.
-Sometimes it drives to the limit switch, stops, reverses, but continues driving away even after the limit switch is released.
-Sometimes it works properly and drives to the switch, reverses, and just comes off the switch.

I have checked the limit switch, it seems to be working properly when disconnected. When connected it shows a very minute amount of continuity which I believe is through the Mega board itself (other limit switch channels show the same level of "noise" and have not given any trouble).

When running the sketch and checking continuity across the ground and signal pins on the Arduino it shows the limit switch open as it should and then closed when the stepper reaches it, and then open again as the stepper drives off or over the switch.

It's almost like the Arduino is shown the proper signal and chooses to ignore it. I'm stumped.

I know everyone's first reaction is either going to be to show the sketch and/or wiring diagram and/or to check my grounds.

This project is work related so I cannot share the sketch or diagram and I have checked all grounds on the entire system. I have recompiled code and reflashed the Mega a couple of times (it often works properly one time after a reflash) and this sketch has worked many tens of times prior with no issue.

Is it likely that the Mega in question has some internal failure or short that could be causing this? Could it be the code is getting corrupted somehow?

Any suggestions would be appreciated.

You are correct. We would need to see the code.

My thoughts on it are..

  • Yes electrically (hardware wise) tings may be working right.... but if you ARE NOT CHECKING things correctly.. then you may miss the event/interaction.

So are you doing any blocking type of events? where a 'check' for the limit switch is missed?

If this EXACT same code (ie: "this sketch has worked many tens of times prior with no issue.") works on another MEGA.. then it hardware related to that specific MEGA board.

You can easily rule that out by testing with a different board.

How far are the switches from the processor? What value pull up (or down) resistors are on the switch inputs?

I would write a small script to test the software logic of the switch.
Do you poll? How often? Use interrupts? Debounce the switch?

If the software already solves the problem you know you need to analyse your complete script. If the issue persists you need to have a look at the hardware. Check the pull resisitors first. Smaller resisitor means stronger pull but requires more current. Sometimes the internal ones are to weak and you need external.

How about you reduce the circuit diagram to show us just the switch and some rough idea what you have connected. e.g. number inputs and outputs used? Add some pysical properties e.g internal/external pull up/down, resistor value, cable length, voltage, …

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile:

@TomGeorge
He mentioned that this is work related stuff… and can not post it unfortunately… :frowning:

And, so far, seems reluctant to answer questions or respond to comments.

groundFungus:
And, so far, seems reluctant to answer questions or respond to comments.

Well, nothing unusual about that! :astonished: Par for the course I would say ...

Are you using the "Delay" function? It is a blocking function which means when your program executes Delay the program just stops and sits there waiting for the delay function to time out - - try mills if you are using delay

Show us a minimally-viable portion of your code that reads the limit switch and drives the motor. Reading a switch and driving a motor is not proprietary.

Eric1371:
This project is work related so I cannot share the sketch or diagram and I have checked all grounds on the entire system. I have recompiled code and reflashed the Mega a couple of times (it often works properly one time after a reflash) and this sketch has worked many tens of times prior with no issue.

Any suggestions would be appreciated.

Can I suggest you post a circuit diagram, even if it is just showing how you have the limit switches wired to the Mega.

Have got pullup or pulldown resistors fitted to the digital input pins of the Mega that the limit switches are connected to?

If not then you need them, the input pins are high impedance, if you leave then open circuit when the limit switch is open, then they will signal to the controller any level ,HIGH or LOW.

So if you have the limit switching the controller input to 5V, then you need a 10K resisitor from the controller input to GND to make sure the input goes from HIGH to LOW.

If you have the limit switching the controller input to gnd, then you need a 10K resisitor from the controller input to 5V to make sure the input goes from LOW to HIGH.

Can you tell us your electronics, programming, arduino, hardware experience?

Tom.... :slight_smile: