Skip to content

Commit 43b32ba

Browse files
committed
fix arming on no signal, remove throttle protection below 300kv
1 parent 0c4cbf5 commit 43b32ba

File tree

2 files changed

+56
-34
lines changed

2 files changed

+56
-34
lines changed

Src/main.c

+35-19
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102
*1.70 fix dshot for Kiss FC
103103
*1.71 fix dshot for Ardupilot / Px4 FC
104104
*1.72 Fix telemetry output and add 1 second arming.
105+
*1.73 Fix false arming if no signal. Remove low rpm throttle protection below 300kv
105106
*/
106-
107107
#include <stdint.h>
108108
#include "main.h"
109109
#include "targets.h"
@@ -121,7 +121,7 @@
121121

122122

123123
#define VERSION_MAJOR 1
124-
#define VERSION_MINOR 72
124+
#define VERSION_MINOR 73
125125

126126
typedef struct __attribute__((packed)) {
127127
uint8_t version_major;
@@ -135,6 +135,8 @@ firmware_info_s __attribute__ ((section(".firmware_info"))) firmware_info = {
135135
device_name: FIRMWARE_NAME
136136
};
137137

138+
uint8_t EEPROM_VERSION;
139+
138140
//firmware build options
139141
char BRUSHED_MODE = 0; // overrides everything else
140142
char RC_CAR_REVERSE = 0; // have to set bidirectional, comp_pwm off and stall protection off, no sinusoidal startup
@@ -151,6 +153,7 @@ uint32_t REV_Id = 0;
151153

152154
uint16_t loop_time = 0;
153155
uint16_t last_loop_time = 0;
156+
uint16_t armed_timeout_count;
154157

155158
uint8_t desync_happened = 0;
156159
char maximum_throttle_change_ramp = 1;
@@ -526,6 +529,9 @@ void loadEEpromSettings(){
526529
}
527530
}
528531

532+
if(motor_kv < 300){
533+
low_rpm_throttle_limit = 0;
534+
}
529535
low_rpm_level = motor_kv / 200 / (16 / motor_poles);
530536
high_rpm_level = (40 + (motor_kv / 100)) / (16/motor_poles);
531537

@@ -741,8 +747,9 @@ void tenKhzRoutine(){
741747
if(!armed){
742748
if(inputSet){
743749
if(adjusted_input == 0){
744-
zero_input_count++;
745-
if(zero_input_count > 10000){ // one second
750+
armed_timeout_count++;
751+
if(armed_timeout_count > 10000){ // one second
752+
if(zero_input_count > 30){
746753
armed = 1;
747754
#ifdef tmotor55
748755
GPIOB->BRR = LL_GPIO_PIN_3; // turn off red
@@ -761,9 +768,13 @@ if(!armed){
761768
if(!servoPwm){
762769
RC_CAR_REVERSE = 0;
763770
}
771+
}else{
772+
inputSet = 0;
773+
armed_timeout_count =0;
774+
}
764775
}
765776
}else{
766-
zero_input_count =0;
777+
armed_timeout_count =0;
767778
}
768779
}
769780
}
@@ -815,10 +826,10 @@ if(!armed){
815826
if(!running){
816827
old_routine = 1;
817828
zero_crosses = 0;
818-
if(brake_on_stop){
819-
fullBrake();
829+
if(brake_on_stop){
830+
fullBrake();
820831

821-
}
832+
}
822833
}
823834
if (RC_CAR_REVERSE && prop_brake_active) {
824835
#ifndef PWM_ENABLE_BRIDGE
@@ -958,10 +969,10 @@ if(desync_check){
958969
if(send_telemetry){
959970
#ifdef USE_SERIAL_TELEMETRY
960971
makeTelemPackage(degrees_celsius,
961-
battery_voltage,
962-
actual_current,
963-
(uint16_t)consumed_current/10,
964-
e_rpm);
972+
battery_voltage,
973+
actual_current,
974+
(uint16_t)consumed_current/10,
975+
e_rpm);
965976
send_telem_DMA();
966977
send_telemetry = 0;
967978
#endif
@@ -1060,7 +1071,8 @@ void zcfoundroutine(){ // only used in polling mode, blocking routine.
10601071
commutation_interval = (thiszctime + (3*commutation_interval)) / 4;
10611072
advance = commutation_interval / advancedivisor;
10621073
waitTime = commutation_interval /2 - advance;
1063-
while (INTERVAL_TIMER->CNT < waitTime){
1074+
// blanktime = commutation_interval / 4;
1075+
while (INTERVAL_TIMER->CNT - thiszctime < waitTime - advance){
10641076

10651077
}
10661078
commutate();
@@ -1157,6 +1169,7 @@ int main(void)
11571169

11581170

11591171
loadEEpromSettings();
1172+
// EEPROM_VERSION = *(uint8_t*)(0x08000FFC);
11601173
if(firmware_info.version_major != eepromBuffer[3] || firmware_info.version_minor != eepromBuffer[4]){
11611174
eepromBuffer[3] = firmware_info.version_major;
11621175
eepromBuffer[4] = firmware_info.version_minor;
@@ -1165,6 +1178,10 @@ int main(void)
11651178
}
11661179
saveEEpromSettings();
11671180
}
1181+
// if(EEPROM_VERSION != eepromBuffer[2]){
1182+
// eepromBuffer[2] = EEPROM_VERSION;
1183+
// saveEEpromSettings();
1184+
// }
11681185

11691186

11701187
if(use_sin_start){
@@ -1202,10 +1219,10 @@ int main(void)
12021219
}else{
12031220
playStartupTune();
12041221
}
1205-
1222+
zero_input_count = 0;
12061223
MX_IWDG_Init();
12071224
LL_IWDG_ReloadCounter(IWDG);
1208-
zero_input_count = 0;
1225+
12091226

12101227
if (GIMBAL_MODE){
12111228
bi_direction = 1;
@@ -1294,6 +1311,7 @@ if(newinput > 2000){
12941311
}
12951312
#endif
12961313
stuckcounter = 0;
1314+
12971315
if (bi_direction == 1 && proshot == 0 && dshot == 0){
12981316
if(RC_CAR_REVERSE){
12991317
if (newinput > (1000 + (servo_dead_band<<1))) {
@@ -1489,7 +1507,7 @@ if(newinput > 2000){
14891507
}
14901508
if ( stepper_sine == 0){
14911509

1492-
e_rpm = running *(100000/ e_com_time) * 6;
1510+
e_rpm = running * (100000/ e_com_time) * 6;
14931511
k_erpm = e_rpm / 10; // ecom time is time for one electrical revolution in microseconds
14941512
if(low_rpm_throttle_limit){ // some hardware doesn't need this, its on by default to keep hardware / motors protected but can slow down the response in the very low end a little.
14951513

@@ -1648,6 +1666,4 @@ void assert_failed(uint8_t *file, uint32_t line)
16481666
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
16491667
/* USER CODE END 6 */
16501668
}
1651-
#endif /* USE_FULL_ASSERT */
1652-
1653-
1669+
#endif /* USE_FULL_ASSERT */

Src/signal.c

+21-15
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ void computeMSInput(){
3232

3333
void computeServoInput(){
3434

35-
int lastnumber = dma_buffer[0];
36-
for ( int j = 1 ; j < 2; j++){
3735

38-
if(((dma_buffer[j] - lastnumber) >900 ) && ((dma_buffer[j] - lastnumber) < 2150)){ // blank space
36+
if(((dma_buffer[1] - dma_buffer[0]) >900 ) && ((dma_buffer[1] - dma_buffer[0]) < 2150)){
3937

4038
if(bi_direction){
41-
if(dma_buffer[j] - lastnumber <= servo_neutral){
42-
servorawinput = map((dma_buffer[j] - lastnumber), servo_low_threshold, servo_neutral, 0, 1000);
39+
if(dma_buffer[1] - dma_buffer[0] <= servo_neutral){
40+
servorawinput = map((dma_buffer[1] - dma_buffer[0]), servo_low_threshold, servo_neutral, 0, 1000);
4341
}else{
44-
servorawinput = map((dma_buffer[j] - lastnumber), servo_neutral+1, servo_high_threshold, 1001, 2000);
42+
servorawinput = map((dma_buffer[1] - dma_buffer[0]), servo_neutral+1, servo_high_threshold, 1001, 2000);
4543
}
4644
}else{
47-
servorawinput = map((dma_buffer[j] - lastnumber), servo_low_threshold, servo_high_threshold, 0, 2000);
45+
servorawinput = map((dma_buffer[1] - dma_buffer[0]), servo_low_threshold, servo_high_threshold, 0, 2000);
4846
}
49-
break;
47+
signaltimeout = 0;
48+
49+
}else{
50+
zero_input_count = 0; // reset if out of range
5051
}
51-
lastnumber = dma_buffer[j];
52-
}
52+
5353
if (servorawinput - newinput > max_servo_deviation){
5454
newinput += max_servo_deviation;
5555
}else if(newinput - servorawinput > max_servo_deviation){
@@ -83,10 +83,8 @@ void transfercomplete(){
8383
}
8484

8585
if (inputSet == 1){
86-
if(!armed){
87-
signaltimeout = 0;
8886

89-
}
87+
9088

9189
if(dshot_telemetry){
9290
if(out_put){
@@ -110,14 +108,22 @@ if(dshot_telemetry){
110108
}
111109
if (servoPwm == 1){
112110
computeServoInput();
113-
// IC_TIMER_REGISTER->CNT = 0;
114-
signaltimeout = 0;
115111
LL_TIM_IC_SetPolarity(IC_TIMER_REGISTER, IC_TIMER_CHANNEL, LL_TIM_IC_POLARITY_RISING); // setup rising pin trigger.
116112
receiveDshotDma();
117113
LL_DMA_EnableIT_HT(DMA1, INPUT_DMA_CHANNEL);
118114
}
119115

120116
}
117+
if(!armed){
118+
if (adjusted_input < 0){
119+
adjusted_input = 0;
120+
}
121+
if (adjusted_input == 0){ // note this in input..not newinput so it will be adjusted be main loop
122+
zero_input_count++;
123+
}else{
124+
zero_input_count = 0;
125+
}
126+
}
121127
}
122128
}
123129

0 commit comments

Comments
 (0)