Very strange simplefoc behaviour

Hi all,

Over the past few months I have been developing with different FOC boards and different microcontrollers, the ones I have right now are ESP 32 WROOM 32s and Arduino R4 minima with SimpleFOCShield v3.2, SimpleFOC mini v1.0 and MKS dualfoc V3.2 (but this last one I never managed to get working because my ESP has different pin layout).

Now I have seen very inconsistent results when deploying code. If I connect my R4 minima with a single encoder it works, if I then connect my second encoder it will break FOC, if I then remove the second encoder and push code with the single encoder, FOC is still broken. While this is the exact same code that worked 2 minutes earlier.

If I then disconnect both USB and power and reconnect, FOC will work again.

Is this supposed to happen, and what is the correct way to deal with this? I thought I was going insane but I think stuff is breaking when the Arduino is rebooting while power is still connected to minifoc?

Any help is appreciated, I’m just trying to create a serial bridge that takes torque (/voltage) as input but having lots of FOC related issues unfortunately.

EDIT: if it matters; I am using “PreciseMagneticSensorAS5048A motor_sensor = PreciseMagneticSensorAS5048A(10);” from “#include “encoders/as5048a/PreciseMagneticSensorAS5048A.h”“

Strange indeed. I had a situation where connecting an AS5048A and AS5047P on the same SPI bus would cause one of them (I think it was the 5048) to return bad angles. But it recovers immediately if I unplug the other while running, and goes bad again when plugged back in. And neither of them is bothered by an MT6835 on the same bus, which is inbetween them on the connector board I made, so I’m fairly sure it’s not a wiring problem. I never did get to the bottom of it, and just moved one of the encoders to a different SPI bus, but it doesn’t looks like you can do that on the minima.

See if you can gather some more information. Does one or both of the encoders return bad angles, or is FOC broken in some other way? Does each of them work if the other is not plugged in?

Needing a hard reset to recover is odd, but I wouldn’t worry too much about it unless it’s a lot of trouble to do it for each test.