Optical sensor... blasted EMI :(

I have an optical interrupter triggering an interrupt on the Arduino as part of a miniature rolling road for slotcars. The interruptor is triggered in turn by a small DC motor turning over via the wheels of the slotcar. The code works great. In fact it all worked great until...

I put my more powerful cars onto it and their road speed jumped 10 fold to the other cars. Its not the cars super performance I'm sorry to say but the EMI coming from these motors is generating spurious signals. I've knocked the circuit down to a single piece of wire, I've put my scope on the wire, I've wrapped the wiring with tin foil, I've put brass plate and lead plate between the motor and wiring and still its getting these pesky blips on the signal. If I move the motor about 6 inches away it settles down.

But I can't move the sensor further from the motor :(. I am STUCK. I hope there is some sort of electronic cleverness I can do to this setup. Any help please.

Cheers Alan

Have you tried putting some capacitors across the terminals of the motors on the cars.

KenF:
Have you tried putting some capacitors across the terminals of the motors on the cars.

Yes. However, not everybody at the club does or would do this anyway so isn't really an option in any case.

A large part of the problem is that the new hand controllers use PWM to power the motors and this is causing some of the EMI above and beyond the motors own (I think i - I can see all sorts of stuff going on on my scope including the PWM from my TruSpeed and Slot.It).

Have you tried twisting the pair?

Paulcet:
Have you tried twisting the pair?

Which pair? There are three wires effectively from the four coming from the sensor as two are both ground. Two others are 5v with resistors and the fourth is the signal straight into pin2.

Wild thought...

Take two inputs into a comparison thingy (okay this may not be the technical term). One is simply a wire which is effectively an aerial picking up this blasted EMI.

The other is a similar bit of wire but with the sensor attached and hopefully it will have the same signal on it as the plain piece of wire plus the sensor signal.

Subtract one from the other and feed this into pin2...

Is this madness or is there some mileage here and if so what is the magic thing that does the subtraction?

I'm rather confused by "small DC motor turning over via the wheels of the slotcar"

Could you describe this setup in a bit more detail? Also what is the length of the input wires to the arduino.

Your wild thought is almost like "differential input". Not so wild, but it won't be that easy. As to twisting the wires, try the ground and signal wires twisted together. About 1-2 twists per inch.

This photo shows the arrangement. I have taken it all apart and starting again as I trashed the photo interrupter.

The slot car rests on the wheels with the gear and the white marker. As the wheels of the slot car go round they drive the second set of wheels and the white marker passes the photo interrupter generating a signal picked up by the Arduino interrupt routine attached to pin2.

The photo interrupter is a KTIR0811S Sub-miniature Photointerrupter. The wiring is shown in the other photo. I played with the resistor settings to adjust the sensitivity of the sensor (nothing to do with its ability to filter out the EMI). I ended up with 220ohm and 10Kohm.

I have tried plain wire and shielded wire (a shielded USB lead). I have also tried putting the Arduino into two! metal boxes and still doesn't stop it. Cuts it down though. Distance is the only saviour and the most 'noisy' motor seems to need about 12" to clear it away. The mains hum seems to be cleared away when the sensor is correctly wired in with its resistors (fortunately).

The background signal is 50Hz and my test sketch picks this up reliably which is all the mains hum in my man-cave. So the hum is capable of generating more than 200/1023 x 5v worth of signal otherwise it wouldn't trigger the interrupt service routine. The wire for this test when just a wire plugged into pin2 is about 9 inches long. Longer than I need but a more demanding test situation.

The Arduino and the slot car are not sharing any of the same circuitry.

Paulcet:
Your wild thought is almost like "differential input". Not so wild, but it won't be that easy. As to twisting the wires, try the ground and signal wires twisted together. About 1-2 twists per inch.

Can you provide a little more info about this please? Some pointers to the right reading or devices would be useful although a fully developed and tested circuit diagram with fully debugged sketch would be good too (just kidding :wink: )

Paulcet:
Your wild thought is almost like "differential input". Not so wild, but it won't be that easy. As to twisting the wires, try the ground and signal wires twisted together. About 1-2 twists per inch.

I have tried a twisted test using my 'aerial' attached to pin2 and wound with wire attached to GND. No slot cars running just sitting in my man-cave.

The result is at least the 50Hz mains hum but times as much as 72 Hz so it is now picking other spurious signals :frowning:

Ah a ROLLING road. I should have been paying more attention. It could be worth seeing what happens if you power the UNO with a battery.

KenF:
Ah a ROLLING road. I should have been paying more attention. It could be worth seeing what happens if you power the UNO with a battery.

I use the serial out to see the values... I'd have to configure an LCD.

However I'm not convinced about whether a battery would solve the problem - is this something you've seen before or just a hunch?

acboother:
Can you provide a little more info about this please? Some pointers to the right reading or devices would be useful although a fully developed and tested circuit diagram with fully debugged sketch would be good too (just kidding :wink: )

A little light reading:

Some example circuits:
http://www.analog.com/library/analogdialogue/archives/46-10/single_ended_to_differential.html

acboother:
I have tried a twisted test using my 'aerial' attached to pin2 and wound with wire attached to GND. No slot cars running just sitting in my man-cave.

The result is at least the 50Hz mains hum but times as much as 72 Hz so it is now picking other spurious signals :frowning:

Do you mean to say that the 50Hz mains interference is lower than untwisted? The 72Hz signal is curious... I don't know what to say. :frowning:

50Hz untwisted... 50+Hz varying twisted

Low frequency interferance is far more likely to be transmitted by conductors rather than airwaves. Hence my suggestion of testing with a battery, in an attempt to discover which pathway the noise is taking to get to your arduino.

Paulcet:
A little light reading:
http://en.wikipedia.org/wiki/Differential_signaling

Some example circuits:
http://www.analog.com/library/analogdialogue/archives/46-10/single_ended_to_differential.html
Do you mean to say that the 50Hz mains interference is lower than untwisted? The 72Hz signal is curious... I don't know what to say. :frowning:

That looks interesting... I'll study that in the morning when my brain is awake again.

KenF:
Low frequency interferance is far more likely to be transmitted by conductors rather than airwaves. Hence my suggestion of testing with a battery, in an attempt to discover which pathway the noise is taking to get to your arduino.

I'm connected to the PC with a USB cable. Do you think its creeping in that way?

If so why does it stop picking up the mains hum, for instance, when there is no wire in pin2 even though I'm still running the same code and waiting on those interrupts?

The mains hum seems to be cleared away when the sensor is correctly wired in with its resistors (fortunately).

I'm not sure I understand the problem statement. Once aspect of the problem appears to be continuous background "mains hum" at 50 Hz triggering the interrupt Another aspect seems to be pulses coming from pwm motor driver/controllers. Another noise seems to be coming from the motors themselves. Can you help break this down for us?

The signal you want from the optical sensor should be both of a frequency and duration as the white window goes through the slot. Can you detect a rising and falling edge? One thought I had is that you could only count pulses of a certain duration, which would be a function of rpm, and only count pulses occurring at certain intervals which also would be a function of rpm. Filtering in software does not sound easy, but if you can't get there with hardware you might have some options.

cattledog:
I'm not sure I understand the problem statement. Once aspect of the problem appears to be continuous background "mains hum" at 50 Hz triggering the interrupt Another aspect seems to be pulses coming from pwm motor driver/controllers. Another noise seems to be coming from the motors themselves. Can you help break this down for us?

All of that is going on. Mains hum seems to disappear or be consumed somehow, once the circuit is properly connected to the sensor but worries me about its existence just in case it is slipping through or may do in another environment (that is not my man-cave).

I think (but its a guess) that the motor EMI is worsened by the fact that it is receiving PWM from the controllers. I can see mains hum, spikes and PWM traces when I connect up my 'scope with the same "aerial" as I use with the Arduino.

Using a non PWM, traditional rheostat, controller still has problems.

What sort of "breaking down" do you want? Give me an example please.

The signal you want from the optical sensor should be both of a frequency and duration as the white window goes through the slot.

That's right

Can you detect a rising and falling edge?

Yes, no problems.

One thought I had is that you could only count pulses of a certain duration, which would be a function of rpm, and only count pulses occurring at certain intervals which also would be a function of rpm.

I'll look into the mathematics of this one. My worry is the noisy signals are themselves a function of motor rpm which is effectively what I'm recording so cleaning these out may be quite difficult.

Filtering in software does not sound easy, but if you can't get there with hardware you might have some options.

I'm going to look into using the diff amps as proposed earlier.

Another solution is to move the slot car about 75cm away from the sensor which is doable but hardly a very elegant solution.... and not something that will fit inside my pit-box without making it foldable.