simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
2.02k stars 518 forks source link

_micros() accuracy #42

Open Polyphe opened 3 years ago

Polyphe commented 3 years ago

Hello @askuric, When I use _micros(), I get 75us for the loop of FOC:

t0=_micros(); motor.loopFOC(); motor.move(); t2=_micros(); Serial.print("..."); Serial.println(t2-t0);

The result is t2-t0 = 94 with a time distribution of loopFOC() @75 + a move() @19 = 94us.

And, then, when I use this, I get 20us with an oscilloscope:

GPIOA->BSRR = GPIO_BSRR_BS15; motor.loopFOC(); GPIOA->BSRR = GPIO_BSRR_BR15;

I think there is an accuracy issue with _micros(). Maybe, use a Timer for a best accuracy as for the Atmega328, and increase the accuracy of all others measures of timing, velocity, and so on.

Best regards.

KaSroka commented 3 years ago

It looks like in GPIO example you have ommited motor.move(); call which is doing a lot of things, depending on controller type.