DC Link converted to fixed-point

This commit is contained in:
EmanuelFeru 2019-10-12 19:51:31 +02:00
parent d87e9d68c6
commit f6fc825e5f
3 changed files with 13 additions and 14 deletions

View File

@ -7,6 +7,7 @@
#define DEAD_TIME 32 // PWM deadtime #define DEAD_TIME 32 // PWM deadtime
#define DELAY_IN_MAIN_LOOP 5 // in ms. default 5. it is independent of all the timing critical stuff. do not touch if you do not know what you are doing. #define DELAY_IN_MAIN_LOOP 5 // in ms. default 5. it is independent of all the timing critical stuff. do not touch if you do not know what you are doing.
#define TIMEOUT 5 // number of wrong / missing input commands before emergency off #define TIMEOUT 5 // number of wrong / missing input commands before emergency off
#define A2BIT_CONV 50 // bits per A on ADC. Example: 50 = 1 A, 100 = 2 A, etc
// ADC conversion time definitions // ADC conversion time definitions
#define ADC_CONV_TIME_1C5 (14) //Total ADC clock cycles / conversion = ( 1.5+12.5) #define ADC_CONV_TIME_1C5 (14) //Total ADC clock cycles / conversion = ( 1.5+12.5)
@ -93,13 +94,13 @@
// ############################### MOTOR CONTROL (overwrite) ######################### // ############################### MOTOR CONTROL (overwrite) #########################
#define CTRL_TYP_SEL 1 // [-] Control type selection: 0 = Commutation , 1 = FOC Field Oriented Control (default) #define CTRL_TYP_SEL 1 // [-] Control type selection: 0 = Commutation , 1 = FOC Field Oriented Control (default)
#define CTRL_MOD_REQ 1 // [-] Control mode request: 0 = Open mode, 1 = Voltage mode (default), 2 = Speed mode, 3 = Torque mode #define CTRL_MOD_REQ 1 // [-] Control mode request: 0 = Open mode, 1 = Voltage mode (default), 2 = Speed mode, 3 = Torque mode
#define DIAG_ENA 1 // [-] Motor Diagnostics enable flag: 0 = Disabled, 1 = Enabled (default) #define DIAG_ENA 1 // [-] Motor Diagnostics enable flag: 0 = Disabled, 1 = Enabled (default)
#define FIELD_WEAK_ENA 0 // [-] Field Weakening enable flag: 0 = Disabled (default), 1 = Enabled #define FIELD_WEAK_ENA 0 // [-] Field Weakening enable flag: 0 = Disabled (default), 1 = Enabled
#define I_MOT_MAX (15 * 50) << 4 // [A] Maximum motor current (change only the first number, the rest is needed for fixed-point conversion) #define I_MOT_MAX (15 * A2BIT_CONV) << 4 // [A] Maximum motor current limit (Change only the first number, the rest is needed for fixed-point conversion)
#define DC_CUR_LIMIT 17 // [A] DC current limit in amps per motor. (Final current protection. Above this value, current chopping is applied. To avoid this make sure that DC_CUR_LIMIT = I_MOT_MAX + 2A ) #define I_DC_MAX (17 * A2BIT_CONV) // [A] Maximum DC Link current limit (This is the final current protection. Above this value, current chopping is applied. To avoid this make sure that I_DC_MAX = I_MOT_MAX + 2A )
#define N_MOT_MAX 800 << 4 // [rpm] Maximum motor speed (change only the first number, the rest is needed for fixed-point conversion) #define N_MOT_MAX 800 << 4 // [rpm] Maximum motor speed (change only the first number, the rest is needed for fixed-point conversion)
// GENERAL NOTES: // GENERAL NOTES:

View File

@ -123,15 +123,13 @@
#define DELAY_TIM_FREQUENCY_US 1000000 #define DELAY_TIM_FREQUENCY_US 1000000
#define MOTOR_AMP_CONV_DC_AMP 0.02f // A per bit (12) on ADC.
#define MILLI_R (R * 1000) #define MILLI_R (R * 1000)
#define MILLI_PSI (PSI * 1000) #define MILLI_PSI (PSI * 1000)
#define MILLI_V (V * 1000) #define MILLI_V (V * 1000)
#define NO 0 #define NO 0
#define YES 1 #define YES 1
#define ABS(a) (((a) < 0.0f) ? -(a) : (a)) #define ABS(a) (((a) < 0) ? -(a) : (a))
#define LIMIT(x, lowhigh) (((x) > (lowhigh)) ? (lowhigh) : (((x) < (-lowhigh)) ? (-lowhigh) : (x))) #define LIMIT(x, lowhigh) (((x) > (lowhigh)) ? (lowhigh) : (((x) < (-lowhigh)) ? (-lowhigh) : (x)))
#define SAT(x, lowhigh) (((x) > (lowhigh)) ? (1.0f) : (((x) < (-lowhigh)) ? (-1.0f) : (0.0f))) #define SAT(x, lowhigh) (((x) > (lowhigh)) ? (1.0f) : (((x) < (-lowhigh)) ? (-1.0f) : (0.0f)))
#define SAT2(x, low, high) (((x) > (high)) ? (1.0f) : (((x) < (low)) ? (-1.0f) : (0.0f))) #define SAT2(x, low, high) (((x) > (high)) ? (1.0f) : (((x) < (low)) ? (-1.0f) : (0.0f)))

View File

@ -1,5 +1,5 @@
/* /*
* This file has been re-implemented FOC motor control. * This file implements FOC motor control.
* This control method offers superior performanace * This control method offers superior performanace
* compared to previous cummutation method. The new method features: * compared to previous cummutation method. The new method features:
* reduced noise and vibrations * reduced noise and vibrations
@ -66,7 +66,7 @@ static uint32_t buzzerTimer = 0;
uint8_t enable = 0; uint8_t enable = 0;
static uint8_t enableFin = 0; static uint8_t enableFin = 0;
static const uint16_t pwm_res = 64000000 / 2 / PWM_FREQ; // = 2000 static const uint16_t pwm_res = 64000000 / 2 / PWM_FREQ; // = 2000
static uint16_t offsetcount = 0; static uint16_t offsetcount = 0;
static int16_t offsetrl1 = 2000; static int16_t offsetrl1 = 2000;
@ -113,7 +113,7 @@ void DMA1_Channel1_IRQHandler(void) {
curR_DC = (int16_t)(adc_buffer.dcr - offsetdcr); curR_DC = (int16_t)(adc_buffer.dcr - offsetdcr);
// Disable PWM when current limit is reached (current chopping) // Disable PWM when current limit is reached (current chopping)
if(ABS(curL_DC * MOTOR_AMP_CONV_DC_AMP) > DC_CUR_LIMIT || timeout > TIMEOUT || enable == 0) { if(ABS(curL_DC) > I_DC_MAX || timeout > TIMEOUT || enable == 0) {
LEFT_TIM->BDTR &= ~TIM_BDTR_MOE; LEFT_TIM->BDTR &= ~TIM_BDTR_MOE;
//HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1); //HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
} else { } else {
@ -121,7 +121,7 @@ void DMA1_Channel1_IRQHandler(void) {
//HAL_GPIO_WritePin(LED_PORT, LED_PIN, 0); //HAL_GPIO_WritePin(LED_PORT, LED_PIN, 0);
} }
if(ABS(curR_DC * MOTOR_AMP_CONV_DC_AMP) > DC_CUR_LIMIT || timeout > TIMEOUT || enable == 0) { if(ABS(curR_DC) > I_DC_MAX || timeout > TIMEOUT || enable == 0) {
RIGHT_TIM->BDTR &= ~TIM_BDTR_MOE; RIGHT_TIM->BDTR &= ~TIM_BDTR_MOE;
} else { } else {
RIGHT_TIM->BDTR |= TIM_BDTR_MOE; RIGHT_TIM->BDTR |= TIM_BDTR_MOE;