ADC noise problems

Hello forum, I have a problem with noise on my analog lines and I was wondering if anyone had any quick and dirty ideas I could play with. Here is a quick description of what I 'm trying to do.

I have a DC-SS009 3-axis accelerometer which spits out an analog signal which can be read through the Arduino's ADC. I thought I 'd mount it on a platform that is allowed to rotate along one axis and stick two motors with propellers on either end to balance it at a given angle. The whole setup can be seen below.

Now, some more detail. The motors suck around 400 mA when going strong so I power them through an L293 H-Bridge. Now, here is the problem. Motors on the power line do absolutely disgusting things to the voltage level. When powering both my Arduino and the motors from the same source, I have had the Arduino resetting repeatedly.

To counter this, I have kept the Arduino and motor power supplies separate, the motors are powered by a battery (some 10.5 Volts give or take) and the Arduino by the PC through the USB cable. To keep things even cleaner, the logic level voltage needed by L293 is given by a 5V voltage regulator and not by the Arduino 5V pin. This way, the only interaction between the Arduino and the L293 is through two of the Arduino's digital out PWM pins which connect to the corresponding input pins of the L293. To dampen any nastiness in the motor power lines I have added a capacitor on each, connecting it to ground. Battery, voltage regulator, motors and Arduino share a common ground. All this is shown in the diagram below.

If I 'm using my multimeter properly, the capacitors I 'm using seem to be around 3.5 nF. Here they are.

This circuit is the best I could come up with the get rid of noise but unfortunately, it doesn't cut it. Here's why.

The picture below shows the final angle readings I get after processing the ADC voltages. This is the range of motion I have physically allowed the platform and the resolution is not that bad within it. These readings have been taken with the motors off and me moving the platform with my hand. It is sketched in a silly little Processing sketch I have written to act as a crude scope.

The next one shows the same thing (me moving the platform around within its limits of motion) but with the motors on. The noise is beyond terrible.

This one shows the transition to quiet as I turn the motors off. The difference is obvious.

Now, the big question is, where does the noise come from? If it's kicked back down the motors' power supply line and somehow manages to travel through the L293 and up the Arduino's digital output pins there's not much more I can think of doing other than stuffing ever bigger capacitors on the motor power supply line. However, I thought I could be picking up electromagnetic noise through the unshielded lines going to the ADC acting as aerials. I 'm sure the motors must be spitting out some pretty disgusting EM fields around them as they go about their business and the ADC line is just begging to pick it up.

To test this, I disconnected the digital output pins from the L293, completely isolating the Arduino from the motor power supply lines (they still share a ground). I then connected the motors directly to the battery and turned them on and off. The results are shown below. I was quite astonished at what a tremendous amount of noise my unshielded line is picking up (I am also astonished that the platform actually manages to kind of balance, although in a very drunk manner).

So, my big question. Is there anything I can try to get better measurements? The obvious answers I can think of are:

a) get an accelerometer with digital output (I 've got my eye on this one Triple Axis Accelerometer Breakout - BMA180 - SEN-09723 - SparkFun Electronics). Expensive but the best solution I guess.

b) get shorter ADC lines. My cables are certainly longer than they need to be but what happens if for whatever reason I need them to be long?

c) shield them. If I wrap the cables in tin foil and then connect it to ground, will I get any worthwhile effect or would I be wasting my time?

Am I missing something obvious?

Cheers.

I think your noise problem may be vibrations induced by the motors. Perhaps filtering the signal would help reduce the noise.

You can also put series inductors in both motor leads with a capacitor across both the motor and across the other side of the inductors. These should be larger than 3n5, make them 100nF and should be fitted physically as close to the motor as possible. One inch away is too far.

D'oh, I 'm a moron :stuck_out_tongue:

Vibrations!

I simply removed the accelerometer board from the platform and held it in my hand a few millimetres above its position and my "noise" disappeared.

Thank you so much guys, Grumpy Mike's tutorial is excellent reading, straight to the point. I 'm glad you pointed me to it.

Hello again, I 'm trying to make a sketch of all the advice I got in this thread so that I can visualise it and perhaps help some poor sod in the future. So, this is what I have come up with.

KE7GKP:
Killing the motor noise requires putting the capacitor(S) DIRECTLY at the motor terminals. Even three capacitors, one from each terminal to the motor case, and one across the terminals. And likely significantly larger value capacitors.

I have added cap C1 across the terminals and C2 from each terminal to the case. Some ballpark figures (and ballpark value ranges) for these caps would be welcome.

KE7GKP:
Also, bypassing the H-bridge chip itself would be advisable

This I don't understand. I need the H-Bridge to supply the thirsty motors. What do you mean by bypassing it?

Grumpy_Mike:
You can also put series inductors in both motor leads with a capacitor across both the motor and across the other side of the inductors. These should be larger than 3n5, make them 100nF and should be fitted physically as close to the motor as possible. One inch away is too far.

I have added the series inductors (L). I guess "across both the motor" means C1. However, I don't understand what is meant by "across the other side of the inductors". Other side of what? Should I add caps in parallel with the inductors (Ca?)? Connect them across the power line gap (Cb?)? My guess is the latter, since it would serve the same purpose as the 47 uF cap in the final sketch in Grumpy Mike's De-coupling tutorial. Have I got that right?

Hello again, I finally managed to try out the suggestions above and I thought I 'd post the results.

Finding inductors was not easy but with a quick trip to a local computer shop I managed to get my hands on a broken motherboard. From this, I was able to get my hands on some inductors and some pretty enormous electrolytic capacitors which came in handy.

So, the circuit was very simple this time. I connected one motor directly to the battery and sampled the voltage (~10V) through the Arduino's ADC after cutting it down to about a third of its size.

Motor, Arduino and battery share a common ground.

I initially sampled it with the motor "raw". This was terrible, the Arduino disconnected immediately when the motor started working. Even worse, because I 'm on Linux, I could keep an eye on current developments via "dmesg". I could see that the FTDI chip was trying to connect but couldn't as long as the motor was running.

I then connected the smallest electrolytic cap I had salvaged from the motherboard straight across the motor terminals. That was a 100uF, a thousand times bigger than Grumpy Mike's suggestion but my biggest ceramics were small. The motor ran like a dream.

My next move was adding a very large electrolytic cap (3300 uF) parallel to the original, bringing the total to 3400 uF. For some reason, the Arduino didn't like that, it reset itself a couple of times when I turned on the motor, although "dmesg" informed me that the FTDI immediately went and registered at the next available serial port (a Processing sketch trying to talk to the chip kept the original port occupied).

I removed the big electrolytic and went on, adding 47nF ceramic caps from each terminal to the case, added inductors and finally added the big electrolytic across the far side of the inductors, taking measurements at every step. This is what the final thing looks like.

And here's a picture.

I then had a look at the data. Here's a graph of sampled voltages with the motor on.

The standard deviations of the signals in every case is on the legend. There is a definite trend for the voltage to settle more as more components are added. However, it seems that, compared to the vast difference I got between the samples of the "raw motor" (where I couldn't even get a sample as the Arduino immediately gave up) and adding the first cap between the terminals, the remaining components did not do much more.

Still, I had fun playing around with the circuit. Thanks again.

My next move was adding a very large electrolytic cap (3300 uF) parallel to the original, bringing the total to 3400 uF. For some reason, the Arduino didn't like that,

It might have been the large inrush current when it was turned on that caused the arduino to glitch. Get the motor running and then switch to it to see if it was this.

Note with large capacitors control is sluggish as the capacitors keep the motor running for a short time after you turn it off.

I did, it was fine switching arduino on with the motor on, and it was fine most of the time if I switched the arduino on first. I only got around two or three resets at, say, around seven or eight tries (and the FTDI chip immediately reconnected to another port) so it was a rather minor glitch compared to the case of the raw motor.

The vibration noise is presumably mostly above the frequencies of interest for balancing the rotors - so low-pass filtering of the accelerometer outputs would be an obvious step, try time constants from 50ms to 200ms or so and see if that helps.