-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix static hall signal error detection #105
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b22a2e
Fix static hall signal error detection
at-wat b851e4e
Fix comment position
at-wat 605268c
Update condition
at-wat eebd8b8
Fix error count condition
at-wat 391d402
Show hall error only once
at-wat 86f3c14
Fix hallenc error count
at-wat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,27 +422,38 @@ void FIQ_PWMPeriod() | |
char dir; | ||
uint16_t halldiff; | ||
|
||
// ホール素子信号が全相1、全相0のときはエラー | ||
if ((hall[i] & 0x07) == (HALL_U | HALL_V | HALL_W) || | ||
(hall[i] & 0x07) == 0) | ||
{ | ||
// Stop motor control if static hall signal error is continued for more than 3 PWM cycle interrups. | ||
if (driver_state.error.hall[i] <= 12) | ||
{ | ||
driver_state.error.hall[i] += 6; | ||
} | ||
if (driver_state.error.hall[i] > 12) | ||
{ | ||
motor[i].error_state |= ERROR_HALL_SEQ; | ||
printf("PWM:static hall err (%x)\n\r", hall[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この条件は継続して発生するため、ここでprintfすると制御周期でprintfし続けることになり処理が間に合わなくなる。 if ((motor[i].error_state & ERROR_HALL_SEQ) == 0)
printf("PWM:static hall err (%x)\n\r", hall[i]);
motor[i].error_state |= ERROR_HALL_SEQ; のように、初めてこのエラーになるときだけprintfするようにすることで不具合を防げる |
||
} | ||
continue; | ||
} | ||
|
||
u = v = w = 0; | ||
halldiff = (hall[i] ^ _hall[i]) & 0x07; | ||
|
||
if (halldiff == 0) | ||
continue; | ||
dir = 0; | ||
|
||
if ((hall[i] & 0x07) == (HALL_U | HALL_V | HALL_W) || | ||
(hall[i] & 0x07) == 0 || | ||
halldiff == 3 || halldiff >= 5) | ||
// ホース素子信号が2ビット以上変化したときはエラー | ||
if (halldiff == 3 || halldiff >= 5) | ||
{ | ||
// if( (hall[i] & 0x07) == ( HALL_U | HALL_V | HALL_W ) ) printf( "ENC error: 111\n\r" ); | ||
// if( (hall[i] & 0x07) == 0 ) printf( "ENC error: 000\n\r" ); | ||
// if( halldiff == 3 || halldiff >= 5 ) printf( "ENC error: %x->%x\n\r", _hall[i], hall[i] ); | ||
// ホール素子信号が全相1、全相0のとき | ||
// ホース素子信号が2ビット以上変化したときはエラー | ||
|
||
// Skip next one error to avoid counting another edge of this error. | ||
if (driver_state.error.hall[i] < 12) | ||
if (driver_state.error.hall[i] <= 12) | ||
{ | ||
driver_state.error.hall[i] += 12; | ||
|
||
} | ||
if (driver_state.error.hall[i] > 12) | ||
{ | ||
// エラー検出後、1周以内に再度エラーがあれば停止 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
連続でホール素子がこの状態になったとすると、
driver_state.error.hall[i]
は0->6->12と変化するのでここのifはtrueにならなさそう。一度値が変化しないと L468 に飛ばないので6の倍数から崩れることがない?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかに
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
元々、エラーが出続けてカウンタ(8bit)がオーバーフローしたときに小さい値になってエラー状態が解除されるのを防ぐためにカウントの上限を付けているんだった