How to damp noise from a motor

I’m using the SparkFun [motor driver to run a [12VDC worm drive 40 RPM motor to lift a doll elevator in a Barbie house I’m building for my granddaughter. To track the position of the elevator I have a [600 pulse/rev rotary encoder. Both the motor and the encoder work perfectly – when used separately. The plan is to connect the shafts (with a spool that holds the lift line between them), so I can use the encoder pulses to measure the movement.

When I run the motor, though, without the shafts connected, so the encoder isn’t moving at all, it causes noise on the encoder phase lines, enough to cause some false pulses to register. When the shafts are connected, the resulting pulse sequence is very noisy (as seen on an oscilloscope), and the pulse rate is far higher than it should be, 50% to 100% higher (and highly variable).

I’m powering both the motor and the encoder with 12VDC from the same power supply (currently a bench supply). I’m controlling everything with a particle.io Photon. I’m not using the Photon’s internal pullups because they’re 40k and the (scant) docs on the encoder say 2k is needed. I tried the internal pullups and it seemed to work about the same.

It’s wired as follows (I can create an upload a schematic a little later if that’s needed):

+12V to motor driver VM and encoder Vin

-12V to motor driver GND and encoder GND

Motor driver A01 and A02 to motor.

Encoder phase A to A0, configured as INPUT, with ~2k pullup to 3V3.

Encoder phase B to A1, configured as INPUT, with ~2k pullup to 3V3.

Driver PWM, AIN1 and AIN2 connected to D2, D3, D4. (D0/D1 are used as I2C SDA/SCL for running some other stuff).

I think what I need to do is somehow prevent noise from the motor from leaking back through the motor driver and into the input power on the encoder, but my actual electronics knowledge is sadly lacking (I’m a software engineer, just beginning my remedial electronics education).

Suggestions? Do I need to do something else to more fully diagnose the problem? I have an oscilloscope, as mentioned.

Thanks.](Amazon.com)](Amazon.com)](SparkFun Motor Driver - Dual TB6612FNG (with Headers) - ROB-14450 - SparkFun Electronics)

So… this is interesting.

I was counting pulses in an interrupt handler. This seemed like the obvious way to do it, since it would mean my loop() wouldn’t have to be very fast to avoid missing pulses. After trying lots of random things, I decided that, just for completeness, I’d try counting by calling digitalRead() in loop() – and making sure that loop() was sufficiently fast.

It works. At least there are no bogus pulses when the encoder shaft isn’t being spun.

The pulse rate I’m getting is a bit fast; I have a 40 rpm = 2/3 rps motor spinning it, and the encoder is 600 ppr, so I’d expect 400pps and I’m getting a little over twice that. Manually timing the rotation shows it’s actually rotating at about 43 rpm, which is very close to half what I’m reading from the encoder.

So… I think this is working. I’m confused as to why the interrupt gets triggered more than it should. I could see the lower sample rate of counting in loop() resulting in fewer extra pulses if there are short-lived, noisy transients in the signal, but it should still see some if they’re actually in the source signal. With the oscilloscope I do see noise in the signal that isn’t present when I disconnect the motor.

I guess this could work. I’ll just have to write my loop() so that it samples the encoder on every iteration but only occasionally samples I2C sensors, since performing I2C transactions is slower (and I’ll crank up the I2C bus rate to max to make them as fast as possible). But I’m confused about why I see the extraneous interrupt triggers, but don’t see extraneous pulses when I poll the pin.

Any idea?

Could be EMI from the motor.

If you rotate the encode manually, does it count correctly?

You might try the recommendations in the link below to see if that helps.

https://www.pololu.com/docs/0J15/9