Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

[FEATURE]Cache the results of trigonometric functions?

Open FFiot opened this issue 2 years ago • 5 comments

st = _sin(angle); ct = _cos(angle); Cache the results of trigonometric functions? Angle does not change between samples。 Clarke transform:src\BLDCMotor.cpp Line 546.
Inverse clarke transform:src\common\base_classes\CurrentSense.cpp Line 42.

// function approximating cosine calculation by using fixed size array // ~55us (float array) // ~56us (int array)

FFiot avatar May 23 '22 23:05 FFiot

Makes sense. This will also help people who replace the trig functions with more accurate but potentially slower versions.

runger1101001 avatar May 24 '22 10:05 runger1101001

If a change is done here, it may be a good idea to better provide a way to use a table of values. Depending on the resolution, the actual could be extrapolated or looked up. That would allow people to use different kinds of waves. Perhaps, parametrizing by current or distance to the pole...

arturohernandez10 avatar May 24 '22 23:05 arturohernandez10

Um, that's actually the way the trig functions already work...

_sin() and _cos() are defined in https://github.com/simplefoc/Arduino-FOC/blob/master/src/common/foc_utils.cpp They use a lookup table.

But I agree it could be cool to allow the user more control over this lookup table, or to replace the _sin() and _cos() with their own, perhaps MCU-optimised implementations.

runger1101001 avatar May 25 '22 07:05 runger1101001

https://github.com/simplefoc/Arduino-FOC/pull/262

runger1101001 avatar Mar 21 '23 23:03 runger1101001

https://community.simplefoc.com/t/embedded-world-2023-stm32-cordic-co-processor/3107

runger1101001 avatar Mar 21 '23 23:03 runger1101001