0

Odd M4 Motor Encoder Interrupt behavior.
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Odd M4 Motor Encoder Interrupt behavior.

by in2infinity on Mon May 03, 2021 3:23 pm

I've designed a custom board which uses an Itsybitsy M4 running board mounted DRV8871 drivers to turn DC motors which have rotary quadrature encoders. The board is setup to drive up to three motors. I never have more than 1 motor running at a time - they essentially run in sequence - motor 1 run to X encoder counts, delay, motor 2 run to X encoder counts, delay, motor 3 run to x encoder counts. Then I have them all run in reverse sequence back to encoder count 0.

I got the code working just fine with one motor using the EncoderStepCounter library and interrupts set on pins 12 and 11 - which is my motor port 1. Motor port 2 sensors are on pins 3 and 2. I can adjust the code to run a single motor off either of the first 2 ports with no problems (haven't got to port 3 yet). When I try to scale it up to 2 motors, weird things start happening. Motor 1 always works going up, but misses counts going back to 0 (I'd say about 75% of counts). Motor 2 doesn't always count up (it stops counting randomly about 10% of the time - like it looses connection with the encoder). When it does count up to completion, it always counts back down fine.

Using the serial output I can see that counting up, the interrupts are called correctly. Interrupt 1 is called when motor 1 is running, Interrupt 2 is called when motor 2 is running. On motor 1, the position variable notes a +1 change every other cycle. On motor 2, the position variable notes a +1 change every fourth cycle (switching the motors does not change this so it not motor specific) When the motors are reversed, interrupt 1 is called by motor 1, but interrupt 2 also fires about 2 - 3% of the time. It also fails to see the motor position change. So, the position variable for the sensor comes back 0 (no change) 99% of the time, which accounts for the slow counting.

No matter what I do in the code, I always get the same result. I went so far as to reverse engineer the EncoderStepCounter library back to regular routines in the main program, duplicate and isolate them for the two motors and I always get the same result.

Is there anyone out there that has gotten multiple motors with encoders to work with an M4 who may be able to help me track down my problem?

in2infinity
 
Posts: 7
Joined: Mon Nov 25, 2013 2:20 pm

Re: Odd M4 Motor Encoder Interrupt behavior.

by in2infinity on Tue May 04, 2021 6:20 pm

Out of frustration I decided to scrap the interrupts and just run the motors/encoders using the EncoderStepCounter library directly through while loops. Doing that, all three motors count correctly.

Not sure what it is about the interrupts, but they are definitely wonky if you plan to use more then 1 encoder.

in2infinity
 
Posts: 7
Joined: Mon Nov 25, 2013 2:20 pm

Please be positive and constructive with your questions and comments.