From 8ce1ca984ab40bc2cb0b006fc7e2d1b70b8e145a Mon Sep 17 00:00:00 2001 From: neoxic Date: Sun, 7 Jan 2024 22:25:09 -0800 Subject: [PATCH] Firmware revision 9 (patch 1) Engage drag brake only after rotor has stopped Take lowest ramp point from "duty_spup" rather than fixed 25% Maximum "duty_spup" is 50 (was 25) Default "duty_drag" is 0 (was 75) --- src/defs.h | 2 +- src/io.c | 2 +- src/main.c | 21 +++++++++++++-------- src/util.c | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/defs.h b/src/defs.h index 088bd50..5dd6e29 100644 --- a/src/defs.h +++ b/src/defs.h @@ -174,7 +174,7 @@ #define DUTY_RATE 25 #endif #ifndef DUTY_DRAG -#define DUTY_DRAG 75 +#define DUTY_DRAG 0 #endif #ifndef THROT_MODE #define THROT_MODE 0 diff --git a/src/io.c b/src/io.c index 7a3f9ce..ac95063 100644 --- a/src/io.c +++ b/src/io.c @@ -649,7 +649,7 @@ static void sbustx(void) { b = a >> 8 | 0x80; break; case 1: // SBS-01R (RPM) - a = min(erpm / (6 * cfg.telem_poles >> 1), 0xffff); + a = min(erpm / (cfg.telem_poles * 3), 0xffff); b = a >> 8; break; case 2: // SBS-01C (current) diff --git a/src/main.c b/src/main.c index abc066f..8fd88e4 100644 --- a/src/main.c +++ b/src/main.c @@ -89,7 +89,7 @@ static void resync(void) { sync = 0; accl = 0; ival = 10000; - ertm = 60000000; + ertm = 100000000; } #endif @@ -142,7 +142,8 @@ static void nextstep(void) { TIM1_CCMR2 = m2; TIM1_CCER = er; step = 1; - sync = 6; + sync = 1; + ertm = 60000000; return; } if (sine) { // Sine startup @@ -182,6 +183,7 @@ static void nextstep(void) { TIM1_EGR = TIM_EGR_UG | TIM_EGR_COMG; TIM_DIER(IFTIM) = 0; compctl(0); + sync = 0; prep = 1; return; } @@ -547,8 +549,11 @@ void main(void) { running = 1; } } else { // Neutral - curduty = cfg.duty_drag * 20; - running = 0; + if (sync == 6) curduty = 0; // Coasting + else { // Drag brake + curduty = cfg.duty_drag * 20; + running = 0; + } if (braking == 1) braking = 2; // Reverse after braking } #ifndef SENSORED @@ -568,8 +573,8 @@ void main(void) { TIM_EGR(IFTIM) = TIM_EGR_UG; step = b + 1; // Switch over to 6-step sine = 0; - prep = 0; sync = 0; + prep = 0; accl = 0; ival = 10000; nextstep(); @@ -582,7 +587,7 @@ void main(void) { erpm = 60000000 / ertm; arr = scale(erpm, 30000, 60000, arr, CLK_KHZ / cfg.freq_max); // Variable PWM frequency } - int maxduty = sync < 6 ? cfg.duty_spup * 20 : scale(erpm, 0, cfg.duty_ramp * 1000, 500, 2000); + int maxduty = scale(erpm, 0, cfg.duty_ramp * 1000, cfg.duty_spup * 20, 2000); if ((newduty -= choke) < 0) newduty = 0; if (newduty > maxduty) newduty = maxduty; int a = accl ? 0 : cfg.duty_rate; @@ -602,7 +607,7 @@ void main(void) { if (running && !step) { // Start motor __disable_irq(); ival = 10000; - ertm = 60000000; + ertm = 100000000; nextstep(); TIM1_EGR = TIM_EGR_UG | TIM_EGR_COMG; TIM1_DIER |= TIM_DIER_COMIE; @@ -625,8 +630,8 @@ void main(void) { laststep(); step = 0; sine = 0; - prep = 0; sync = 0; + prep = 0; accl = 0; ertm = 0; erpm = 0; diff --git a/src/util.c b/src/util.c index 623bceb..483d2a9 100644 --- a/src/util.c +++ b/src/util.c @@ -126,7 +126,7 @@ void checkcfg(void) { cfg.freq_max = clamp(cfg.freq_max, cfg.freq_min, 96); cfg.duty_min = clamp(cfg.duty_min, 1, 100); cfg.duty_max = clamp(cfg.duty_max, cfg.duty_min, 100); - cfg.duty_spup = clamp(cfg.duty_spup, 1, 25); + cfg.duty_spup = clamp(cfg.duty_spup, 1, 50); cfg.duty_ramp = clamp(cfg.duty_ramp, 0, 100); cfg.duty_rate = clamp(cfg.duty_rate, 1, 100); cfg.duty_drag = clamp(cfg.duty_drag, 0, 100);