@@ -432,7 +432,7 @@ uint16_t ADC_raw_temp;
432
432
uint16_t ADC_raw_volts ;
433
433
uint16_t ADC_raw_current ;
434
434
uint16_t ADC_raw_input ;
435
- uint8_t adc_counter = 0 ;
435
+ uint8_t PROCESS_ADC_FLAG = 0 ;
436
436
char send_telemetry = 0 ;
437
437
char telemetry_done = 0 ;
438
438
char prop_brake_active = 0 ;
@@ -447,10 +447,10 @@ uint16_t adjusted_input = 0;
447
447
#define TEMP110_CAL_VALUE ((uint16_t*)((uint32_t)0x1FFFF7C2))
448
448
449
449
uint16_t smoothedcurrent = 0 ;
450
- const uint8_t numReadings = 100 ; // the readings from the analog input
450
+ const uint8_t numReadings = 50 ; // the readings from the analog input
451
451
uint8_t readIndex = 0 ; // the index of the current reading
452
452
uint32_t total = 0 ;
453
- uint16_t readings [100 ];
453
+ uint16_t readings [50 ];
454
454
455
455
uint8_t bemf_timeout_happened = 0 ;
456
456
uint8_t changeover_step = 5 ;
@@ -711,9 +711,9 @@ void loadEEpromSettings()
711
711
use_current_limit = 1 ;
712
712
}
713
713
714
- currentPid .Kp = eepromBuffer .current_P ;
714
+ currentPid .Kp = eepromBuffer .current_P * 2 ;
715
715
currentPid .Ki = eepromBuffer .current_I ;
716
- currentPid .Kd = eepromBuffer .current_D ;
716
+ currentPid .Kd = eepromBuffer .current_D * 2 ;
717
717
718
718
if (eepromBuffer .sine_mode_power == 0 || eepromBuffer .sine_mode_power > 10 ) {
719
719
eepromBuffer .sine_mode_power = 5 ;
@@ -1348,6 +1348,7 @@ void tenKhzRoutine()
1348
1348
}
1349
1349
#endif
1350
1350
if (one_khz_loop_counter > PID_LOOP_DIVIDER ) { // 1khz PID loop
1351
+ PROCESS_ADC_FLAG = 1 ; // set flag to do new adc read at lower priority
1351
1352
one_khz_loop_counter = 0 ;
1352
1353
if (use_current_limit && running ) {
1353
1354
use_current_limit_adjust -= (int16_t )(doPidCalculations (& currentPid , actual_current ,
@@ -1789,7 +1790,6 @@ int main(void)
1789
1790
#endif
1790
1791
1791
1792
while (1 ) {
1792
-
1793
1793
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
1794
1794
#if defined(FIXED_DUTY_MODE ) || defined(FIXED_SPEED_MODE )
1795
1795
setInput ();
@@ -1966,8 +1966,7 @@ if(zero_crosses < 5){
1966
1966
send_telem_DMA (49 );
1967
1967
send_esc_info_flag = 0 ;
1968
1968
}
1969
- adc_counter ++ ;
1970
- if (adc_counter > 200 ) { // for adc and telemetry
1969
+ if (PROCESS_ADC_FLAG == 1 ) { // for adc and telemetry set adc counter at 1khz loop rate
1971
1970
#if defined(STMICRO )
1972
1971
ADC_DMA_Callback ();
1973
1972
LL_ADC_REG_StartConversion (ADC1 );
@@ -2013,7 +2012,7 @@ if(zero_crosses < 5){
2013
2012
}
2014
2013
}
2015
2014
}
2016
- if (low_voltage_count > (20000 - (stepper_sine * 18000 ))) {
2015
+ if (low_voltage_count > (10000 - (stepper_sine * 9900 ))) { // 10 second wait before cut-off for low voltage
2017
2016
LOW_VOLTAGE_CUTOFF = 1 ;
2018
2017
input = 0 ;
2019
2018
allOff ();
@@ -2023,7 +2022,7 @@ if(zero_crosses < 5){
2023
2022
armed = 0 ;
2024
2023
}
2025
2024
2026
- adc_counter = 0 ;
2025
+ PROCESS_ADC_FLAG = 0 ;
2027
2026
#ifdef USE_ADC_INPUT
2028
2027
if (ADC_raw_input < 10 ) {
2029
2028
zero_input_count ++ ;
0 commit comments