From fc2cb4d0dafc818a74d7dc1c140433e72e4a1853 Mon Sep 17 00:00:00 2001 From: AlkaMotors <37931458+AlkaMotors@users.noreply.github.com> Date: Tue, 24 Dec 2024 08:36:20 -0400 Subject: [PATCH] ramp rate and comparator interrupt changes g071 f421 f051 f415 --- Inc/targets.h | 94 +++++++++++++++++++++++++++----------- Mcu/f051/Inc/comparator.h | 2 +- Mcu/f051/Src/comparator.c | 19 ++++---- Mcu/f415/Src/at32f415_it.c | 11 +++-- 4 files changed, 88 insertions(+), 38 deletions(-) diff --git a/Inc/targets.h b/Inc/targets.h index 4de226d9..44b732ee 100644 --- a/Inc/targets.h +++ b/Inc/targets.h @@ -73,6 +73,18 @@ #define USE_INTERNAL_AMP #endif +#ifdef NEUTRON_SINGLE_L431 +#define FILE_NAME "NEUTRON_SINGLE_L431" +#define FIRMWARE_NAME "Neutron L4 S" +#define DEAD_TIME 70 +#define HARDWARE_GROUP_L4_N +#define TARGET_VOLTAGE_DIVIDER 210 +#define CURRENT_OFFSET 498 +#define MILLIVOLT_PER_AMP 8 +#define USE_SERIAL_TELEMETRY +#define USE_INTERNAL_AMP +#endif + #ifdef VIMDRONES_L431 #define FIRMWARE_NAME "VimdroneL431" #define FILE_NAME "VIMDRONES_L431" @@ -133,7 +145,7 @@ #ifdef REF_L431 #define FILE_NAME "REF_L431" -#define FIRMWARE_NAME "L431 Neutron" +#define FIRMWARE_NAME "L431 TEST" #define DEAD_TIME 80 #define HARDWARE_GROUP_L4_A #define TARGET_VOLTAGE_DIVIDER 260 @@ -358,6 +370,18 @@ #define PA6_NTC_ONLY #endif +#ifdef F4A_RUSH_F421 +#define FIRMWARE_NAME "F4A RUSH " +#define FILE_NAME "F4A_RUSH_F421" +#define DEAD_TIME 40 +#define HARDWARE_GROUP_AT_540 +#define HARDWARE_GROUP_AT_E +#define USE_SERIAL_TELEMETRY +#define USE_PA14_TELEMETRY +#define PA6_NTC_ONLY +#endif + + #ifdef F4A_SINGLE_F421 #define FIRMWARE_NAME "F4A Single " #define FILE_NAME "F4A_SINGLE_F421" @@ -365,7 +389,7 @@ #define HARDWARE_GROUP_AT_540 #define HARDWARE_GROUP_AT_E #define USE_SERIAL_TELEMETRY -#define USE_PA14_TELEMETRY +//#define USE_PA14_TELEMETRY #define PA6_NTC_ONLY #endif @@ -400,6 +424,18 @@ #define ADC_CHANNEL_VOLTAGE ADC_CHANNEL_6 #endif +#ifdef JHEMCU_F421 +#define FIRMWARE_NAME "JHEMCU_F421 " +#define FILE_NAME "JHEMCU_F421" +#define DEAD_TIME 80 +#define HARDWARE_GROUP_AT_B +#define HARDWARE_GROUP_AT_045 +#define USE_SERIAL_TELEMETRY +#define ADC_CHANNEL_CURRENT ADC_CHANNEL_3 +#define ADC_CHANNEL_VOLTAGE ADC_CHANNEL_6 +#define TARGET_MIN_BEMF_COUNTS 3 +#endif + #ifdef FLASHHOBBY_F421 #define FIRMWARE_NAME "FH F421 " #define FILE_NAME "FLASHHOBBY_F421" @@ -524,7 +560,7 @@ #define ADC_CHANNEL_VOLTAGE ADC_CHANNEL_6 #endif -#ifdef TEKKO32_4IN1_F421 +#ifdef TEKKO32_4IN1_F421 #define FIRMWARE_NAME "Tekko32 4in1" #define FILE_NAME "TEKKO32_4IN1_F421" #define DEAD_TIME 80 @@ -589,24 +625,6 @@ #define ADC_CHANNEL_TEMP ADC_CHANNEL_6 #endif -#ifdef FLYROTOR_F421 -#define FIRMWARE_NAME "FLYROTOR_150" -#define FILE_NAME "FLYROTOR_F421" -#define DEAD_TIME 100 -#define HARDWARE_GROUP_AT_B -#define HARDWARE_GROUP_AT_450 -#define USE_SERIAL_TELEMETRY -#define MILLIVOLT_PER_AMP 19 -#define TARGET_VOLTAGE_DIVIDER 190 -#define USE_NTC -#define USE_LED_STRIP -#define WS2812_PIN GPIO_PINS_3 -#define USE_PULSE_OUT -#define ADC_CHANNEL_CURRENT ADC_CHANNEL_3 -#define ADC_CHANNEL_VOLTAGE ADC_CHANNEL_2 -#define ADC_CHANNEL_TEMP ADC_CHANNEL_6 -#endif - #ifdef HAKRC_K_F421 #define FIRMWARE_NAME "HAKRC F4 K " #define FILE_NAME "HAKRC_K_F421" @@ -658,7 +676,7 @@ #endif #ifdef TEKKO32_F421 -#define FIRMWARE_NAME "Tekko32 F4" +#define FIRMWARE_NAME "Tekko32 F421" #define FILE_NAME "TEKKO32_F421" #define DEAD_TIME 60 #define HARDWARE_GROUP_AT_045 @@ -789,7 +807,7 @@ #endif #ifdef TEKKO32_F415 -#define FIRMWARE_NAME "Tekko32 F4 " +#define FIRMWARE_NAME "Tekko32 F415" #define FILE_NAME "TEKKO32_F415" #define DEAD_TIME 100 #define HARDWARE_GROUP_AT_D @@ -902,6 +920,15 @@ #define USE_SERIAL_TELEMETRY #endif +#ifdef SKYSTARS_KO60_F421 +#define FIRMWARE_NAME "F421 KO60 " +#define FILE_NAME "SKYSTARS_KO60_F421" +#define DEAD_TIME 60 +#define HARDWARE_GROUP_AT_B +#define HARDWARE_GROUP_AT_045 +#define USE_SERIAL_TELEMETRY +#endif + #ifdef SKYSTARS_KM65_F421 #define FIRMWARE_NAME "F421 KM65" #define FILE_NAME "SKYSTARS_KM65_F421" @@ -1120,7 +1147,7 @@ #define DEAD_TIME 45 #define HARDWARE_GROUP_F0_B #define USE_SERIAL_TELEMETRY -// #define USE_RGB_LED +#define USE_RGB_LED #endif #ifdef OCDRC_F051 @@ -1633,7 +1660,7 @@ #define TARGET_VOLTAGE_DIVIDER 110 #define HARDWARE_GROUP_G0_A #define USE_SERIAL_TELEMETRY -#define SIXTY_FOUR_KB_MEMORY +//#define SIXTY_FOUR_KB_MEMORY #define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_4 #define CURRENT_ADC_PIN LL_GPIO_PIN_4 #define USE_LED_STRIP @@ -1890,6 +1917,21 @@ #define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_7 #endif +#ifdef CRAWLMASTER_F031 +#define FILE_NAME "CRAWLMASTER_F031" +#define FIRMWARE_NAME "HH CM F031" +#define DEAD_TIME 60 +#define HARDWARE_GROUP_F031_A +#define TARGET_STALL_PROTECTION_INTERVAL 8000 +#define MILLIVOLT_PER_AMP 28 +#define USE_SERIAL_TELEMETRY +#define CURRENT_SENSE_ADC_PIN LL_GPIO_PIN_5 +#define VOLTAGE_SENSE_ADC_PIN LL_GPIO_PIN_7 + +#define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_5 +#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_7 +#endif + #ifndef FIRMWARE_NAME /* if you get this then you have forgotten to add the section for your target above */ #error "Missing defines for target" @@ -3501,7 +3543,7 @@ #define TARGET_MIN_BEMF_COUNTS 3 // #define USE_SERIAL_TELEMETRY // moved to individual ESCs #define USE_ADC -#define LOOP_FREQUENCY_HZ 10000 +#define LOOP_FREQUENCY_HZ 20000 #endif #ifdef MCU_G071 diff --git a/Mcu/f051/Inc/comparator.h b/Mcu/f051/Inc/comparator.h index bf6a4933..0d659ed7 100644 --- a/Mcu/f051/Inc/comparator.h +++ b/Mcu/f051/Inc/comparator.h @@ -14,7 +14,7 @@ //#define COMP_PA4 0b1000101 //#define COMP_PA5 0b1010101 -// High speed comparator +//// High speed comparator #define COMP_PA0 0b1100001 #define COMP_PA4 0b1000001 #define COMP_PA5 0b1010001 diff --git a/Mcu/f051/Src/comparator.c b/Mcu/f051/Src/comparator.c index 32850e2b..21868340 100644 --- a/Mcu/f051/Src/comparator.c +++ b/Mcu/f051/Src/comparator.c @@ -6,12 +6,13 @@ */ #include "comparator.h" - +#include "common.h" #include "targets.h" COMP_TypeDef* active_COMP = COMP1; uint8_t getCompOutputLevel() { return LL_COMP_ReadOutputLevel(active_COMP); } +uint8_t medium_speed_set; void maskPhaseInterrupts() { @@ -23,9 +24,6 @@ void enableCompInterrupts() { EXTI->IMR |= (1 << 21); } void changeCompInput() { - // TIM3->CNT = 0; - // HAL_COMP_Stop_IT(&hcomp1); // done in comparator interrupt - // routine if (step == 1 || step == 4) { // c floating COMP->CSR = PHASE_C_COMP; @@ -36,13 +34,18 @@ void changeCompInput() if (step == 3 || step == 6) { // b floating COMP->CSR = PHASE_B_COMP; } +if((average_interval < 400)){ +COMP->CSR = COMP->CSR & ~(1<<2); + +medium_speed_set = 0; +} +if((average_interval > 600)){ +COMP->CSR = COMP->CSR | 1<<2; +medium_speed_set = 1; +} if (rising) { EXTI->RTSR = 0x0; EXTI->FTSR = 0x200000; - - // hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_FALLING; // - // polarity of - // comp output reversed } else { // falling bemf EXTI->FTSR = 0x0; diff --git a/Mcu/f415/Src/at32f415_it.c b/Mcu/f415/Src/at32f415_it.c index b0462bd7..de33ac78 100644 --- a/Mcu/f415/Src/at32f415_it.c +++ b/Mcu/f415/Src/at32f415_it.c @@ -20,6 +20,8 @@ int recieved_ints = 0; #include "ADC.h" #include "main.h" #include "targets.h" +#include "comparator.h" +#include "common.h" /** @addtogroup AT32F421_StdPeriph_Templates * @{ */ @@ -164,11 +166,14 @@ void DMA1_Channel6_IRQHandler(void) */ void CMP1_IRQHandler(void) { - if ((EXINT->intsts & EXTI_LINE) != (uint32_t)RESET) { - // EXTI->PND = EXTI_LINE; + if((INTERVAL_TIMER->cval) > ((average_interval>>1))){ + EXINT->intsts = EXTI_LINE; + interruptRoutine(); + }else{ + if (getCompOutputLevel() == rising){ EXINT->intsts = EXTI_LINE; - interruptRoutine(); } + } } /**