I have a circuit with two Arduinos talking to each other through RS485. The master (Arduino Mega) sends commands to the slave (Arduino Uno), and the slave drives two stepper motors in response to the commands.
It mostly works well, but when both motors are stepping slowly, some garbage characters are received by the master on the RS485 bus, and I can't work out where it's coming from. It only happens when both stepper motors are running at low speed, which is when the motors are at their maximum current draw.
I've attached the schematic of the parts I think are relevant.
The whole system is powered by a 12v 7.5Ah sealed lead-acid battery, so there's no noise coming from there, and the battery has plenty of supply. The motors draw a maximum of 200mA each, and are full-stepped - no microstepping. Each of the motor driver ICs has a 0.1uF caps directly across the 5V supply lines, and the motors have a dedicated 7805 voltage regulator to power the motor coils.
The MAX485 is powered by the 5v supply from the Arduino board, and running at 9600 baud. Everything apart from the arduino is soldered on to a prototype shield on top of the Arduino.
I have tried soldering larger caps across the stepper motor drivers (double up with second 0.1uF), but didn't seem to make a difference. I tried a 10uF electrolytic on the output of the voltage regular - no difference. I tried running the 12V supply separately from the RS485 lines - no difference. (Ground line was still running with the RS485 lines). I've grounded the inputs to the unused channels on the driver ICs.
Where do you think the noise might be coming from, and what should I try next?
It mostly works well, but when both motors are stepping slowly, some garbage characters are received by the master on the RS485 bus, and I can't work out where it's coming from. It only happens when both stepper motors are running at low speed, which is when the motors are at their maximum current draw.
Have you tried disconnecting the motors, and running the sketch such that a low speed is commanded? That would rule out a software problem. Or, temporarily power the motor circuit from a separate 5V supply.
You don't have any capacitors on your 7805. Well, there is only one on the load side. That is bad. The requirements are critical, you need to have certain values and they need to be located near the IC. If you don't it can oscillate. It's also a hugely wasteful regulator for this job, more energy is wasted in heat than reaches the motor. Is it heatsinked? How? How hot does it get?
Also what does your ground topology look like? If ground conductors can not carry sufficient current, and/or there are ground loops due to sharing of motor and CPU or I/O ground return paths, there can definitely be cross talk.
Planning on doing a lot of this kind of work? Invest in a scope. A PC based scope is cheap nowadays.
Not only are you wasting more than half your power by using a linear regulator you are also drawing more than twice the current you need to through your 10m of cable, with the associated voltage drop. If you use a buck converter you will draw less than half the current and thus drop less than half the voltage you are dropping now. Capacitors are essential across the 12V at the input to and the output of the converter. If in doubt add more capacitors.
surfdabbler:
Where do you think the noise might be coming from, and what should I try next?
There is going to be coupling between the wires in the cable. Specifically, a shift in current draw on the power/ground pair, as with a slow moving stepper motor, will couple with the RS485 pair. It would be better to use twisted pair for both of these to reduce cross talk. If all you have available is the flat cable you could test this by running power/ground and RS485 over separate cables and twisting each.
Kudos for showing a schematic that has sufficient detail on the cable wire type to be able to identify and point out this as a potential issue!
Thanks for all the suggestions. There's some great ideas there.
I had assumed the MAX485 board has included the termination resistors, but I will check this and make sure.
I will add caps to the 7805 on input and output. I tried already with the 10uF on the output, but I'll try larger caps, and on the input as well. (Now I'm thinking about all my other projects where I've used 7805 without any caps... )
I can actually drop the supply voltage down from 12V, so I'll do this to save electricity. The motors are only running for short periods, and nothing gets hot, but no sense wasting electricity. Originally I needed 12V for other reasons, but I can get away with less. If I was using a buck-converter, then maybe it would actually be better to leave it at 12 to reduce the line current, but as I'm just using a 7805, I'll try dropping it.
I tried running the system with the motors disconnected, and this gets rid of the spurious data.
In a few weeks I might be able to get access to an oscilliscope, so I'll try that if I don't have any success before then.
I don't need a scope to tell you the motor is inducing spikes on the 5V power.
What you are doing is just not done. Motor power
and logic power should be 100% isolated from each other. A common GND is fine but that's where it ends.
If you’re using modules, the 120 ohm bus terminations are installed as well as bypass caps. You used the pinout of the IC’s so I figured you had bare chips, not modules. Details do matter when you ask for help since we only know what you tell us.
I would expect it is your wiring as grounding most often done incorrectly with motor circuits. My comment #2 in post #2 still stands.
WattsThat:
If you’re using modules, the 120 ohm bus terminations are installed as well as bypass caps. You used the pinout of the IC’s so I figured you had bare chips, not modules. Details do matter when you ask for help since we only know what you tell us.
There is also the labeling, "U3 MAX485" ... the U designation is always an IC identifier by convention. I would never draw a module in a deceptive way like this even if I know, since it might even confuse myself 6 months down the road.
To be more specific use twisted pair for RS485, and don't run it in the same cable as high-current power wiring.
You'll have no issues if you follow this standard practice. If you have to run the cables together, use shielded
twisted pair for RS485.
Having flat ribbon means you have very strong coupling between the power wires and signal wires - having a
few more wires so you could have ground wires between power and signal might have worked, but without
any screening between the high current and signal wires means you have strong cross-talk.
There is also the labeling, "U3 MAX485" ... the U designation is always an IC identifier by convention. I would never draw a module in a deceptive way like this even if I know, since it might even confuse myself 6 months down the road.
I thing what he is saying is the IC name should never be in the designator field. It is always "U?".
The name of the IC can be a separate text label somewhere away from the designator label.
It's the same as putting the name of a transistor in the "Q?" designator field. I would put the "U?" designator
in the middle of the IC and the IC name two lines below that.
Another thing, if motor and RS485 share a ground, the motor current can induce voltage spikes in the RS485 ground because the ground has to pass motor current and any resistance in the wire translates into a voltage. That could be a problem, no matter how the wires are laid out physically. You should try running a separate ground return wire for the motor and for the RS485.
Hi,
What looks a bit worrying to me is the 12V power supply is along side the 485 pair and the gnd to the 485 modules shares the pulsing load current from the steppers.
As suggested a separate 12V supply cable and twisted cable for the 485.
As you add "future devices" the load/current on the 12V supply wires will increase.
How far apart will the units be?
I realised that the 'noise' data was happening when no data is being transmitted. When data is sent through the cable, it always gets through. The MAX485 module already had 120 ohms between the A and B lines, but no biasing, so I've added 680 ohm biasing resistors to the 'master' end of the RS485 lines, and it's fixed it! I'm not seeing any noise data anymore when the motors are running.
I've also improved my protocol to include a "Start of transmission" character, so that any spurious data that precedes this can be discarded. This also makes it much more robust, and was actually solving the communications even when the noise was still there. I've also bought some buck-converters to convert the 12v line down to 5v, so it will be more efficient, and pull less current through the supply line when the motors are running, and also have better smoothing.