I wrote some code for an ESP32 via the Arduino IDE to run a BLDC motor openloop with a DRV8313 driver. It works very well as long as I do not do anything in the main loop except calling “motor.move(target_velocity);”.
As soon as I add some more code to the main loop the motor stops running during the execution of the additional code. The simplest example would be adding a delay like “delay(5000);”. If I do that the motor stops running for 5 seconds.
So my question is: Is it possible to run a motor in the ‘background’ with simplefoc while executing other commands? What am I missing?
Thanks much in advance!
No you are not missing anything. The MCU is a single thread process. You need to execute either extremely short commands inside the loop which would not slow down the motor loop or execute them outside and pass the results to the mcu using a protocol or by other means which will not slow down the loop.
There may be a way to run simplefoc on a two core mcu such as arduino portenta and dedicate one core to the motor loop then have the cores communicate.
Thank you very much for your response! Much appreciated!
How much time does one have between motor.move() calls without degrading the motor signals?
Does this depend on the RPM? My motor is running constantly at 3.5rad/sec (open loop).
Depends on your MCU speed. At about 3.5 rad/sec your extra logic delay should be under 1 uS. You can test with _delay(1) and see if the motor will stutter and change behavior of the rotation. The faster MCU you got, the more logic you can execute inside the loop without impacting the loop performance.
It does depend on the RPM and the MCU speed. Slower RPM is not that impacted however if he motor is rotating really fast then the time to execute extra instructions without degrading the loop obviously shrinks.
Bigger is always better as far as MCU is concerned.