|
@@ -94,15 +94,15 @@ float hall_sensor_get_theta(void){
|
|
|
}
|
|
}
|
|
|
_hall.est_theta = tick_2_s(delta_ticks(_hall.ticks)) * _hall.degree_per_s + _hall.theta;
|
|
_hall.est_theta = tick_2_s(delta_ticks(_hall.ticks)) * _hall.degree_per_s + _hall.theta;
|
|
|
float est_delta = _hall.est_theta - _hall.theta;
|
|
float est_delta = _hall.est_theta - _hall.theta;
|
|
|
- if (est_delta > 60) {
|
|
|
|
|
- _hall.est_theta = _hall.theta + 60;
|
|
|
|
|
- if (_hall.est_theta >= 360){
|
|
|
|
|
- _hall.est_theta -= 360;
|
|
|
|
|
|
|
+ if (est_delta > PHASE_60_DEGREE) {
|
|
|
|
|
+ _hall.est_theta = _hall.theta + PHASE_60_DEGREE;
|
|
|
|
|
+ if (_hall.est_theta >= PHASE_360_DEGREE){
|
|
|
|
|
+ _hall.est_theta -= PHASE_360_DEGREE;
|
|
|
}
|
|
}
|
|
|
- }else if (est_delta < -60){
|
|
|
|
|
- _hall.est_theta = _hall.theta - 60;
|
|
|
|
|
- if (_hall.est_theta <= -360) {
|
|
|
|
|
- _hall.est_theta += 360;
|
|
|
|
|
|
|
+ }else if (est_delta < -PHASE_60_DEGREE){
|
|
|
|
|
+ _hall.est_theta = _hall.theta - PHASE_60_DEGREE;
|
|
|
|
|
+ if (_hall.est_theta <= -PHASE_360_DEGREE) {
|
|
|
|
|
+ _hall.est_theta += PHASE_360_DEGREE;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return _hall.est_theta;
|
|
return _hall.est_theta;
|
|
@@ -125,7 +125,7 @@ float hall_sensor_avg_speed(void) {
|
|
|
|
|
|
|
|
|
|
|
|
|
int hall_sensor_calibrate(float voltage, u16 *hall_table){
|
|
int hall_sensor_calibrate(float voltage, u16 *hall_table){
|
|
|
- foc_open_loop();
|
|
|
|
|
|
|
+ foc_set_controller_mode(FOC_MODE_OPEN_LOOP);
|
|
|
hall_sensor_set_theta(true, 0.0f);
|
|
hall_sensor_set_theta(true, 0.0f);
|
|
|
foc_set_dq_command(0.0f, 0.0f);
|
|
foc_set_dq_command(0.0f, 0.0f);
|
|
|
foc_pwm_start(true);
|
|
foc_pwm_start(true);
|
|
@@ -207,34 +207,34 @@ void hall_sensor_handler(void) {
|
|
|
case STATE_1:
|
|
case STATE_1:
|
|
|
if (state_prev == STATE_5) {
|
|
if (state_prev == STATE_5) {
|
|
|
_hall.direction = POSITIVE;
|
|
_hall.direction = POSITIVE;
|
|
|
- theta_now = _hall.phase_offset + 60.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_60_DEGREE;
|
|
|
}else if (state_prev == STATE_3) {
|
|
}else if (state_prev == STATE_3) {
|
|
|
_hall.direction = NEGATIVE;
|
|
_hall.direction = NEGATIVE;
|
|
|
- theta_now = _hall.phase_offset + 120.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_120_DEGREE;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case STATE_2:
|
|
case STATE_2:
|
|
|
if (state_prev == STATE_3) {
|
|
if (state_prev == STATE_3) {
|
|
|
_hall.direction = POSITIVE;
|
|
_hall.direction = POSITIVE;
|
|
|
- theta_now = _hall.phase_offset + 180.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_180_DEGREE;
|
|
|
}else if (state_prev == STATE_6) {
|
|
}else if (state_prev == STATE_6) {
|
|
|
_hall.direction = NEGATIVE;
|
|
_hall.direction = NEGATIVE;
|
|
|
- theta_now = _hall.phase_offset + 240.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_240_DEGREE;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case STATE_3:
|
|
case STATE_3:
|
|
|
if (state_prev == STATE_1) {
|
|
if (state_prev == STATE_1) {
|
|
|
_hall.direction = POSITIVE;
|
|
_hall.direction = POSITIVE;
|
|
|
- theta_now = _hall.phase_offset + 120.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_120_DEGREE;
|
|
|
}else if (state_prev == STATE_2) {
|
|
}else if (state_prev == STATE_2) {
|
|
|
_hall.direction = NEGATIVE;
|
|
_hall.direction = NEGATIVE;
|
|
|
- theta_now = _hall.phase_offset + 180.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_180_DEGREE;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case STATE_4:
|
|
case STATE_4:
|
|
|
if (state_prev == STATE_6) {
|
|
if (state_prev == STATE_6) {
|
|
|
_hall.direction = POSITIVE;
|
|
_hall.direction = POSITIVE;
|
|
|
- theta_now = _hall.phase_offset + 300.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_300_DEGREE;
|
|
|
}else if (state_prev == STATE_5) {
|
|
}else if (state_prev == STATE_5) {
|
|
|
_hall.direction = NEGATIVE;
|
|
_hall.direction = NEGATIVE;
|
|
|
theta_now = _hall.phase_offset;
|
|
theta_now = _hall.phase_offset;
|
|
@@ -246,16 +246,16 @@ void hall_sensor_handler(void) {
|
|
|
theta_now = _hall.phase_offset;
|
|
theta_now = _hall.phase_offset;
|
|
|
}else if (state_prev == STATE_1) {
|
|
}else if (state_prev == STATE_1) {
|
|
|
_hall.direction = NEGATIVE;
|
|
_hall.direction = NEGATIVE;
|
|
|
- theta_now = _hall.phase_offset + 60.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_60_DEGREE;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case STATE_6:
|
|
case STATE_6:
|
|
|
if (state_prev == STATE_2) {
|
|
if (state_prev == STATE_2) {
|
|
|
_hall.direction = POSITIVE;
|
|
_hall.direction = POSITIVE;
|
|
|
- theta_now = _hall.phase_offset + 240.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_240_DEGREE;
|
|
|
}else if (state_prev == STATE_4) {
|
|
}else if (state_prev == STATE_4) {
|
|
|
_hall.direction = NEGATIVE;
|
|
_hall.direction = NEGATIVE;
|
|
|
- theta_now = _hall.phase_offset + 300.0f;
|
|
|
|
|
|
|
+ theta_now = _hall.phase_offset + PHASE_300_DEGREE;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|