Strange problem with incremental encoders

I try two BLDC motors with ESP32.

First option:
Encoder encoder_1 = Encoder(34, 35, 1024);
Encoder encoder_2 = Encoder(32, 33, 1024);
Motor with encoder_1 works ok.
Motor with encoder_2 works ok.
But if both motors rotates in the same time, after about 10-20 sec. the current drawn by the motors starts to increase strongly, motors lose synchronization and stop.
The faster the motors rotates, the faster they stop.

I tried another pins:
Encoder encoder_1 = Encoder(34, 35, 1024);
Encoder encoder_2 = Encoder(14, 23, 1024);
Motor with encoder_1 works ok.
Motor with encoder_2 works ok.
Both motors together also works ok!

Third option:
Encoder encoder_1 = Encoder(32, 33, 1024);
Encoder encoder_2 = Encoder(14, 23, 1024);
Motors with encoder_1 works ok.
Motors with encoder_2 works ok.
Both motors together also works ok!

So, I don’t understand what’s wrong with the first option?
I’m guessing there’s something wrong with the interrupt priorities?

Hey @Rem666,

This is very curious :smiley:
Which esp32 board are you using?

ESP32-WROOM-32U

I tried a few other pins:
Encoder encoder_1 = Encoder(21, 22, 1024);
Encoder encoder_2 = Encoder(14, 23, 1024);
Motor with encoder_1 works ok.
Motor with encoder_2 works ok.
But do not work together!

Encoder encoder_1 = Encoder(21, 22, 1024);
Encoder encoder_2 = Encoder(18, 19, 1024);
Motor with encoder_1 works ok.
Motor with encoder_2 works ok.
But do not work together!

Encoder encoder_1 = Encoder(34, 35, 1024);
Encoder encoder_2 = Encoder(21, 22, 1024);
Motor with encoder_1 works ok.
Motor with encoder_2 works ok.
Both motors work well together too!

So if one of the encoders is connected to pins 34, 35 or 32, 33, both motors together work fine.
Other options don’t work… Very strange.

Huh huh, we need an esp expert here, I’ve got no idea really. :slight_smile:

Maybe something to do with the pins that are bu default pulled up or down at boot?

I really don’t know.

I thought it was a problem with the interrupts when they fire at the same time. I did a test - I connected one encoder to two inputs and saw what would happen when the interrupts were triggered at the same time. I tried several input combinations. No problem, I always get exactly the same results. Interrupts are not the problem.
When I first tried the encoders on ESP32, I accidentally connected one of them to inputs 34,35 (it could also be 36,39, but two motors together don’t work either). All other options do not work. These four pins are kind of a weird exception.

So if I used any other motors (not simpleFOC) with the encoders, I wouldn’t have noticed any problems.
The problem remains unclear…

I’m following this with interest, but unfortunately I have no advice on it.

I think some other users have made the same discovery as you, I seem to remember reading some forum posts or GitHub issues about the ESP32 encoders not working. I think maybe it was solved by changing the ESP32 framework version to a lower one.

Or is it possible that it is an electrical issue? That some combinations of pins are on the same supply rail, while other combinations use seperate supplies? Is the MCU sourcing or sinking current, or just in input mode?

I think it’s not a problem with the encoders. There will be something else.
I did one more experiment: both motors rotate at velocity_openloop (the same ones that stop in closed loop). I’m just looking at the values of both encoders for a long time. They are exactly the same.
I tried to change the ESP32 framework version to a lower one. No difference.
I don’t think it could be an electrical issue… The schematic is quite simple, there are only two simpleFOCmini and ESP32.