Stepper is resetting my arduino code

I am using arduino uno R3 to build an inverted pendulum project. in my project, I am using 1. TB6600 4A 9-42V Stepper Motor Driver 2. Stepper Motor Nema 17 Bipolar 1.7A 3. (2)Optic encoders and a relay and some swithces

I am using the tone() funtion to run the stepper at different frequencies. the problem is that at low frequencies, I do not have any issues but at high frequency close to 15000, the arduino code resets.

I am using microstepping (1/8). offcourse when I double the microstepping to 16, the issue would be at around freq=30000 for the tone() function.

I increased the current to my driver from 1 to 4 and the voltage from 20 to 30, but the frequency of 15000 that caused the issue did not change.

In order to troubleshoot, I disconnected the power for the driver and ran the code by itself, it did not have any issues or limitations. it seems like the driver is causing the arduino to crash. maybe noise. please let me know if you have any ideas on what could be causing this.

Also another trouble shooting was: I took the load off the stepper motor and ran the code, in this case I did not have any issues neither, so it seems like the high torque on the motor causes issues.

Regards

What does Your power supplying look like? Attach a drawing and specifications. Your description and Your tests looks like a pwr suåply problems. Have You tried using the full mechanical load and check for the maximum frequency then?

Attach Your code for the other experienced members.

A diagram showing clearly how everything is connected would also be useful. A photo of a simple pencil drawing will be fine. See this Simple Image Guide

Why have you chosen to use the tone() function ?

...R Stepper Motor Basics Simple Stepper Code

Here is a drawing of my circuit.
My power supply is a eventek kps305D which provides variable 0-30 VDC and 0-5 A.
Also the 15000 freq issue that resets my code is when I am applying mechanical load, without the mechanical load, I don’t have any issues other than maximum rpm.

The reason that I using tune() is because I have to run code while the motor is getting a specific pwm. i.e I need the timer to do its job without interrupting my code.

If there is any other library that does use the arduino timer and runs parallel to my code, that will do the job.

Hi,
OPs diagram;
369ae78477eb816f16a411e118aef1634eb292d2.jpg

What is the relay and how are you controlling it?
I see no gnd return or driver transistor.

Tom… :slight_smile:

TomGeorge:
Hi,
OPs diagram;
369ae78477eb816f16a411e118aef1634eb292d2.jpg

What is the relay and how are you controlling it?
I see no gnd return or driver transistor.

Tom… :slight_smile:

I didnt think that is necessary to explain.
This is my relay link. Idk what you need to know about this.
https://www.amazon.com/gp/product/B072BY3KJF/ref=ppx_yo_dt_b_asin_title_o04__o00_s00?ie=UTF8&psc=1

The relay is a safety switch to disconnect the main power supply. It is powered by it’s own 5v DV power supply and it’s ground is connected to the power supply ground. The controlling signal goes to it’s input thru the arduino which is triggered using a simple switch at the end of my rail. I did not mention the trigger switch in my diagram to keep it simple.

Transistor? I have no clue about this. the driver is connected to the arduino ground. I am not sure about your question.

When the Arduino unintentionally resets, a power/ground problem is the most likely explanation.

However, your diagram is useless precisely because it does not show all the power and ground connections, or properly labeled pin connections.

If you want help, provide the required information.

@karimi67, do not cross-post. Other thread removed.

karimi67: I didnt think that is necessary to explain. This is my relay link. Idk what you need to know about this. https://www.amazon.com/gp/product/B072BY3KJF/ref=ppx_yo_dt_b_asin_title_o04__o00_s00?ie=UTF8&psc=1

The relay is a safety switch to disconnect the main power supply. It is powered by it's own 5v DV power supply and it's ground is connected to the power supply ground. The controlling signal goes to it's input thru the arduino which is triggered using a simple switch at the end of my rail. I did not mention the trigger switch in my diagram to keep it simple.

Transistor? I have no clue about this. the driver is connected to the arduino ground. I am not sure about your question.

That relay module has a transistor driver built in so no problem. But it may need a gnd connection to Arduino. Tom... :)

Here I tried to have better drawn circuit

karimi67: I dont know why it does not let me upload a new image. it says for security reasons can't upload it.

What file format are you trying to upload?

Grumpy_Mike: What file format are you trying to upload?

It is Jpg.

"Your attachment has failed security checks and cannot be uploaded. Please consult the forum administrator."

See this http://forum.arduino.cc/index.php?topic=293955.0

Here is my second try at drawing the circuit



Better, thanks. Where are the required current limiting resistors on the optocoupler inputs (D3, D7 and D8)?

Please post a link to the motor driver data sheet, user manual or product page and a photo of your setup. That will help us decide where the interference might arise (motor and motor power wires too close to the Arduino, etc.)

Hi, Can you post a link to your optical encoders and how are they physically connected in your project?

Can you post a picture of your project so we can see your layout please?

Thanks.. Tom... :)

I did not use any resistor on the motor driver optocouplers. Should I? I will try it out.

I have attached a photo of my messy setup but it is original. that is how I run my tests.

Also as an update: I disconnected one of the optic encoders which is at the end of the rail and that eliminated the issue meaning that I could run the motor untill max reaching max rpm… I don’t know if that is pulling too much current or not. But checking the resistance between its VCC and Gnd, it was in the order of Mega ohms.

encoder link:

Motor and Motor driver link:

One potentially serious problem is the breadboard. Breadboards cannot handle motor current and the tracks will burn if you try. Connect the motor leads and motor power supply leads directly to the driver.

I did not use any resistor on the motor driver optocouplers.

There may be one built in to the motor driver, but there is no useful documentation on the Amazon page.

You should measure the current flowing into the optocoupler input when you apply 5V to it. If is it 20 mA or less, it is safe to connect it directly to an Arduino output pin. Otherwise, use a resistor.

I checked the currents to the motor driver and it was less than 20 mA. got rid of the bread board, no luck.
The only thing that I noticed is that there is 120 mA going to the ground pin of the arduino. The ground pin is shared between the components.

Hi,
Ops pics;
67b42c9ebd7c4372f63625373ead9d68c750ed12.jpg
4c615e1bee3e6e68cfa290de21fca54210146195.jpg
Can I suggest you rewire your project so that the power supply wires for the stepper are well away and separate to the arduino input and control wires.

I see a lot of wires crossing over and being a bit of a nest.

Put the power supply over near the driver and the stepper, not on the other side of your project.
Long power leads with potentially noisy stepper currents produce interference and that can be induced in the Arduino wiring you have it entangled with.

Tom… :slight_smile:
PS Although the power supply voltage is constant, the current is being switched ON and OFF very quickly, a square wave, and this produces electromagnetic radiating noise.