Skip to content

Commit

Permalink
Fix absolute angle compensation (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Jan 29, 2019
1 parent 81e5362 commit 5fc4926
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tfrog-motordriver/controlPWM.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void FIQ_PWMPeriod()
break;
case MOTOR_TYPE_AC3:
phase[2] = motor[j].pos - motor_param[j].enc0tran;
phase[2] = (uint64_t)(phase[2] + motor_param[j].phase_offset) *
phase[2] = (int64_t)(phase[2] + motor_param[j].phase_offset) *
motor_param[j].enc_mul / 0x40000 +
SinTB_2PI + SinTB_2PI / 4;
phase[1] = phase[2] - SinTB_2PI / 3;
Expand All @@ -340,7 +340,10 @@ void FIQ_PWMPeriod()
{
int pwmt;

pwmt = (int)sin_(phase[i] % SinTB_2PI) * rate / (4096 * 2);
int p = phase[i] % SinTB_2PI;
if (p < 0)
p += SinTB_2PI;
pwmt = (int)sin_(p) * rate / (4096 * 2);
pwmt += PWM_center;
if (pwmt < PWM_abs_min)
pwmt = PWM_abs_min;
Expand Down

0 comments on commit 5fc4926

Please sign in to comment.