Skip to content

Commit

Permalink
remove auto advance, readd advance_level logic
Browse files Browse the repository at this point in the history
  • Loading branch information
freasy committed Aug 21, 2024
1 parent 614fb33 commit ebd2e60
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
3 changes: 0 additions & 3 deletions Inc/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ typedef union EEprom_u {
uint8_t input_type; // 46
uint8_t reserved_2[5]; //47-51
uint8_t tune[124]; // 52-175
//eeprom v3
uint8_t auto_advance; // 176
char unused[7]; //177-183
};
uint8_t buffer[184];
} EEprom_t;
Expand Down
2 changes: 2 additions & 0 deletions Inc/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*/
#define VERSION_MAJOR 2
#define VERSION_MINOR 16

#define EEPROM_VERSION 2
21 changes: 7 additions & 14 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ enum inputType {
EDTARM,
};


EEprom_t eepromBuffer;
uint32_t eeprom_address = EEPROM_START_ADD;
char set_hysteris = 0;
uint16_t prop_brake_duty_cycle = 0;
Expand All @@ -315,7 +315,7 @@ uint16_t target_e_com_time_low;
uint8_t compute_dshot_flag = 0;
uint8_t crsf_input_channel = 1;
uint8_t crsf_output_PWM_channel = 2;
char eeprom_layout_version = 3;
char eeprom_layout_version = EEPROM_VERSION;
uint8_t telemetry_interval_ms = 30;
char temp_advance = 1;
uint16_t motor_kv = 2000;
Expand Down Expand Up @@ -621,6 +621,10 @@ void loadEEpromSettings()
//*eepromBuffer = *(EEprom_t*)(eeprom_address);
read_flash_bin(eepromBuffer.buffer, eeprom_address, sizeof(eepromBuffer.buffer));

if (eepromBuffer.advance_level > 3) {
eepromBuffer.advance_level = 2;
}

if (eepromBuffer.pwm_frequency < 49 && eepromBuffer.pwm_frequency > 7) {
if (eepromBuffer.pwm_frequency < 49 && eepromBuffer.pwm_frequency > 23) {
TIMER1_MAX_ARR = map(eepromBuffer.pwm_frequency, 24, 48, TIM1_AUTORELOAD, TIM1_AUTORELOAD / 2);
Expand Down Expand Up @@ -758,13 +762,6 @@ void loadEEpromSettings()
high_rpm_level = motor_kv / 12 / (32 / eepromBuffer.motor_poles);
}
reverse_speed_threshold = map(motor_kv, 300, 3000, 1000, 500);

if (eepromBuffer.eeprom_version > 2) {
if (eepromBuffer.auto_advance > 1) {
eepromBuffer.auto_advance = 0;
save_flash_nolib(eepromBuffer.buffer, sizeof(eepromBuffer.buffer), eeprom_address);
}
}
// reverse_speed_threshold = 200;
// if (!eepromBuffer.comp_pwm) {
// eepromBuffer.bi_direction = 0;
Expand All @@ -776,10 +773,6 @@ void saveEEpromSettings()

eepromBuffer.eeprom_version = eeprom_layout_version;

if (eepromBuffer.eeprom_version == 2) {
eepromBuffer.auto_advance = 0;
}

save_flash_nolib(eepromBuffer.buffer, sizeof(eepromBuffer.buffer), eeprom_address);
}

Expand Down Expand Up @@ -876,7 +869,7 @@ void PeriodElapsedCallback()
DISABLE_COM_TIMER_INT(); // disable interrupt
commutate();
commutation_interval = (3 * commutation_interval + thiszctime) >> 2;
if (!eepromBuffer.auto_advance) {
if (!eepromBuffer.use_hall_sensors) {
advance = (commutation_interval >> 3) * temp_advance; // 60 divde 8 7.5 degree increments
} else {
advance = (commutation_interval * auto_advance_level) >> 6; // 60 divde 64 0.9375 degree increments
Expand Down
2 changes: 0 additions & 2 deletions Src/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include "serial_telemetry.h"
#include "sounds.h"
#include "targets.h"

EEprom_t eepromBuffer;
int max_servo_deviation = 250;
int servorawinput;
uint16_t smallestnumber = 20000;
Expand Down

0 comments on commit ebd2e60

Please sign in to comment.