From c87af91880cac09ad52014c1765f42c84b01a06c Mon Sep 17 00:00:00 2001 From: alexklimaj Date: Tue, 19 Nov 2024 11:54:37 -0700 Subject: [PATCH] Rebase Alka Improve startup low kv motors ef2ec01871d6c81a2e98c9881048ba68371ef9d4 --- Inc/targets.h | 3 +++ Inc/version.h | 4 ++-- Mcu/f051/Inc/comparator.h | 12 +++++++++--- Mcu/g071/Src/peripherals.c | 7 +++++-- Src/main.c | 16 +++++++++++----- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Inc/targets.h b/Inc/targets.h index 13bde1a9..5ee42f93 100644 --- a/Inc/targets.h +++ b/Inc/targets.h @@ -1316,6 +1316,7 @@ #define USE_DRV8328_NFAULT #define NFAULT_PORT GPIOB #define NFAULT_PIN LL_GPIO_PIN_5 +#define TARGET_MIN_BEMF_COUNTS 3 #endif #ifdef RHINO80A_F051 @@ -3331,7 +3332,9 @@ #define APPLICATION_ADDRESS 0x08001000 #define MAIN_COMP COMP1 #define EXTI_LINE LL_EXTI_LINE_21 +#ifndef TARGET_MIN_BEMF_COUNTS #define TARGET_MIN_BEMF_COUNTS 2 +#endif #define COMPARATOR_IRQ ADC1_COMP_IRQn #define USE_ADC #ifndef CURRENT_ADC_PIN diff --git a/Inc/version.h b/Inc/version.h index 0f0d0125..67208d1d 100644 --- a/Inc/version.h +++ b/Inc/version.h @@ -2,6 +2,6 @@ update this file for new releases */ #define VERSION_MAJOR 2 -#define VERSION_MINOR 16 +#define VERSION_MINOR 17 -#define EEPROM_VERSION 2 \ No newline at end of file +#define EEPROM_VERSION 2 diff --git a/Mcu/f051/Inc/comparator.h b/Mcu/f051/Inc/comparator.h index dfb6c492..e08281b8 100644 --- a/Mcu/f051/Inc/comparator.h +++ b/Mcu/f051/Inc/comparator.h @@ -9,9 +9,15 @@ #define COMPARATOR_H_ #endif /* COMPARATOR_H_ */ -#define COMP_PA0 0b1100001 -#define COMP_PA4 0b1000001 -#define COMP_PA5 0b1010001 +// Medium speed comparator +#define COMP_PA0 0b1100101 +#define COMP_PA4 0b1000101 +#define COMP_PA5 0b1010101 + +// High speed comparator +// #define COMP_PA0 0b1100001 +// #define COMP_PA4 0b1000001 +// #define COMP_PA5 0b1010001 #include "main.h" diff --git a/Mcu/g071/Src/peripherals.c b/Mcu/g071/Src/peripherals.c index 0c725ffd..7cc9534f 100644 --- a/Mcu/g071/Src/peripherals.c +++ b/Mcu/g071/Src/peripherals.c @@ -134,7 +134,7 @@ void MX_COMP1_Init(void) COMP_InitStruct.OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED; COMP_InitStruct.OutputBlankingSource = LL_COMP_BLANKINGSRC_TIM1_OC5; LL_COMP_Init(COMP1, &COMP_InitStruct); - LL_COMP_SetPowerMode(COMP1, LL_COMP_POWERMODE_HIGHSPEED); + LL_COMP_SetPowerMode(COMP1, LL_COMP_POWERMODE_MEDIUMSPEED); LL_COMP_SetCommonWindowMode(__LL_COMP_COMMON_INSTANCE(COMP1), LL_COMP_WINDOWMODE_DISABLE); LL_COMP_SetCommonWindowOutput(__LL_COMP_COMMON_INSTANCE(COMP1), @@ -202,7 +202,7 @@ void MX_COMP2_Init(void) COMP_InitStruct.OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED; COMP_InitStruct.OutputBlankingSource = LL_COMP_BLANKINGSRC_TIM1_OC5; LL_COMP_Init(COMP2, &COMP_InitStruct); - LL_COMP_SetPowerMode(COMP2, LL_COMP_POWERMODE_HIGHSPEED); + LL_COMP_SetPowerMode(COMP2, LL_COMP_POWERMODE_MEDIUMSPEED); LL_COMP_SetCommonWindowMode(__LL_COMP_COMMON_INSTANCE(COMP2), LL_COMP_WINDOWMODE_DISABLE); LL_COMP_SetCommonWindowOutput(__LL_COMP_COMMON_INSTANCE(COMP2), @@ -822,4 +822,7 @@ void enableCorePeripherals() NVIC_SetPriority(EXTI4_15_IRQn, 2); NVIC_EnableIRQ(EXTI4_15_IRQn); EXTI->IMR1 |= (1 << 15); + #ifdef USE_PULSE_OUT + LL_GPIO_SetPinMode(RPM_PULSE_PORT, RPM_PULSE_PIN, LL_GPIO_MODE_OUTPUT); + #endif } diff --git a/Src/main.c b/Src/main.c index c4cb8197..94508ed0 100644 --- a/Src/main.c +++ b/Src/main.c @@ -835,9 +835,9 @@ void commutate() } __enable_irq(); changeCompInput(); - if (average_interval > 2500) { - old_routine = 1; - } +// if (average_interval > 2500) { +// old_routine = 1; +// } bemfcounter = 0; zcfound = 0; commutation_intervals[step - 1] = commutation_interval; // just used to calulate average @@ -1540,7 +1540,7 @@ void zcfoundroutine() enableCompInterrupts(); // enable interrupt } } else { - if (commutation_interval < 1300) { + if (zero_crosses > 30) { old_routine = 0; enableCompInterrupts(); // enable interrupt } @@ -1811,7 +1811,13 @@ int main(void) input_ready = 0; } #endif - +if(zero_crosses < 5){ + min_bemf_counts_up = TARGET_MIN_BEMF_COUNTS * 2; + min_bemf_counts_down = TARGET_MIN_BEMF_COUNTS * 2; +}else{ + min_bemf_counts_up = TARGET_MIN_BEMF_COUNTS; + min_bemf_counts_down = TARGET_MIN_BEMF_COUNTS; +} RELOAD_WATCHDOG_COUNTER(); e_com_time = ((commutation_intervals[0] + commutation_intervals[1] + commutation_intervals[2] + commutation_intervals[3] + commutation_intervals[4] + commutation_intervals[5]) + 4) >> 1; // COMMUTATION INTERVAL IS 0.5US INCREMENTS if (eepromBuffer.variable_pwm) {