Skip to content

Commit

Permalink
Ignore single-shot hall signal error (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored May 7, 2019
1 parent 2c9d607 commit ac0d851
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tfrog-motordriver/controlPWM.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,11 @@ void FIQ_PWMPeriod()
//if( halldiff == 3 || halldiff >= 5 ) printf( "ENC error: %x->%x\n\r", _hall[i], hall[i] );
// ホール素子信号が全相1、全相0のとき
// ホース素子信号が2ビット以上変化したときはエラー
if (driver_state.error.hall[i] < 128)

// Skip next one error to avoid counting another edge of this error.
if (driver_state.error.hall[i] < 12)
driver_state.error.hall[i] += 12;

if (driver_state.error.hall[i] > 12)
{
// エラー検出後、1周以内に再度エラーがあれば停止
Expand Down Expand Up @@ -538,8 +541,23 @@ void FIQ_PWMPeriod()
// In worst case, initial encoder origin can have offset of motor_param[i].enc_rev/12.
if (_abs(err) > motor_param[i].enc_rev / 6)
{
motor[i].error_state |= ERROR_HALL_ENC;
printf("PWM:enc-hall err (%d)\n\r", err);
// Skip next one error to avoid counting another edge of this error.
if (driver_state.error.hallenc[i] < 12)
driver_state.error.hallenc[i] += 12;

if (driver_state.error.hallenc[i] > 12)
{
// Enter error stop mode if another error occurs within one revolution
motor[i].error_state |= ERROR_HALL_ENC;
printf("PWM:enc-hall err (%d)\n\r", err);
}
// Don't apply erroneous absolute angle
continue;
}
else
{
if (driver_state.error.hallenc[i] > 0)
driver_state.error.hallenc[i]--;
}
}

Expand Down
1 change: 1 addition & 0 deletions tfrog-motordriver/controlVelocity.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ typedef struct _DriverState
{
unsigned char low_voltage;
unsigned char hall[2];
unsigned char hallenc[2];
} error;
enum
{
Expand Down
6 changes: 6 additions & 0 deletions tfrog-motordriver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ int main()
driver_state.error.low_voltage = 0;
driver_state.error.hall[0] = 0;
driver_state.error.hall[1] = 0;
driver_state.error.hallenc[0] = 0;
driver_state.error.hallenc[1] = 0;

printf("Velocity Control init\n\r");
// Configure velocity control loop
Expand Down Expand Up @@ -704,6 +706,8 @@ int main()
driver_state.error.low_voltage = 0;
driver_state.error.hall[0] = 0;
driver_state.error.hall[1] = 0;
driver_state.error.hallenc[0] = 0;
driver_state.error.hallenc[1] = 0;
driver_state.ifmode = 0;
driver_state.watchdog = 0;
// Driver loop
Expand Down Expand Up @@ -761,6 +765,8 @@ int main()
}
driver_state.error.hall[0] = 0;
driver_state.error.hall[1] = 0;
driver_state.error.hallenc[0] = 0;
driver_state.error.hallenc[1] = 0;
motor[0].error_state |= ERROR_WATCHDOG;
motor[1].error_state |= ERROR_WATCHDOG;
printf("Watchdog - init parameters\n\r");
Expand Down

0 comments on commit ac0d851

Please sign in to comment.