103
103
*1.71 fix dshot for Ardupilot / Px4 FC
104
104
*1.72 Fix telemetry output and add 1 second arming.
105
105
*1.73 Fix false arming if no signal. Remove low rpm throttle protection below 300kv
106
+ *1.74 Add Sine Mode range and drake brake strength adjustment
106
107
*/
107
108
#include <stdint.h>
108
109
#include "main.h"
121
122
122
123
123
124
#define VERSION_MAJOR 1
124
- #define VERSION_MINOR 73
125
+ #define VERSION_MINOR 74
125
126
126
127
typedef struct __attribute__((packed )) {
127
128
uint8_t version_major ;
@@ -141,7 +142,7 @@ uint8_t EEPROM_VERSION;
141
142
char BRUSHED_MODE = 0 ; // overrides everything else
142
143
char RC_CAR_REVERSE = 0 ; // have to set bidirectional, comp_pwm off and stall protection off, no sinusoidal startup
143
144
char GIMBAL_MODE = 0 ; // also sinusoidal_startup needs to be on.
144
-
145
+ char USE_HALL_SENSOR = 0 ;
145
146
//move these to targets folder or peripherals for each mcu
146
147
147
148
@@ -157,6 +158,8 @@ uint16_t armed_timeout_count;
157
158
158
159
uint8_t desync_happened = 0 ;
159
160
char maximum_throttle_change_ramp = 1 ;
161
+ char sine_mode_changeover_thottle_level = 5 ;
162
+ char drag_brake_strength = 10 ;
160
163
161
164
char crawler_mode = 0 ; // no longer used //
162
165
uint16_t velocity_count = 0 ;
@@ -527,8 +530,24 @@ void loadEEpromSettings(){
527
530
}else {
528
531
RC_CAR_REVERSE = 0 ;
529
532
}
533
+ if (eepromBuffer [39 ] == 0x01 ){
534
+ #ifdef HAS_HALL_SENSORS
535
+ USE_HALL_SENSOR = 1 ;
536
+ #else
537
+ USE_HALL_SENSOR = 0 ;
538
+ #endif
539
+ }else {
540
+ USE_HALL_SENSOR = 0 ;
541
+ }
542
+ if (eepromBuffer [40 ] > 4 && eepromBuffer [40 ] < 26 ){ // sine mode changeover 5-25 percent throttle
543
+ sine_mode_changeover_thottle_level = eepromBuffer [40 ];
544
+ }
545
+ if (eepromBuffer [41 ] > 0 && eepromBuffer [41 ] < 11 ){ // drag brake 0-10
546
+ drag_brake_strength = eepromBuffer [41 ];
547
+ }
530
548
}
531
549
550
+
532
551
if (motor_kv < 300 ){
533
552
low_rpm_throttle_limit = 0 ;
534
553
}
@@ -790,6 +809,7 @@ if(!armed){
790
809
if (!stepper_sine && !BRUSHED_MODE ){
791
810
if (input >= 47 + (80 * use_sin_start ) && armed ){
792
811
if (running == 0 ){
812
+ allOff ();
793
813
if (!old_routine ){
794
814
startMotor ();
795
815
}
@@ -802,13 +822,14 @@ if(!armed){
802
822
#endif
803
823
804
824
}
805
- // coasting = 0;
806
- // running = 1;
807
825
if (use_sin_start ){
808
826
duty_cycle = map (input , 127 , 2047 , minimum_duty_cycle , TIMER1_MAX_ARR );
809
827
}else {
810
828
duty_cycle = map (input , 47 , 2047 , minimum_duty_cycle , TIMER1_MAX_ARR );
811
829
}
830
+ if (!RC_CAR_REVERSE ){
831
+ prop_brake_active = 0 ;
832
+ }
812
833
}
813
834
if (input < 47 + (80 * use_sin_start )){
814
835
if (play_tone_flag != 0 ){
@@ -828,7 +849,6 @@ if(!armed){
828
849
zero_crosses = 0 ;
829
850
if (brake_on_stop ){
830
851
fullBrake ();
831
-
832
852
}
833
853
}
834
854
if (RC_CAR_REVERSE && prop_brake_active ) {
@@ -846,8 +866,11 @@ if(!armed){
846
866
zero_crosses = 0 ;
847
867
bad_count = 0 ;
848
868
if (brake_on_stop ){
849
- fullBrake ();
850
-
869
+ if (!use_sin_start ){
870
+ duty_cycle = 1980 + drag_brake_strength * 2 ;
871
+ proportionalBrake ();
872
+ prop_brake_active = 1 ;
873
+ }
851
874
}else {
852
875
allOff ();
853
876
duty_cycle = 0 ;
@@ -930,15 +953,11 @@ if (running){
930
953
}
931
954
adjusted_duty_cycle = ((duty_cycle * tim1_arr )/TIMER1_MAX_ARR )+ 1 ;
932
955
}else {
933
- if (RC_CAR_REVERSE ){
934
956
if (prop_brake_active ){
935
957
adjusted_duty_cycle = TIMER1_MAX_ARR - ((duty_cycle * tim1_arr )/TIMER1_MAX_ARR )+ 1 ;
936
958
}else {
937
959
adjusted_duty_cycle = 0 ;
938
960
}
939
- }else {
940
- adjusted_duty_cycle = 0 ;
941
- }
942
961
}
943
962
last_duty_cycle = duty_cycle ;
944
963
@@ -950,7 +969,7 @@ if (running){
950
969
TIM1 -> CCR3 = adjusted_duty_cycle ;
951
970
}
952
971
average_interval = e_com_time / 3 ;
953
- if (desync_check ){
972
+ if (desync_check && zero_crosses > 10 ){
954
973
// if(average_interval < last_average_interval){
955
974
//
956
975
// }
@@ -1502,8 +1521,20 @@ if(newinput > 2000){
1502
1521
GPIOB -> BSRR = LL_GPIO_PIN_3 ;
1503
1522
#endif
1504
1523
}else {
1505
- input = adjusted_input ;
1506
-
1524
+ if (use_sin_start ){
1525
+ if (adjusted_input < 30 ){ // dead band ?
1526
+ input = 0 ;
1527
+ }
1528
+
1529
+ if (adjusted_input > 30 && adjusted_input < (sine_mode_changeover_thottle_level * 20 )){
1530
+ input = map (adjusted_input , 30 , (sine_mode_changeover_thottle_level * 20 ) , 47 ,160 );
1531
+ }
1532
+ if (adjusted_input >= (sine_mode_changeover_thottle_level * 20 )){
1533
+ input = map (adjusted_input , (sine_mode_changeover_thottle_level * 20 ) ,2000 , 160 , 2000 );
1534
+ }
1535
+ }else {
1536
+ input = adjusted_input ;
1537
+ }
1507
1538
}
1508
1539
if ( stepper_sine == 0 ){
1509
1540
@@ -1600,7 +1631,7 @@ if (old_routine && running){
1600
1631
if (input > 48 && armed ){
1601
1632
1602
1633
if (input > 48 && input < 137 ){// sine wave stepper
1603
- // LL_TIM_DisableIT_UPDATE(TIM1);
1634
+
1604
1635
maskPhaseInterrupts ();
1605
1636
allpwm ();
1606
1637
advanceincrement ();
@@ -1621,9 +1652,11 @@ if(input > 48 && armed){
1621
1652
old_routine = 1 ;
1622
1653
commutation_interval = 9000 ;
1623
1654
average_interval = 9000 ;
1655
+ last_average_interval = average_interval ;
1624
1656
// minimum_duty_cycle = ;
1625
1657
INTERVAL_TIMER -> CNT = 9000 ;
1626
1658
zero_crosses = 0 ;
1659
+ prop_brake_active = 0 ;
1627
1660
step = changeover_step ; // rising bemf on a same as position 0.
1628
1661
comStep (step );// rising bemf on a same as position 0.
1629
1662
LL_TIM_GenerateEvent_UPDATE (TIM1 );
@@ -1632,10 +1665,23 @@ if(input > 48 && armed){
1632
1665
}
1633
1666
1634
1667
}else {
1635
- TIM1 -> CCR1 = 0 ; // set duty cycle to 50 out of 768 to start.
1668
+ if (brake_on_stop ){
1669
+ duty_cycle = 1980 + drag_brake_strength * 2 ;
1670
+ adjusted_duty_cycle = TIMER1_MAX_ARR - ((duty_cycle * tim1_arr )/TIMER1_MAX_ARR )+ 1 ;
1671
+ TIM1 -> ARR = tim1_arr ;
1672
+ TIM1 -> CCR1 = adjusted_duty_cycle ;
1673
+ TIM1 -> CCR2 = adjusted_duty_cycle ;
1674
+ TIM1 -> CCR3 = adjusted_duty_cycle ;
1675
+ proportionalBrake ();
1676
+ prop_brake_active = 1 ;
1677
+ }else {
1678
+ TIM1 -> CCR1 = 0 ;
1636
1679
TIM1 -> CCR2 = 0 ;
1637
1680
TIM1 -> CCR3 = 0 ;
1638
- fullBrake ();
1681
+ allOff ();
1682
+ }
1683
+
1684
+
1639
1685
}
1640
1686
1641
1687
}
0 commit comments