
Can PWM interfere with I2C?
#1
Posted 03 March 2012 - 11:30 PM
#2
Posted 04 March 2012 - 02:06 AM
I know that switching (pwm) can be very "noisy" so it sounds like you got interferenceAs soon I starting using PWM to drive a motorshield the reads on the ITG3200 lock up (never return)
I'm no expert in impeding interference but I think decoupling capacitors with values depending on switching frequency would help. I'm sure someone else knows this part much better than me.
#3
Posted 04 March 2012 - 03:19 AM
#4
Posted 04 March 2012 - 06:59 AM
Hi
Probably the quickest test you can do, is to disconnect the load from the shield and see if it the I2c still locks up.
Another quick check (that you have probably already done) is to make sure that the pins you are using for the gyro aren't the pins you are using for the motor shield.
Good suggestion indeed.
My suspect is on how the wiring has been made. Since the motors suck a lot of current, and that's pulsing, you should pay attention on the ground.
That's because the ground is the way on where the current "returns", but it's also the way on where the I2C signal returns.
Watch at the attached picture. There are two circuits, and they looks almost the same: the connections and the components are identical.
On the left side there's a battery that provides power for the load (e.g. motors) on the right side. However, any wire has its own resistance, especially if it's long yet thin. These resistance are depicted on the top and bottom wiring.
There's another generator VS which is the signal of the I2C, and a meter which should "read" that signal correctly.
On the upper circuit, the ground is just one wire shared with both the load and the I2C signal.
Just to give the idea, let's use some number. The wiring resistors could be 1 Ohm each, the battery voltage 10 Volts, and the load 10 Ohms.
The current flowing through the battery->load->battery link is:
I=10 V / (10 Ohms + 1 + 1) = 0.83 A
However, the voltage on the lower lead of the load is NOT zero (i.e. ground), but there's the voltage drop caused by the bottom resistor. That is:
0.83 A * 1 Ohm = 0.83V
But this drop is actually involved in the I2C signal link, so the meter reads the original signal, PLUS the stray drop.
That obviously leads to a wrong read.
Now check the bottom circuit. The only difference is on where the ground is connected, and there are *two* wires, instead of one.
Better: there are still two links, one for the load, and one for the I2C, but they do not share any resistor.
Thus, the voltage drop on the below resistor is still present, but won't interfere at all with the signal link.
Hope it helps.
Cheers
Attached Files
#5
Posted 04 March 2012 - 09:24 AM
After reading Hanzibal's suggestion, I tried a 10uF capacitor between the power line and the ground line of the gyro but that didn't seem to work. I only had the 1 cap so I couldn't try a different capacity cap.
Magpie, I am using the pwm pins for the motor controller and the I2C pins for the gyro so I don't think that I've got a problem there.
When I disconnect the motor controller entirely but still drive the PWM pins, there doesn't seem to be a problem. So perhaps as Mario said, there's a problem in the wiring.
My setup is:
- a 6xAA battery pack which is split between:
- Vin/Gnd on netduino+
- Vin/Gnd on a 5V (3A) voltage regulator
- the output of the 5V voltage regulator is split into
- the power input of the motor controller shield which drives 2 motors
- the power input of 2 x micro servos for a pan and tilt bracket
- the power input of a parallax ping sensor
- an I2C ITG3200 gyro which is powered from the 3v3 from the netduino+ (and connected to a netduino+ Gnd)
I'm not sure if it's possible but I'm going to try and wire it up in such a way as to resemble Mario's 2nd diagram.
I also was wondering whether I'd be better off getting a serial to PWM controller to generate the PWM signals but if it's a wiring issue then I'd probably see the same thing anyhow.
thanks
#6
Posted 06 March 2012 - 09:15 AM
#7
Posted 06 March 2012 - 11:00 AM
#8
Posted 06 March 2012 - 11:41 AM
#9
Posted 06 March 2012 - 12:43 PM
Basically we need to reduce the magnetic coupling between your shields high current noisy wires and the I2C stuff.
First I would try to identify the noisy wires, and where they are both switch and carrying the most current. It would be everything from the motors back to the chip outputs. for each coil. Including the ground path. Re Marios diagram. It is really only the high current wires that are switching that are the problem, not so much the voltage supply. Though a decent cap near the motor drivers Vin pins wouldn't hurt.
Secondly I would identify everywhere the I2C wires are travelling. Even if it is through parts of your system that they don't carry any current, ie dead ends.
I don't think you need to worry so much about the ground path for this bit.
These two parts need to have their coupling reduced.
Classic ways to do this are:
- keeping them separate. Maybe unstacking the stack, somehow.
- keeping them separate. Running looms in different paths, definitely not parallel and lying alongside.
- twisting the wires going off to the motor as separate pairs. (just like Cat 5/6 cable)
- putting a steel shield between them.
- Try different frequencies of either I2C (if you can ) or PWM.
ps. I am glad you are having this problem, only because its reminded me how noisy the shields are.
I am trying to lay out a High Powered Led shield right now. And I am trying to minimise these types of problems.
SteffShield
#10
Posted 06 March 2012 - 12:44 PM
#11
Posted 06 March 2012 - 01:28 PM
#12
Posted 06 March 2012 - 08:54 PM
Hi Magpie,
Following up on your advice, I read a bit about voltage changes induced by high current wires that aren't even part of the same circuit and one of the things they suggested was to coil/twist the high current wires around each other. I tried this (and also moved them marginally further away from the rest of the circuit) and immediately there was a difference. The gyro didn't lock up the first time but ended up reading wacky values progressively. The 2nd time it locked up still but it got alot further than usual. So it would seem to be almost definitely induced interference. I didn't have any 0.1uF capacitors to run across the motor terminals which they suggested as well. The combination of twisting the wires and keeping them further away and the caps hopefully will be enough to allow me to get this working. If not maybe I'll have to get some low current motors instead.
thanks
Is there anyway you can shield things? Either by putting a shield around your control boards, or around your motors. A cheap and easy way is a Faraday cage. You can build one pretty easily with some aluminum mesh from the hardware store. Look in the window screen section. Be warned, its a real pain to work with, and you will need to have something like tin snips to cut it.
If you fully enclose either your motors or driver boards, you should see your interference go away.
-dan
#13
Posted 12 March 2012 - 10:58 AM
#14
Posted 12 March 2012 - 05:34 PM
Hi everyone,
I did a bit of rewiring, replacing alot of 12" jumper wires with shorter length breadboard jumper wires. This seems to have gotten things working well enough. Magpie I didn't end up trying different frequencies for the pwm or I2C but I'll keep that in mind if it comes up again. Thanks for the advice Dan, I hope I won't have to resort to a Faraday cage for this project but who knows. It would be nice if you could buy some shielded cable sheaths though, has anyone seen anything like that?
thanks
Buying shielded cable will probably run you a pretty penny. A much cheaper option is get some RG-6 (coax), and carefully strip off the outer plastic shield, then pull out the inner solid-core wire and plastic tube. So what your left with is a braided tube of copper wire. I have used that in the past to make cheap DIY shielded cables.
-dan
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users