Skip to content

Commit

Permalink
remove auto_advance, reintroduced advance_level logic
Browse files Browse the repository at this point in the history
  • Loading branch information
freasy committed Aug 16, 2024
1 parent 614fb33 commit dd68113
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 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
24 changes: 9 additions & 15 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -759,12 +763,6 @@ void loadEEpromSettings()
}
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 +774,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 +870,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 Expand Up @@ -1643,9 +1637,9 @@ int main(void)

// EEPROM_VERSION = *(uint8_t*)(0x08000FFC);

if((*(uint32_t*)(0x08000FE0)) == 0xf8){
eeprom_address = (uint32_t)0x0800F800;
}
if((*(uint32_t*)(0x08000FE0)) == 0xf8){
eeprom_address = (uint32_t)0x0800F800;
}


#ifdef USE_MAKE
Expand Down

0 comments on commit dd68113

Please sign in to comment.