mirror of https://github.com/rusefi/bldc.git
Some refactoring and a fix
This commit is contained in:
parent
0bfe9bce9a
commit
c525ce4671
|
@ -175,17 +175,7 @@ static msg_t sten_thread(void *arg) {
|
||||||
servo_val = 0.0;
|
servo_val = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use duty cycle control when running slowly, otherwise use current control.
|
mcpwm_set_current(servo_val * MCPWM_CURRENT_MAX);
|
||||||
if (fabsf(mcpwm_get_rpm()) < 4500 && fabsf(servo_val) > MCPWM_MIN_DUTY_CYCLE) {
|
|
||||||
if (servo_val > 0.0) {
|
|
||||||
utils_truncate_number(&servo_val, 0.1, 0.3);
|
|
||||||
mcpwm_set_duty(servo_val);
|
|
||||||
} else {
|
|
||||||
mcpwm_set_duty(0.0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mcpwm_set_current(servo_val * MCPWM_CURRENT_MAX);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mcpwm_set_current(0.0);
|
mcpwm_set_current(0.0);
|
||||||
}
|
}
|
||||||
|
|
47
mcpwm.c
47
mcpwm.c
|
@ -204,10 +204,6 @@ static void set_next_timer_settings(mc_timer_struct *settings);
|
||||||
static void set_switching_frequency(int frequency);
|
static void set_switching_frequency(int frequency);
|
||||||
static int try_input(void);
|
static int try_input(void);
|
||||||
|
|
||||||
#if MCPWM_IS_SENSORLESS
|
|
||||||
static int integrate_cycle(float v_diff);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Defines
|
// Defines
|
||||||
#define ADC_CDR_ADDRESS ((uint32_t)0x40012308)
|
#define ADC_CDR_ADDRESS ((uint32_t)0x40012308)
|
||||||
#define CYCLE_INT_START (0.0)
|
#define CYCLE_INT_START (0.0)
|
||||||
|
@ -528,7 +524,6 @@ void mcpwm_set_duty(float dutyCycle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
control_mode = CONTROL_MODE_DUTY;
|
control_mode = CONTROL_MODE_DUTY;
|
||||||
|
|
||||||
set_duty_cycle_hl(dutyCycle);
|
set_duty_cycle_hl(dutyCycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -881,10 +876,7 @@ static void set_duty_cycle_ll(float dutyCycle) {
|
||||||
#if MCPWM_IS_SENSORLESS
|
#if MCPWM_IS_SENSORLESS
|
||||||
if (state != MC_STATE_RUNNING) {
|
if (state != MC_STATE_RUNNING) {
|
||||||
state = MC_STATE_RUNNING;
|
state = MC_STATE_RUNNING;
|
||||||
if (rpm_now < MCPWM_MIN_RPM) {
|
pwm_cycles_sum = 0.0;
|
||||||
set_next_comm_step(comm_step);
|
|
||||||
commutate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (state != MC_STATE_RUNNING) {
|
if (state != MC_STATE_RUNNING) {
|
||||||
|
@ -1355,34 +1347,38 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) {
|
||||||
case 1:
|
case 1:
|
||||||
v_diff = ph1;
|
v_diff = ph1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
v_diff = -ph2;
|
v_diff = -ph2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
v_diff = ph3;
|
v_diff = ph3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
v_diff = -ph1;
|
v_diff = -ph1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
v_diff = ph2;
|
v_diff = ph2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
v_diff = -ph3;
|
v_diff = -ph3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v_diff > 0) {
|
if (v_diff > 0) {
|
||||||
if (state == MC_STATE_RUNNING || state == MC_STATE_OFF) {
|
if (state == MC_STATE_RUNNING || state == MC_STATE_OFF) {
|
||||||
integrate_cycle((float)v_diff);
|
cycle_integrator += v_diff / (float)switching_frequency_now;
|
||||||
|
|
||||||
|
const float rpm_fac = rpm_now / 50000.0;
|
||||||
|
const float cycle_int_limit = MCPWM_CYCLE_INT_LIMIT_LOW * (1.0 - rpm_fac) +
|
||||||
|
MCPWM_CYCLE_INT_LIMIT_HIGH * rpm_fac;
|
||||||
|
const float limit = (cycle_int_limit * 0.0005);
|
||||||
|
|
||||||
|
if (cycle_integrator >= limit) {
|
||||||
|
commutate();
|
||||||
|
cycle_integrator = CYCLE_INT_START;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cycle_integrator = CYCLE_INT_START;
|
cycle_integrator = CYCLE_INT_START;
|
||||||
|
@ -1524,25 +1520,6 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) {
|
||||||
chSysUnlockFromIsr();
|
chSysUnlockFromIsr();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MCPWM_IS_SENSORLESS
|
|
||||||
static int integrate_cycle(float v_diff) {
|
|
||||||
cycle_integrator += v_diff / (float)switching_frequency_now;
|
|
||||||
|
|
||||||
const float rpm_fac = rpm_now / 50000.0;
|
|
||||||
const float cycle_int_limit = MCPWM_CYCLE_INT_LIMIT_LOW * (1.0 - rpm_fac) +
|
|
||||||
MCPWM_CYCLE_INT_LIMIT_HIGH * rpm_fac;
|
|
||||||
const float limit = (cycle_int_limit * 0.0005);
|
|
||||||
|
|
||||||
if (cycle_integrator >= limit) {
|
|
||||||
commutate();
|
|
||||||
cycle_integrator = CYCLE_INT_START;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void mcpwm_set_detect(void) {
|
void mcpwm_set_detect(void) {
|
||||||
if (try_input()) {
|
if (try_input()) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue