DC Link converted to fixed-point
This commit is contained in:
parent
d87e9d68c6
commit
f6fc825e5f
|
@ -7,6 +7,7 @@
|
|||
#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 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
|
||||
#define ADC_CONV_TIME_1C5 (14) //Total ADC clock cycles / conversion = ( 1.5+12.5)
|
||||
|
@ -97,8 +98,8 @@
|
|||
#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 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 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_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 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)
|
||||
|
||||
|
||||
|
|
|
@ -123,15 +123,13 @@
|
|||
|
||||
#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_PSI (PSI * 1000)
|
||||
#define MILLI_V (V * 1000)
|
||||
|
||||
#define NO 0
|
||||
#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 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)))
|
||||
|
|
|
@ -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
|
||||
* compared to previous cummutation method. The new method features:
|
||||
* ► reduced noise and vibrations
|
||||
|
@ -113,7 +113,7 @@ void DMA1_Channel1_IRQHandler(void) {
|
|||
curR_DC = (int16_t)(adc_buffer.dcr - offsetdcr);
|
||||
|
||||
// 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;
|
||||
//HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
|
||||
} else {
|
||||
|
@ -121,7 +121,7 @@ void DMA1_Channel1_IRQHandler(void) {
|
|||
//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;
|
||||
} else {
|
||||
RIGHT_TIM->BDTR |= TIM_BDTR_MOE;
|
||||
|
|
Loading…
Reference in New Issue