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] Hall sensor without interrupt #418

Closed
Candas1 opened this issue Jul 6, 2024 · 5 comments · Fixed by #424
Closed

[FEATURE] Hall sensor without interrupt #418

Candas1 opened this issue Jul 6, 2024 · 5 comments · Fixed by #424
Labels
enhancement New feature or request
Milestone

Comments

@Candas1
Copy link
Collaborator

Candas1 commented Jul 6, 2024

I wrote this code some time ago but I haven't published it because I wasn't sure it was useful enough. I am posting it here to get your opinion, specially you @dekutree64 as you did a lot of work on this sensor.

What it does is:

  • if no interrupts are enabled for hall sensors, it will just check the hall states directly when sensor is updated.
  • some small code optimizations

The user can choose if he wants to run it with or without interrupts.

Benefits:

  • if user forgets to enable interrupts, the motor will still run (we could issue a warning in debug mode)
  • if there are not enough interrupts available (arduino?), the motor can still run
  • With interrupts, the faster the motor spins the more interrupts are triggered, slowing down the loop duration/frequency. Without interrupts, the code runs at constant duration/frequency
  • PIDs/filters might not be impacted by hall interrupts running in the middle
  • less problems when there are noise issues ? (to be checked)

Downside:

  • the slower the MCU is and the faster the motor spins, the less accurate the position will be
@Candas1 Candas1 added the enhancement New feature or request label Jul 6, 2024
@dekutree64
Copy link
Contributor

Looks good to me.

I don't think you can drive faster than one update per sector anyway, since the lagging stator field will start decelerating the rotor instead of accelerating it.

You have to miss at least 2 pulses before the position is lost, so it would require some fast backdriving before it's a problem. The main place I can see that happening is rolling down a hill on an electric skateboard, and that doesn't need to keep track of absolute position.

The main thing you'll lose is accurate timestamps for velocity calculation. May need higher lowpass Tf to average it out, resulting in slower velocity PID response time. Probably not enough to be a problem, though.

@Candas1
Copy link
Collaborator Author

Candas1 commented Jul 7, 2024

Thanks a lot for your very valid comments.
I am getting 320 kv motors with hall sensors soon, I can test this at high speeds with slow and fast MCUs and compare the velocity with and without interrupts.

This is more like a fallback mode but I want to make sure it works.

@dekutree64
Copy link
Contributor

This is awesome. I can use 41F halls now, which don't need any filtering capacitors. They generate excessive interrupts even if I do add capacitors, but work effortlessly with this new code.

I'm getting about 190rad/s top speed. Loop time is around 400us, so 2.5kHz. With 7 pole pairs that's 2500/7/6=59.5 revolutions per second, or 374rad/s theoretical top speed. I don't think nyquist frequency applies here, so I'm not sure why it's maxing out at half, but IIRC that's been about my top speed with other configurations too.

@Candas1
Copy link
Collaborator Author

Candas1 commented Jul 15, 2024

Happy to hear it's useful, I will check if I can get it in the next release.

@askuric askuric linked a pull request Jul 18, 2024 that will close this issue
@Candas1
Copy link
Collaborator Author

Candas1 commented Jul 21, 2024

This was released. Thanks again for the feedback.

@Candas1 Candas1 closed this as completed Jul 21, 2024
@runger1101001 runger1101001 added this to the 2.3.4_Release milestone Jul 22, 2024
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

Successfully merging a pull request may close this issue.

3 participants