Skip to content

Fixes #13934: Fix motor(PWM protocol) spin while fc reset. #13937

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

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

kedeng
Copy link
Contributor

@kedeng kedeng commented Sep 28, 2024

Fixes #13934

Tested targets: SPEEDYBEEF405V4, SPEEDYBEEF405AIO and ARGUSF7AIO.

Before change, the PWM output may in high level while reset:
reboot_pwm

After add delay, PWM output keep zero duty before fc reset:
reboot_pwm_low

Copy link

Do you want to test this code? You can flash it directly from Betaflight Configurator:

  • Simply put #13937 (this pull request number) in the Select commit field of the Configurator firmware flasher tab (you need to Enable expert mode, Show release candidates and Development).

WARNING: It may be unstable. Use only for testing!

@haslinghuis haslinghuis added this to the 4.6 milestone Sep 28, 2024
Copy link
Contributor

@ledvinap ledvinap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

motorShutdown() already contains 1.5ms delay and is only point that calls motorDevice->vTable.shutdown(); . Increasing that delay may be enough. And it will prevent 'hidden' delay in virtual function,

@@ -35,6 +35,10 @@

#include "pg/motor.h"

#ifndef PWM_SHUTDOWN_DELAY
#define PWM_SHUTDOWN_DELAY 600
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interval may be too short. You need at least 2ms for standard PWM pulse ( just for pulse to end, PWM interval may be 20ms)

Copy link
Contributor Author

@kedeng kedeng Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested a few more values: 200ms, 300ms, 490ms, none of these values can fix the problem. But value greater than or equal to 500ms can fix the issue.

The reason is after 500ms low level, ESC will in disarm state (ESC determine signal loss), in disarm state any signal interference will not considered valid. ESC need receive initialization sequence to re-enter arm state again.

So value greater or equal 500ms is OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, i confused us and ms.
.6 s is noticeable time, but esc disarm is reasonable strategy. Maybe delay can be moved outside of this function (there is already delay after shutdown call). I'll look into it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to move delay to motorShutdown, but's not all protocols require such a long delay.
The delay value can be set based on the ESC protocol currently in use.
We are on holiday now, I'll change and test it later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can return minimum guard time before reboot from motorDevice->vTable.shutdown();. Then extend delay in motorShutdown(); if necessary.

Copy link
Member

@blckmn blckmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved conditional on the changes requested by @ledvinap

@kedeng kedeng requested a review from ledvinap October 7, 2024 13:24
@haslinghuis haslinghuis merged commit 10d5963 into betaflight:master Oct 7, 2024
26 checks passed
haslinghuis pushed a commit to haslinghuis/betaflight that referenced this pull request Oct 7, 2024
…etaflight#13937)

* Fix motor(PWM protocol) spin while fc reset.

* move delay out to motorShutdown
blckmn pushed a commit that referenced this pull request Oct 8, 2024
…13937) (#13958)

Fixes #13934: Fix motor(PWM protocol) spin while fc reset. (#13937)

* Fix motor(PWM protocol) spin while fc reset.

* move delay out to motorShutdown

Co-authored-by: ke deng <degkxp@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

When the motor protocol is set to PWM, reboot FC can cause the motor to spin unexpectedly
5 participants