Issues with the library on different boards

Hi,
I have a project that needs to drive a motor quite fast and that use a AS5048a magnetic sensor as encoder.

I first developped it on the Arduino UNO without issues except its computation capacity (16mHz, loop called every 1 ms). I purchased different boards (nano connect, nano esp32, nucleo L432KC, teensy 4.0, pi pico) in order to overcome this limit.

I had a generic sketch that drove the motor in velocity openloop.
The loop() (motor.loopFOC + motor.move(targetSpeed) took 40 ms on a rp2040 board (pi pico and nano connect, arduino-pico 3.1.1 and simple FOC 2.3.4).
Upgrading the arduino-pico board to 4.3.1, The same loop took 50 us.
However, the MagneticSensorSPI base class .init() blocks the program. I used an homemade sensor class to overcome that and test.

I tried the NUCLEO-L432KC board, but as soon as the simplefoc library is included, the program compiles but is not executed (tried with blink…).
The nucleo board is STM32 MCU based boards 2.9.0.

I also tried an esp32 nano board but I couldn’t program without force reseting the board. This issue was not related to the simple foc library

Hi @nakeze,
It’s definitely possible to overcome your 1 ms limit. I use an ESP32 to drive two motors in closed-loop mode (and two AS5048a, using this driver) and I achieve 0.15 ms.

Hi Quentin,
Yes it is definitely possible, with teensy and rp2040, the loop is over 10 khz. I wanted to list the issues that I faced, which were :

  • Poor computation time with an old arduino-pico version.
  • Code than don’t run on nucleo-L432KC stm32 2.9.0 even though compilation is fine.

I know that it must be hard to maintain and document all these different combinations. Maybe the page : Microcontrollers | Arduino-FOC could get a boad version and simple foc version compatibility that were tested at new release.

If the code is not hanging but initialization fails somewhere, you can enable the debug build flag for stm:

SIMPLEFOC_STM32_DEBUG

You can enable it by adding this to the build_blags in platformio.ini if you use platformio:

-D SIMPLEFOC_STM32_DEBUG

You also need to add this to your code:

void setup(){
  Serial.begin(115200);
  SimpleFOCDebug::enable(&Serial);
  delay(3000); // wait 3s to connect serial console on PC
  ...
}

You will then get more details on the serial output.