Skip to content

Commit

Permalink
Firmware revision 9 (patch 1)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
neoxic committed Jan 8, 2024
1 parent 15aaea7 commit 8ce1ca9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 13 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void resync(void) {
sync = 0;
accl = 0;
ival = 10000;
ertm = 60000000;
ertm = 100000000;
}
#endif

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -625,8 +630,8 @@ void main(void) {
laststep();
step = 0;
sine = 0;
prep = 0;
sync = 0;
prep = 0;
accl = 0;
ertm = 0;
erpm = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8ce1ca9

Please sign in to comment.