Skip to content

Commit

Permalink
Firmware revision 7 (patch 1)
Browse files Browse the repository at this point in the history
Fix bug that led to delayed state reset after a desync
Drop logic that halved commutation delay on rapid acceleration
Revert increased acceleration slew rate above 60kERPM
  • Loading branch information
neoxic committed Sep 24, 2023
1 parent ac0c7e5 commit 96abd5a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ static char prep, accl, tick, reverse, ready;
}
#endif

#ifndef SENSORED
static void resync(void) {
TIM_DIER(IFTIM) = 0;
sync = 0;
accl = 0;
ival = 10000;
ertm = 100000000;
}
#endif

/*
6-step commutation sequence:
# +|- mask code
Expand Down Expand Up @@ -239,7 +249,7 @@ static void nextstep(void) {
cnt = 0;
} else if (++cnt == 6) {
if ((val > ival ? val - ival : ival - val) > ival >> 1) { // Probably desync
TIM_DIER(IFTIM) = TIM_DIER_UIE;
resync();
return;
}
val = ival;
Expand Down Expand Up @@ -295,11 +305,7 @@ void iftim_isr(void) { // BEMF zero-crossing
int sr = TIM_SR(IFTIM);
if ((er & TIM_DIER_UIE) && (sr & TIM_SR_UIF)) { // Timeout
TIM_SR(IFTIM) = ~TIM_SR_UIF;
TIM_DIER(IFTIM) = 0;
sync = 0;
accl = 0;
ival = 10000;
ertm = 100000000;
resync();
return;
}
if (!(er & IFTIM_ICE)) return;
Expand All @@ -308,7 +314,7 @@ void iftim_isr(void) { // BEMF zero-crossing
int u = ival * 3;
accl = t < u >> 2 && sync == 6; // Rapid acceleration
ival = (t + u) >> 2; // Commutation interval
IFTIM_OCR = ((ival >> 1) - (ival * cfg.timing >> 4)) >> accl; // Commutation delay
IFTIM_OCR = (ival >> 1) - (ival * cfg.timing >> 4); // Commutation delay
TIM_EGR(IFTIM) = TIM_EGR_UG;
TIM_DIER(IFTIM) = 0;
if (sync < 6) ++sync;
Expand Down Expand Up @@ -524,7 +530,7 @@ void main(void) {
int maxduty = sync < 6 ? cfg.duty_spup * 20 : scale(erpm, 0, cfg.duty_ramp * 1000, 500, 2000);
if ((newduty -= choke) < 0) newduty = 0;
if (newduty > maxduty) newduty = maxduty;
int a = accl ? 0 : cfg.duty_rate << (erpm > 60000);
int a = accl ? 0 : cfg.duty_rate;
int b = a >> 3;
if (r < (a & 7)) ++b;
if (++r == 8) r = 0;
Expand Down

0 comments on commit 96abd5a

Please sign in to comment.