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

Fix static hall signal error detection #105

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions tfrog-motordriver/controlPWM.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link

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の倍数から崩れることがない?

Copy link
Member Author

Choose a reason for hiding this comment

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

たしかに

Copy link
Member Author

Choose a reason for hiding this comment

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

元々、エラーが出続けてカウンタ(8bit)がオーバーフローしたときに小さい値になってエラー状態が解除されるのを防ぐためにカウントの上限を付けているんだった

{
motor[i].error_state |= ERROR_HALL_SEQ;
printf("PWM:static hall err (%x)\n\r", hall[i]);
Copy link

Choose a reason for hiding this comment

The 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周以内に再度エラーがあれば停止
Expand Down
Loading