Skip to content

Commit

Permalink
ramp rate and comparator interrupt changes g071 f421 f051 f415
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkaMotors committed Dec 29, 2024
1 parent 6669105 commit fc2cb4d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 38 deletions.
94 changes: 68 additions & 26 deletions Inc/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -358,14 +370,26 @@
#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"
#define DEAD_TIME 60
#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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Mcu/f051/Inc/comparator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions Mcu/f051/Src/comparator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions Mcu/f415/Src/at32f415_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @{
*/
Expand Down Expand Up @@ -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();
}
}
}

/**
Expand Down

0 comments on commit fc2cb4d

Please sign in to comment.