Skip to content

Commit ac0d851

Browse files
authored
Ignore single-shot hall signal error (#59)
1 parent 2c9d607 commit ac0d851

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

tfrog-motordriver/controlPWM.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,11 @@ void FIQ_PWMPeriod()
394394
//if( halldiff == 3 || halldiff >= 5 ) printf( "ENC error: %x->%x\n\r", _hall[i], hall[i] );
395395
// ホール素子信号が全相1、全相0のとき
396396
// ホース素子信号が2ビット以上変化したときはエラー
397-
if (driver_state.error.hall[i] < 128)
397+
398+
// Skip next one error to avoid counting another edge of this error.
399+
if (driver_state.error.hall[i] < 12)
398400
driver_state.error.hall[i] += 12;
401+
399402
if (driver_state.error.hall[i] > 12)
400403
{
401404
// エラー検出後、1周以内に再度エラーがあれば停止
@@ -538,8 +541,23 @@ void FIQ_PWMPeriod()
538541
// In worst case, initial encoder origin can have offset of motor_param[i].enc_rev/12.
539542
if (_abs(err) > motor_param[i].enc_rev / 6)
540543
{
541-
motor[i].error_state |= ERROR_HALL_ENC;
542-
printf("PWM:enc-hall err (%d)\n\r", err);
544+
// Skip next one error to avoid counting another edge of this error.
545+
if (driver_state.error.hallenc[i] < 12)
546+
driver_state.error.hallenc[i] += 12;
547+
548+
if (driver_state.error.hallenc[i] > 12)
549+
{
550+
// Enter error stop mode if another error occurs within one revolution
551+
motor[i].error_state |= ERROR_HALL_ENC;
552+
printf("PWM:enc-hall err (%d)\n\r", err);
553+
}
554+
// Don't apply erroneous absolute angle
555+
continue;
556+
}
557+
else
558+
{
559+
if (driver_state.error.hallenc[i] > 0)
560+
driver_state.error.hallenc[i]--;
543561
}
544562
}
545563

tfrog-motordriver/controlVelocity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ typedef struct _DriverState
139139
{
140140
unsigned char low_voltage;
141141
unsigned char hall[2];
142+
unsigned char hallenc[2];
142143
} error;
143144
enum
144145
{

tfrog-motordriver/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,8 @@ int main()
593593
driver_state.error.low_voltage = 0;
594594
driver_state.error.hall[0] = 0;
595595
driver_state.error.hall[1] = 0;
596+
driver_state.error.hallenc[0] = 0;
597+
driver_state.error.hallenc[1] = 0;
596598

597599
printf("Velocity Control init\n\r");
598600
// Configure velocity control loop
@@ -704,6 +706,8 @@ int main()
704706
driver_state.error.low_voltage = 0;
705707
driver_state.error.hall[0] = 0;
706708
driver_state.error.hall[1] = 0;
709+
driver_state.error.hallenc[0] = 0;
710+
driver_state.error.hallenc[1] = 0;
707711
driver_state.ifmode = 0;
708712
driver_state.watchdog = 0;
709713
// Driver loop
@@ -761,6 +765,8 @@ int main()
761765
}
762766
driver_state.error.hall[0] = 0;
763767
driver_state.error.hall[1] = 0;
768+
driver_state.error.hallenc[0] = 0;
769+
driver_state.error.hallenc[1] = 0;
764770
motor[0].error_state |= ERROR_WATCHDOG;
765771
motor[1].error_state |= ERROR_WATCHDOG;
766772
printf("Watchdog - init parameters\n\r");

0 commit comments

Comments
 (0)