Skip to content

Commit 3f029e9

Browse files
committed
Firmware revision 14 (patch 5)
Reduce overcurrent protection P-term Fix variable PWM frequency Add missing checkcfg() Add ESCAPE5 target Amend ESCAPE1 target
1 parent 0725185 commit 3f029e9

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ add_target(AIRBOT1 AT32F421 DEAD_TIME=66 COMP_MAP=321 SENS_MAP=0xA3A6 VOLT_MUL=7
5656
add_target(AIRBOT2 STM32F051 DEAD_TIME=26 COMP_MAP=321 SENS_MAP=0xA3 VOLT_MUL=738 IO_PA2)
5757
add_target(DYS1 STM32F051 DEAD_TIME=26 COMP_MAP=123 SENS_MAP=0xA6A3 CURR_MUL=60 LED_MAP=0xAFB3B4 LED_INV IO_PA2)
5858
add_target(EMAX1 STM32F051 DEAD_TIME=26 COMP_MAP=123 IO_PA2)
59-
add_target(ESCAPE1 STM32G071 DEAD_TIME=35 COMP_MAP=123 SENS_MAP=0xA5A4 VOLT_MUL=1100 CURR_MUL=30 LED_WS2812 LED_STAT IO_PA2 IO_AUX)
59+
add_target(ESCAPE1 STM32G071 DEAD_TIME=35 COMP_MAP=123 HALL_MAP=0xAFB35 SENS_MAP=0xA6A5A4 VOLT_MUL=1100 CURR_MUL=30 BEC_MAP=0xCEF LED_WS2812 LED_STAT IO_PA2)
6060
add_target(ESCAPE2 STM32G071 DEAD_TIME=35 COMP_MAP=123 SENS_MAP=0xA6 VOLT_MUL=1100 BEC_MAP=0xADE IO_PA2)
6161
add_target(ESCAPE3 AT32F421 DEAD_TIME=66 COMP_MAP=123 SENS_MAP=0xA6 VOLT_MUL=1100 BEC_MAP=0xADE)
62-
add_target(ESCAPE4 STM32G071 DEAD_TIME=35 COMP_MAP=123 HALL_MAP=0xB358 SENS_MAP=0xA6A5A4 TEMP_SENS=NTC10K3455UP2K VOLT_MUL=1100 CURR_MUL=30 BEC_MAP=0xCEF LED_MAP=0xF2AF LED1_INV LED_STAT IO_PA2)
62+
add_target(ESCAPE4 STM32G071 DEAD_TIME=35 COMP_MAP=123 HALL_MAP=0xB358 SENS_MAP=0xA6A5A4 VOLT_MUL=1100 CURR_MUL=30 BEC_MAP=0xCEF LED_MAP=0xF2AF LED1_INV LED_STAT IO_PA2)
63+
add_target(ESCAPE5 STM32G071 DEAD_TIME=35 COMP_MAP=123 SENS_MAP=0xA6 VOLT_MUL=1100 BEC_MAP=0xA45 LED_WS2812 LED_STAT IO_PA2)
6364
add_target(FLYCOLOR1 STM32F051 DEAD_TIME=26 COMP_MAP=123 SENS_MAP=0xA6 VOLT_MUL=1100 LED_MAP=0xB5B4B3 IO_PA2)
6465
add_target(FLYCOLOR2 STM32G071 DEAD_TIME=35 COMP_MAP=123 SENS_MAP=0xA6 VOLT_MUL=1100 LED_MAP=0xB8 LED_STAT)
6566
add_target(FREELYRC1 AT32F421 DEAD_TIME=66 COMP_MAP=123 SENS_MAP=0xA3 VOLT_MUL=1100 LED_WS2812 LED_STAT)

src/common.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,17 @@ static inline int clamp(int x, int a, int b) {return min(max(x, a), b);}
153153
// Temperature sensors
154154

155155
static inline int NTC10K3455LO2K(int x) {
156-
if (x < 100) return 0;
157156
return (x < 2338 ? (x - 1650) * 46 + 74841 : (x - 2640) * 83 + 132044) >> 8;
158157
}
159158

160159
static inline int NTC10K3455UP2K(int x) {
161-
if (x > 3200) return 0;
162160
return (x > 961 ? (x - 1650) * -46 + 74841 : (x - 660) * -83 + 132044) >> 8;
163161
}
164162

165163
static inline int NTC10K3455LO10K(int x) {
166-
if (x < 100) return 0;
167164
return (x < 2762 ? (x - 1650) * 36 + 25600 : (x - 3036) * 151 + 107130) >> 8;
168165
}
169166

170167
static inline int NTC10K3455UP10K(int x) {
171-
if (x > 3200) return 0;
172168
return (x > 537 ? (x - 1650) * -36 + 25600 : (x - 264) * -151 + 107130) >> 8;
173169
}

src/defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#endif
8484

8585
#ifndef TEMP_SENS
86-
#define TEMP_SENS(x) 0
86+
#define TEMP_SENS NTC10K3455UP2K
8787
#endif
8888
#ifndef VOLT_MUL
8989
#define VOLT_MUL 0 // %

src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "common.h"
1919

2020
#define REVISION 14
21-
#define REVPATCH 4
21+
#define REVPATCH 5
2222

2323
const Cfg cfgdata = {
2424
.id = 0x32ea,
@@ -65,7 +65,7 @@ const Cfg cfgdata = {
6565
.music = MUSIC, // Startup music
6666
.volume = VOLUME, // Sound volume (%) [0..100]
6767
.beacon = BEACON, // Beacon volume (%) [0..100]
68-
.bec = BEC, // BEC voltage control [0..3]
68+
.bec = BEC, // BEC voltage control (0 - 5.5V, 1 - 6.5V, 2 - 7.4V, 3 - 8.4V)
6969
.led = LED, // LED on/off bits [0..15]
7070
};
7171

@@ -427,7 +427,7 @@ void adcdata(int t, int u, int v, int c, int a) {
427427
c = 0;
428428
}
429429
temp1 = max((t = smooth(&st, t, 10)) >> 2, 0); // C
430-
temp2 = max((u = smooth(&su, TEMP_SENS(u), 10)) >> 2, 0); // C
430+
temp2 = hall || cfg.prot_sens ? max((u = smooth(&su, TEMP_SENS(u), 10)) >> 2, 0) : 0; // C
431431
volt = smooth(&sv, v * VOLT_MUL * 131 >> 17, 7); // V/100
432432
curr = smooth(&sc, c * CURR_MUL * 205 >> 11, 4); // A/100
433433
i += curr; // Current integral
@@ -607,7 +607,7 @@ void main(void) {
607607
#endif
608608
laststep();
609609
PID bpid = {.Kp = 50, .Ki = 0, .Kd = 1000}; // Stall protection
610-
PID cpid = {.Kp = 400, .Ki = 0, .Kd = 600}; // Overcurrent protection
610+
PID cpid = {.Kp = 80, .Ki = 0, .Kd = 600}; // Overcurrent protection
611611
for (int curduty = 0, running = 0, braking = 2, cutoff = 0, boost = 0, choke = 0, n = 0;;) {
612612
int ccr, arr = CLK_KHZ / cfg.freq_min;
613613
int input = cutoff == 3000 ? 0 : throt;
@@ -679,8 +679,8 @@ void main(void) {
679679
if (brushed && step != reverse + 1) step = 0; // Change brushed direction
680680
if ((newduty += boost - choke) < 0) newduty = 0;
681681
if (ertm) { // Variable PWM frequency
682+
arr = scale(ertm, 1000, 2000, CLK_KHZ / cfg.freq_max, arr); // 30..60 kERPM
682683
erpm = 60000000 / ertm;
683-
arr = scale(erpm, 30000, 60000, arr, CLK_KHZ / cfg.freq_max);
684684
}
685685
int maxduty = min(scale(erpm, 0, cfg.duty_ramp * 1000, cfg.duty_spup * 20, 2000), 2000 - cutback * 25); // 75% cutback at 15C above prot_temp
686686
if (newduty > maxduty) newduty = maxduty;

src/util.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#endif
3838

3939
#ifndef BEC_MAP
40+
#elif BEC_MAP == 0xA45
41+
#define BEC_PORT A
42+
#define BEC_PIN1 4
43+
#define BEC_PIN2 5
4044
#elif BEC_MAP == 0xB35
4145
#define BEC_PORT B
4246
#define BEC_PIN1 3
@@ -497,6 +501,7 @@ int resetcfg(void) {
497501
__disable_irq();
498502
memcpy(&cfg, &cfgdata, sizeof cfgdata);
499503
__enable_irq();
504+
checkcfg();
500505
return savecfg();
501506
}
502507

0 commit comments

Comments
 (0)