I have a stepper motor which drives a linear unit. For references there is limit switch on one side.
If i load my programm on my atmega2560 and then i disconnect the usb cable from the computer and then press a start button -> referencing works perfect.
But if i dont disconnect the usb cable -> the programm doesnt recognice the limit switch -> it would destroy something if i wouldnt stop it.
Does anyone have a idea why that happens?
If necessary i can post my code here.
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
Please post a schematic.
Please post an image of your project.
Please describe the problem better then you just did.
In the second pic you can see the limit switch and the stepper motor.
And in the first pic you can see the atmega2560 with the blue usb cable.
if i disconnect this blue cable everthing works fine. if i dont do that, then the programm doesnt recognize the limit switch.
and for the stepper motor, i have a stepper motor driver...
i know you can see more cables on the microconroller, but i dont use them at the moment (i want to controll 3 stepper motors with it)
i cant imagine why it doesnt work when i connect the microcontroller to the computer via the usb cable
I notice that on that last photograph the wires going to the limit switch terminals are just pushed through and are not soldered. This is the best way to make an intermittent / unreliable connection.
Solder them up please.
You seem to be not aware of the difference between a schematic and a photograph. If you truly don't know then ask and we can enlighten you.
This is my schematic. (Please ignore the black parts of the paper)
I found now that the problem just occurs when i connect my laptop to the power supply.
But i dont understand why it happens. (Shouldn´t it just set all the grounds to the same potential?)
And the problem is not the white cable (this power suppy dont has a ground (earth) connection) - the problem is the 24V power supply for the stepper motor drivers.
Is a USB galvanic isolator the best way to solve this problem?
because i think its not the best idea to disconnect the green/yellow cable from the 24V power suppy or from the power supply of my laptop.
The USB galvanic isolator do 2 things. It bricks the problem for ground loops AND it protect the USB from your PC/laptop for over current from outside. It isn't a bad choice to use in testing conditions.
A good stepper driver (like Leadshine DM856 !!!! for fake) uses optical input (opto coupler) that in fact prevent for ground loops.
Edit: for the limit switch you can better switch to ground and use the internal pull up and a NC contact is better than NO. If the cable is broken by NO you never becomes the end point. By NC, if the cable is broken the end point is reached.
Not correct. You don't need another power supply. What is the most expensive? The USB port of your PC of the galvanic isolation? Do you have a galvanic isolator? I have few without problems.
Ground loops are not only in audio a problem. They are everywhere but are not always a big problem.
Well let's disagree on this one. But just a point, how much actually experience do you have?
I have been using microprocessors to make projects since 1975.
Thanks!
In this case you mean with ground the yellow/green cable which goes to the 24V power supply?
I go to the 24V power supply with one black (L1: 230V), on blue (N) and the yellow/green ground (I m not sure if thats called ground in english).