Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Possibility to run FOC from interrupt #417

Open
Candas1 opened this issue Jul 6, 2024 · 3 comments
Open

[FEATURE] Possibility to run FOC from interrupt #417

Candas1 opened this issue Jul 6, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Candas1
Copy link
Collaborator

Candas1 commented Jul 6, 2024

Some MCUs are fast enough to run the FOC algorithms from the current sense interrupt.
This was already discussion here in the forum, but it was 3 years ago, maybe the opinions have changed.

This could have several benefits:

Constant dt:

FOC will run at constant dt, this will simplify PID and Filter math and help with performance as there is no need to measure the timestamp and calculate dt (this would be needed).

Better timing:

It makes sure FOC runs on recent phase current data, and duty cycles is applied within the same pwm cycle.

Overcurrent protection

This can be used for cycle by cycle software overcurrent protection.

Sensorless

It allows injection for HFI sensorless algorithm.
HFI also needs to identify V1 and V7, and run different code for each with low side current sensing.

Solution:

Allow the user to set up a callback function as parameter to the current sense class, that will be executed in the current sense interrupt. User should manage the callback to run loopfoc().
The code should not overrun, the interrupts should be disabled before and enabled after the callback.

@Candas1 Candas1 added the enhancement New feature or request label Jul 6, 2024
@nmscode
Copy link
Contributor

nmscode commented Jul 6, 2024

An example implementation of this (for stm32 and esp32) can be seen in https://github.com/mcells/Arduino-FOC/tree/esp32-hfi-flux_observer

that branch has several other features but the basic callback with FOC calculations from the interrupt is there as well.

This would require some changes to current sense on stm32 and esp32 to work. From my testing it does work and is quite useful particularly the ocp.

@Copper280z
Copy link
Contributor

One complication is SPI/I2C encoder updating for sensored applications. On ARM chips I can confirm that SPI reads from an ISR work fine presuming there's sufficient time for it to happen, but I'm unsure that's true for any other architecture (AVR/Xtensa/RISCV).

Still it might be advisable to not use the ADC ISR if there's an SPI/I2C sensor. I can't think of a good way to enforce that reliably, so I think that means ISR vs loop execution should be user configurable?

@nmscode
Copy link
Contributor

nmscode commented Jul 6, 2024

Still it might be advisable to not use the ADC ISR if there's an SPI/I2C sensor. I can't think of a good way to enforce that reliably, so I think that means ISR vs loop execution should be user configurable?

Agreed that the isr vs loop execution should be a flag or otherwise user configurable on mcus that support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants