@@ -335,7 +335,7 @@ char RC_CAR_REVERSE = 0; // have to set bidirectional, comp_pwm off and stall pr
335
335
uint16_t ADC_CCR = 30 ;
336
336
uint16_t current_angle = 90 ;
337
337
uint16_t desired_angle = 90 ;
338
-
338
+ char return_to_center = 0 ;
339
339
uint16_t target_e_com_time = 0 ;
340
340
int16_t Speed_pid_output ;
341
341
char use_speed_control_loop = 0 ;
@@ -1002,32 +1002,40 @@ void setInput()
1002
1002
if (newinput > (1000 + (servo_dead_band << 1 ))) {
1003
1003
if (forward == dir_reversed ) {
1004
1004
adjusted_input = 0 ;
1005
- if (running ) {
1005
+ // if (running) {
1006
1006
prop_brake_active = 1 ;
1007
- } else {
1008
- forward = 1 - dir_reversed ;
1009
- }
1007
+ if (return_to_center ){
1008
+ forward = 1 - dir_reversed ;
1009
+ prop_brake_active = 0 ;
1010
+ return_to_center = 0 ;
1011
+ }
1010
1012
}
1011
1013
if (prop_brake_active == 0 ) {
1014
+ return_to_center = 0 ;
1012
1015
adjusted_input = map (newinput , 1000 + (servo_dead_band << 1 ), 2000 , 47 , 2047 );
1013
1016
}
1014
1017
}
1015
1018
if (newinput < (1000 - (servo_dead_band << 1 ))) {
1016
- if (forward == (1 - dir_reversed )) {
1017
- if ( running ) {
1019
+ if (forward == (1 - dir_reversed )) {
1020
+ adjusted_input = 0 ;
1018
1021
prop_brake_active = 1 ;
1019
- } else {
1020
- forward = dir_reversed ;
1021
- }
1022
- adjusted_input = 0 ;
1022
+ if (return_to_center ){
1023
+ forward = dir_reversed ;
1024
+ prop_brake_active = 0 ;
1025
+ return_to_center = 0 ;
1026
+ }
1023
1027
}
1024
1028
if (prop_brake_active == 0 ) {
1029
+ return_to_center = 0 ;
1025
1030
adjusted_input = map (newinput , 0 , 1000 - (servo_dead_band << 1 ), 2047 , 47 );
1026
1031
}
1027
1032
}
1028
1033
if (newinput >= (1000 - (servo_dead_band << 1 )) && newinput <= (1000 + (servo_dead_band << 1 ))) {
1029
1034
adjusted_input = 0 ;
1030
- prop_brake_active = 0 ;
1035
+ if (prop_brake_active ) {
1036
+ prop_brake_active = 0 ;
1037
+ return_to_center = 1 ;
1038
+ }
1031
1039
}
1032
1040
} else {
1033
1041
if (newinput > (1000 + (servo_dead_band << 1 ))) {
@@ -1210,7 +1218,7 @@ void setInput()
1210
1218
}
1211
1219
1212
1220
if (!comp_pwm ) {
1213
- duty_cycle = 0 ;
1221
+ duty_cycle_setpoint = 0 ;
1214
1222
if (!running ) {
1215
1223
old_routine = 1 ;
1216
1224
zero_crosses = 0 ;
@@ -1224,8 +1232,8 @@ void setInput()
1224
1232
}
1225
1233
if (RC_CAR_REVERSE && prop_brake_active ) {
1226
1234
#ifndef PWM_ENABLE_BRIDGE
1227
- duty_cycle = getAbsDif (1000 , newinput ) + 1000 ;
1228
- if (duty_cycle == 2000 ) {
1235
+ duty_cycle_setpoint = getAbsDif (1000 , newinput ) + 1000 ;
1236
+ if (duty_cycle_setpoint >= 1999 ) {
1229
1237
fullBrake ();
1230
1238
} else {
1231
1239
proportionalBrake ();
@@ -1457,7 +1465,7 @@ void tenKhzRoutine()
1457
1465
} else {
1458
1466
1459
1467
if (prop_brake_active ) {
1460
- adjusted_duty_cycle = TIMER1_MAX_ARR - (( duty_cycle * tim1_arr )/ TIMER1_MAX_ARR ) ;
1468
+ adjusted_duty_cycle = TIMER1_MAX_ARR - duty_cycle ;
1461
1469
} else {
1462
1470
adjusted_duty_cycle = ((duty_cycle * tim1_arr ) / TIMER1_MAX_ARR );
1463
1471
}
@@ -1551,6 +1559,9 @@ void zcfoundroutine()
1551
1559
}
1552
1560
#ifdef MCU_GDE23
1553
1561
TIMER_CAR (COM_TIMER ) = waitTime ;
1562
+ #endif
1563
+ #ifdef MCU_F051
1564
+ COM_TIMER -> ARR = waitTime ;
1554
1565
#endif
1555
1566
commutate ();
1556
1567
bemfcounter = 0 ;
0 commit comments