Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Can PWM interfere with I2C?


  • Please log in to reply
13 replies to this topic

#1 spcboog

spcboog

    Member

  • Members
  • PipPip
  • 17 posts

Posted 03 March 2012 - 11:30 PM

Hi all, Hopefully someone can shed some light on this: - Reading from an ITG3200 gyro via IC2 works fine by itself - As soon I starting using PWM to drive a motorshield the reads on the ITG3200 lock up (never return) The motorshield is externally powered. Thanks

#2 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 04 March 2012 - 02:06 AM

As soon I starting using PWM to drive a motorshield the reads on the ITG3200 lock up (never return)

I know that switching (pwm) can be very "noisy" so it sounds like you got interference

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 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 04 March 2012 - 03:19 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.
STEFF Shield High Powered Led Driver shield.

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

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


Biggest fault of Netduino? It runs by electricity.

#5 spcboog

spcboog

    Member

  • Members
  • PipPip
  • 17 posts

Posted 04 March 2012 - 09:24 AM

Thanks everyone for the tips.

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 spcboog

spcboog

    Member

  • Members
  • PipPip
  • 17 posts

Posted 06 March 2012 - 09:15 AM

Hi all, I rewired so that the netduino+ and the gyro don't share any wires with the motor shield on the way back to ground (I unplugged the shield from the netduino+). Unfortunately it still doesn't work. Maybe even with this wiring configuration, the voltage to the netduino is not reliable enough when the motor controller shield is involved. I tried using a 10uF capacitor at various power/ground connections but that didn't seem to fix things. To get around the problem for now, I'm going power the motor controller shield with a separate battery pack. This isn't great but I want to get on with the project in the meantime. Going back to the single battery pack configuration, do you guys think that perhaps powering the netduino+ from a separate voltage regulator might work? So in other words: 1 Battery pack which powers 2 separate regulators: - 1 5V voltage regulator which powers - motor shield - servos x 2 - parallax ping - 1 7.5V voltage regulator which powers - netduino+ thanks

#7 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 06 March 2012 - 11:00 AM

Hi Did you try disconnecting the motors from the shield, and then running the rest of the circuit, including the driver shield? This could tell us conclusively that it is em interference. If is the circuit works when the motors are disconnected but doesn't work when the motors are connected then it is an em interference problem caused by the high currents inducing currents in the rest of the circuitry. If the circuit doesn't work irrespective of the motors then the test will be inconclusive. I dont suppose you have an Oscilloscope? Or one of those bus pirate things.
STEFF Shield High Powered Led Driver shield.

#8 spcboog

spcboog

    Member

  • Members
  • PipPip
  • 17 posts

Posted 06 March 2012 - 11:41 AM

Hi Magpie, I took your advice and tried it with and without the motors connected. The problem seems to only repro with the motors connected. The thing is, I had already disconnected the motor shield from the main battery pack (using a separate pack). With a separate power source, can the high current of the motors still cause issues? Not sure if it's relevant but the 5v logic of the motor shield is coming from the netduino since it is stacked on top of it. thanks

#9 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 06 March 2012 - 12:43 PM

Hi
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.
Basically the coupling is related to the area of the loop which comprises the circuit. This is one of the reasons why wires are twisted to minimise the area. There is always a gap between the conductors but the smaller it is the better.

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
STEFF Shield High Powered Led Driver shield.

#10 spcboog

spcboog

    Member

  • Members
  • PipPip
  • 17 posts

Posted 06 March 2012 - 12:44 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

#11 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 06 March 2012 - 01:28 PM

That's good, it looks like your part way there. Can you change the frequencies? or instead of smaller motors run your motors of a slightly lower voltage, that may help. Keep fiddling around you should be able to find a configuration that works.
STEFF Shield High Powered Led Driver shield.

#12 Dan Morphis

Dan Morphis

    Advanced Member

  • Members
  • PipPipPip
  • 188 posts

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 spcboog

spcboog

    Member

  • Members
  • PipPip
  • 17 posts

Posted 12 March 2012 - 10:58 AM

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

#14 Dan Morphis

Dan Morphis

    Advanced Member

  • Members
  • PipPipPip
  • 188 posts

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

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.