Updated the equations and parameters for the flux integrator

This commit is contained in:
Benjamin Vedder 2014-08-11 22:38:50 +02:00
parent e24b555dea
commit edaf1ca02e
8 changed files with 121 additions and 35 deletions

View File

@ -44,6 +44,7 @@
//#define MCCONF_OUTRUNNER1
#define MCCONF_OUTRUNNER2
//#define MCCONF_RCCAR1
//#define MCCONF_RCCAR2
//#define MCCONF_STEN
/*

View File

@ -18,7 +18,7 @@
/*
* mcconf_outrunner1.h
*
* A configuration for my 2kw hobbyking outrunner. Similar size outrunners
* A configuration for my 2kw hobbyking 215kv outrunner. Similar size outrunners
* should have a similar configuration.
*
* Created on: 14 apr 2014
@ -35,15 +35,16 @@
#define MCPWM_CURRENT_MIN -60.0 // Current limit in Amperes (Lower)
#define MCPWM_IN_CURRENT_MAX 60.0 // Input current limit in Amperes (Upper)
#define MCPWM_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower)
#define MCPWM_MAX_ABS_CURRENT 90.0 // The maximum absolute current above which a fault is generated
#define MCPWM_MAX_ABS_CURRENT 100.0 // The maximum absolute current above which a fault is generated
// Sensorless settings
#define MCPWM_IS_SENSORLESS 1 // Use sensorless commutation
#define MCPWM_MIN_RPM 200 // Auto-commutate below this RPM
#define MCPWM_CYCLE_INT_START_RPM_BR 6000.0 // RPM border between the START and LOW interval
#define MCPWM_CYCLE_INT_LIMIT_START 1700.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_LOW 260.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 30.0 // Flux integrator limit 80K ERPM
#define MCPWM_CYCLE_INT_LIMIT_MAX 1700.0 // Maximum allowed flux integrator limit
#define MCPWM_CYCLE_INT_START_RPM_BR 80000.0 // RPM at the higher flux integrator limit
#define MCPWM_CYCLE_INT_LIMIT_LOW 90.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 40.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_BEMF_INPUT_COUPLING_K 300.0 // Input voltage to bemf coupling constant
// Speed PID parameters
#define MCPWM_PID_KP 0.0001 // Proportional gain

View File

@ -18,7 +18,7 @@
/*
* mcconf_outrunner1.h
*
* A configuration for my 3kw black outrunner.
* A configuration for my scorpion 225kv outrunner.
*
* Created on: 14 apr 2014
* Author: benjamin
@ -38,11 +38,12 @@
// Sensorless settings
#define MCPWM_IS_SENSORLESS 1 // Use sensorless commutation
#define MCPWM_MIN_RPM 200 // Auto-commutate below this RPM
#define MCPWM_CYCLE_INT_START_RPM_BR 6000.0 // RPM border between the START and LOW interval
#define MCPWM_CYCLE_INT_LIMIT_START 1400.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_LOW 180.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 20.0 // Flux integrator limit 80K ERPM
#define MCPWM_MIN_RPM 250 // Auto-commutate below this RPM
#define MCPWM_CYCLE_INT_LIMIT_MAX 1400.0 // Maximum allowed flux integrator limit
#define MCPWM_CYCLE_INT_START_RPM_BR 80000.0 // RPM border between the START and LOW interval
#define MCPWM_CYCLE_INT_LIMIT_LOW 80.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 40.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_BEMF_INPUT_COUPLING_K 300.0 // Input voltage to bemf coupling constant
// Speed PID parameters
#define MCPWM_PID_KP 0.0001 // Proportional gain

View File

@ -18,6 +18,8 @@
/*
* mcconf_rccar1.h
*
* This configuration is for my 4-pole 2.6kw inrunner.
*
* Created on: 14 apr 2014
* Author: benjamin
*/
@ -32,7 +34,8 @@
#define MCPWM_CURRENT_MIN -80.0 // Current limit in Amperes (Lower)
#define MCPWM_IN_CURRENT_MAX 80.0 // Input current limit in Amperes (Upper)
#define MCPWM_IN_CURRENT_MIN -25.0 // Input current limit in Amperes (Lower)
#define MCPWM_MAX_ABS_CURRENT 140.0 // The maximum absolute current above which a fault is generated
#define MCPWM_MAX_ABS_CURRENT 110.0 // The maximum absolute current above which a fault is generated
#define MCPWM_SLOW_ABS_OVERCURRENT 1 // Use the filtered (and hence slower) current for the overcurrent fault detection
#define MCPWM_CURRENT_STARTUP_BOOST 0.08 // The lowest duty cycle to use in current control mode @ 20V.
#define MCPWM_CURRENT_CONTROL_NO_REV 0 // Do not reverse the direction in current control mode, brake only
#define MCPWM_RPM_MAX 100000.0 // The motor speed limit (Upper)
@ -41,10 +44,11 @@
// Sensorless settings
#define MCPWM_IS_SENSORLESS 1 // Use sensorless commutation
#define MCPWM_MIN_RPM 300 // Auto-commutate below this RPM
#define MCPWM_CYCLE_INT_START_RPM_BR 5000.0 // RPM border between the START and LOW interval
#define MCPWM_CYCLE_INT_LIMIT_START 600.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_LOW 50.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 10.0 // Flux integrator limit 80K ERPM
#define MCPWM_CYCLE_INT_LIMIT_MAX 1000.0 // Maximum allowed flux integrator limit
#define MCPWM_CYCLE_INT_START_RPM_BR 80000.0 // RPM border between the START and LOW interval
#define MCPWM_CYCLE_INT_LIMIT_LOW 50.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 30.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_BEMF_INPUT_COUPLING_K 350.0 // Input voltage to bemf coupling constant
// Hall sensor settings
#define MCPWM_HALL_DIR 0 // Hall sensor direction [0 or 1]

69
mcconf/mcconf_rccar2.h Normal file
View File

@ -0,0 +1,69 @@
/*
Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* mcconf_rccar2.h
*
* This configuration is for my crappy coreless inrunner. Since this motor is coreless,
* the coupling constant is extremeley low compared to the other motors.
*
* Created on: 14 apr 2014
* Author: benjamin
*/
#ifndef MCCONF_RCCAR2_H_
#define MCCONF_RCCAR2_H_
/*
* Parameters
*/
#define MCPWM_CURRENT_MAX 80.0 // Current limit in Amperes (Upper)
#define MCPWM_CURRENT_MIN -80.0 // Current limit in Amperes (Lower)
#define MCPWM_IN_CURRENT_MAX 80.0 // Input current limit in Amperes (Upper)
#define MCPWM_IN_CURRENT_MIN -25.0 // Input current limit in Amperes (Lower)
#define MCPWM_MAX_ABS_CURRENT 110.0 // The maximum absolute current above which a fault is generated
#define MCPWM_SLOW_ABS_OVERCURRENT 1 // Use the filtered (and hence slower) current for the overcurrent fault detection
#define MCPWM_CURRENT_STARTUP_BOOST 0.08 // The lowest duty cycle to use in current control mode @ 20V.
#define MCPWM_CURRENT_CONTROL_NO_REV 0 // Do not reverse the direction in current control mode, brake only
#define MCPWM_RPM_MAX 100000.0 // The motor speed limit (Upper)
#define MCPWM_RPM_MIN -100000.0 // The motor speed limit (Lower)
// Sensorless settings
#define MCPWM_IS_SENSORLESS 1 // Use sensorless commutation
#define MCPWM_MIN_RPM 900 // Auto-commutate below this RPM
#define MCPWM_CYCLE_INT_LIMIT_MAX 1000.0 // Maximum allowed flux integrator limit
#define MCPWM_CYCLE_INT_START_RPM_BR 80000.0 // RPM border between the START and LOW interval
#define MCPWM_CYCLE_INT_LIMIT_LOW 40.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 30.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_BEMF_INPUT_COUPLING_K 5.0 // Input voltage to bemf coupling constant
// Hall sensor settings
#define MCPWM_HALL_DIR 0 // Hall sensor direction [0 or 1]
#define MCPWM_HALL_FWD_ADD 2 // Hall sensor offset fwd [0 to 5]
#define MCPWM_HALL_REV_ADD 3 // Hall sensor offset rev [0 to 5]
// Speed PID parameters
#define MCPWM_PID_KP 0.0001 // Proportional gain
#define MCPWM_PID_KI 0.002 // Integral gain
#define MCPWM_PID_KD 0.0 // Derivative gain
#define MCPWM_PID_MIN_RPM 950.0 // Minimum allowed RPM
// Current control parameters
#define MCPWM_CURRENT_CONTROL_GAIN 0.0046 // Current controller error gain
#define MCPWM_CURRENT_CONTROL_MIN 1.0 // Minimum allowed current
#endif /* MCCONF_RCCAR2_H_ */

View File

@ -37,17 +37,18 @@
#define MCPWM_RPM_MIN -50000.0 // The motor speed limit (Lower)
#define MCPWM_MIN_VOLTAGE 20.0 // Minimum input voltage
#define MCPWM_MAX_VOLTAGE 50.0 // Maximum input voltage
#define MCPWM_CURRENT_STARTUP_BOOST 0.03 // The lowest duty cycle to use in current control mode (has to be > MCPWM_MIN_DUTY_CYCLE)
#define MCPWM_CURRENT_STARTUP_BOOST 0.02 // The lowest duty cycle to use in current control mode (has to be > MCPWM_MIN_DUTY_CYCLE)
#define MCPWM_RPM_LIMIT_NEG_TORQUE 0 // Use negative torque to limit the RPM
#define MCPWM_CURR_MIN_RPM_FBRAKE 1500 // Minimum electrical RPM to use full brake at
// Sensorless settings
#define MCPWM_IS_SENSORLESS 1 // Use sensorless commutation
#define MCPWM_MIN_RPM 300 // Auto-commutate below this RPM
#define MCPWM_CYCLE_INT_START_RPM_BR 6000.0 // RPM border between the START and LOW interval
#define MCPWM_CYCLE_INT_LIMIT_START 1700.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_LOW 260.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 30.0 // Flux integrator limit 80K ERPM
#define MCPWM_MIN_RPM 250 // Auto-commutate below this RPM
#define MCPWM_CYCLE_INT_LIMIT_MAX 2800.0 // Maximum allowed flux integrator limit
#define MCPWM_CYCLE_INT_START_RPM_BR 80000.0 // RPM at the higher flux integrator limit
#define MCPWM_CYCLE_INT_LIMIT_LOW 90.0 // Flux integrator limit 0 ERPM
#define MCPWM_CYCLE_INT_LIMIT_HIGH 40.0 // Flux integrator limit MCPWM_CYCLE_INT_START_RPM_BR ERPM
#define MCPWM_BEMF_INPUT_COUPLING_K 300.0 // Input voltage to bemf coupling constant
// Speed PID parameters
#define MCPWM_PID_KP 0.0001 // Proportional gain

28
mcpwm.c
View File

@ -1039,16 +1039,14 @@ static msg_t rpm_thread(void *arg) {
rpm_p1 = rpm_now;
// Update the cycle integrator limit
rpm_dep.cycle_int_limit = utils_map(rpm_now,
MCPWM_CYCLE_INT_START_RPM_BR, 80000.0,
MCPWM_CYCLE_INT_LIMIT_LOW, MCPWM_CYCLE_INT_LIMIT_HIGH);
rpm_dep.cycle_int_limit = rpm_dep.cycle_int_limit_running = utils_map(rpm_now, 0,
MCPWM_CYCLE_INT_START_RPM_BR, MCPWM_CYCLE_INT_LIMIT_LOW,
MCPWM_CYCLE_INT_LIMIT_HIGH);
rpm_dep.cycle_int_limit_running = rpm_dep.cycle_int_limit + (float)ADC_Value[ADC_IND_VIN_SENS] *
MCPWM_BEMF_INPUT_COUPLING_K / (rpm_now > MCPWM_MIN_RPM ? rpm_now : MCPWM_MIN_RPM);
if (rpm_now < MCPWM_CYCLE_INT_START_RPM_BR) {
rpm_dep.cycle_int_limit_running = utils_map(rpm_now, 0,
MCPWM_CYCLE_INT_START_RPM_BR, MCPWM_CYCLE_INT_LIMIT_START,
MCPWM_CYCLE_INT_LIMIT_LOW);
} else {
rpm_dep.cycle_int_limit_running = rpm_dep.cycle_int_limit;
if (rpm_dep.cycle_int_limit_running > MCPWM_CYCLE_INT_LIMIT_MAX) {
rpm_dep.cycle_int_limit_running = MCPWM_CYCLE_INT_LIMIT_MAX;
}
chThdSleepMilliseconds(1);
@ -1376,7 +1374,7 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) {
/*
* Calculate the virtual ground, depending on the state.
*/
if (has_commutated && fabsf(dutycycle_now) > 0.1) {
if (has_commutated && fabsf(dutycycle_now) > 0.2) {
mcpwm_vzero = ADC_V_ZERO;
} else {
mcpwm_vzero = (ADC_V_L1 + ADC_V_L2 + ADC_V_L3) / 3;
@ -1448,10 +1446,10 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) {
if (has_commutated) {
limit = rpm_dep.cycle_int_limit_running * 0.0005;
} else {
limit = rpm_dep.cycle_int_limit * 0.0002;
limit = rpm_dep.cycle_int_limit * 0.0005;
}
if ((cycle_integrator >= (MCPWM_CYCLE_INT_LIMIT_START * 0.0005) || pwm_cycles_sum > last_pwm_cycles_sum / 3.0 || !has_commutated)
if ((cycle_integrator >= (MCPWM_CYCLE_INT_LIMIT_MAX * 0.0005) || pwm_cycles_sum > last_pwm_cycles_sum / 3.0 || !has_commutated)
&& cycle_integrator >= limit) {
commutate();
cycle_integrator = CYCLE_INT_START;
@ -1487,9 +1485,15 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) {
motor_current_iterations++;
input_current_iterations++;
#if MCPWM_SLOW_ABS_OVERCURRENT
if (fabsf(current) > MCPWM_MAX_ABS_CURRENT) {
fault_stop(FAULT_CODE_ABS_OVER_CURRENT);
}
#else
if (fabsf(current_nofilter) > MCPWM_MAX_ABS_CURRENT) {
fault_stop(FAULT_CODE_ABS_OVER_CURRENT);
}
#endif
if (state == MC_STATE_RUNNING && has_commutated) {
// Compensation for supply voltage variations

View File

@ -106,6 +106,8 @@ extern volatile int mcpwm_vzero;
#include "mcconf_outrunner2.h"
#elif defined MCCONF_RCCAR1
#include "mcconf_rccar1.h"
#elif defined MCCONF_RCCAR2
#include "mcconf_rccar2.h"
#elif defined MCCONF_STEN
#include "mcconf_sten.h"
#endif
@ -162,5 +164,8 @@ extern volatile int mcpwm_vzero;
#ifndef MCPWM_CURR_MIN_RPM_FBRAKE
#define MCPWM_CURR_MIN_RPM_FBRAKE 1500 // Minimum electrical RPM to use full brake at
#endif
#ifndef MCPWM_SLOW_ABS_OVERCURRENT
#define MCPWM_SLOW_ABS_OVERCURRENT 0 // Use the filtered (and hence slower) current for the overcurrent fault detection
#endif
#endif /* MC_PWM_H_ */