Skip to content

Commit

Permalink
Firmware revision 4
Browse files Browse the repository at this point in the history
+ Improved acceleration and desync detection
+ Maximum "duty_spup" at 25% for safety
+ Fractional "duty_ramp"
+ CLI "reset" command saves settings
+ DSHOT command 47 resets settings
+ Audio feedback tones for better simultaneous beeping
+ Account for HV lipos during cell count autodetection

No comparator blanking above 30K ERPM
ANALOG fix drag brake
Accommodate DSHOT commands 42,43 to fractional value
Beep revision number via "info"
Cosmetics
  • Loading branch information
neoxic committed Jun 28, 2023
1 parent 79cba2d commit 289a8de
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 89 deletions.
2 changes: 1 addition & 1 deletion mcu/GD32E230/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void tim1_brk_up_trg_com_isr(void) {
int sr = TIM1_SR;
if (sr & TIM_SR_UIF) {
TIM1_SR = ~TIM_SR_UIF;
COMP_CSR &= ~0x700; // COMP_OUT off
if (TIM1_CCR4) COMP_CSR &= ~0x700; // COMP_OUT off
}
if (sr & TIM_SR_COMIF) tim1_com_isr();
}
Expand Down
2 changes: 1 addition & 1 deletion mcu/STM32F051/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void tim1_brk_up_trg_com_isr(void) {
int sr = TIM1_SR;
if (sr & TIM_SR_UIF) {
TIM1_SR = ~TIM_SR_UIF;
COMP_CSR &= ~0x700; // COMP1_OUT off
if (TIM1_CCR4) COMP_CSR &= ~0x700; // COMP1_OUT off
}
if (sr & TIM_SR_COMIF) tim1_com_isr();
}
Expand Down
18 changes: 7 additions & 11 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static int setbeepval(int val) {
}

int execcmd(char *buf) {
static const char *const cmds[] = {"help", "info", "show", "get", "set", "reset", "save", "play", "throt", "beep", 0};
static const char *const cmds[] = {"help", "info", "show", "get", "set", "save", "reset", "play", "throt", "beep", 0};
static const char *const keys[] = {
#define XX(idx, type, key) #key,
CFG_MAP(XX)
Expand All @@ -133,8 +133,8 @@ CFG_MAP(XX)
"show\n"
"get <param>\n"
"set <param> <value>\n"
"reset\n"
"save\n"
"reset\n"
"play <music> [<volume>]\n"
"throt <value>\n"
"beep\n"
Expand All @@ -143,7 +143,7 @@ CFG_MAP(XX)
case 1: // 'info'
if (narg != 1) goto error;
appendstr(&pos, "ESCape32 rev");
appendval(&pos, cfg.revision);
appendval(&pos, setbeepval(cfg.revision));
appendstr(&pos, " [");
appendstr(&pos, cfg.target_name);
appendstr(&pos, "]\nTemp: ");
Expand Down Expand Up @@ -195,16 +195,12 @@ CFG_MAP(XX)
goto error;
}
break;
case 5: // 'reset'
if (narg != 1) goto error;
__disable_irq();
memcpy(&cfg, &cfgdata, sizeof cfgdata);
__enable_irq();
setbeepval(1);
break;
case 6: // 'save'
case 5: // 'save'
if (narg != 1 || !setbeepval(savecfg())) goto error;
break;
case 6: // 'reset'
if (narg != 1 || !setbeepval(resetcfg())) goto error;
break;
case 7: // 'play <music> [<volume>]'
if (narg < 2 || narg > 3) goto error;
val = cfg.volume;
Expand Down
3 changes: 2 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extern char _cfg[], _cfg_start[], _cfg_end[], _rom[], _ram[], _boot[], _vec[]; /
extern const uint16_t sinedata[];
extern const Cfg cfgdata;
extern Cfg cfg;
extern int throt, erpt, erpm, temp, volt, curr, csum, dshotval, beepval;
extern int throt, ertm, erpm, temp, volt, curr, csum, dshotval, beepval;
extern char analog, telreq, flipdir, beacon, dshotext;
extern volatile uint32_t tick;

Expand All @@ -119,5 +119,6 @@ int smooth(int *s, int x, int n);
int calcpid(PID *pid, int x, int y);
void checkcfg(void);
int savecfg(void);
int resetcfg(void);
int playmusic(const char *str, int vol);
void reset(void) __attribute__((__noreturn__));
4 changes: 2 additions & 2 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@
#define DUTY_MAX 100
#endif
#ifndef DUTY_SPUP
#define DUTY_SPUP 15
#define DUTY_SPUP 10
#endif
#ifndef DUTY_RAMP
#define DUTY_RAMP 10
#define DUTY_RAMP 25
#endif
#ifndef DUTY_DRAG
#define DUTY_DRAG 0
Expand Down
24 changes: 14 additions & 10 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void dshotdma(void) {
DMA1_CNDTR(IOTIM_DMA) = 23;
DMA1_CCR(IOTIM_DMA) = DMA_CCR_EN | DMA_CCR_TCIE | DMA_CCR_DIR | DMA_CCR_MINC | DMA_CCR_PSIZE_16BIT | DMA_CCR_MSIZE_8BIT;
if (!dshotval) {
int a = erpt ? erpt : 65408;
int a = ertm ? ertm : 65408;
int b = 0;
if (a > 65408) a = 65408;
while (a > 511) a >>= 1, ++b;
Expand Down Expand Up @@ -314,7 +314,7 @@ static void dshotdma(void) {
cmd = 0;
return;
}
if (!tlm || erpt) return; // Telemetry bit must be set, motor must be stopped
if (!tlm || ertm) return; // Telemetry bit must be set, motor must be stopped
if (cmd != x) {
cmd = x;
cnt = 0;
Expand Down Expand Up @@ -402,23 +402,27 @@ static void dshotdma(void) {
#endif
case 40: // Increase timing
if (cnt != 6) break;
if (cfg.timing < 7) ++cfg.timing;
beepval = cfg.timing;
if ((x = cfg.timing) < 7) ++x;
beepval = cfg.timing = x;
break;
case 41: // Decrease timing
if (cnt != 6) break;
if (cfg.timing > 1) --cfg.timing;
beepval = cfg.timing;
if ((x = cfg.timing) > 1) --x;
beepval = cfg.timing = x;
break;
case 42: // Increase acceleration ramping
if (cnt != 6) break;
if (cfg.duty_ramp < 10) ++cfg.duty_ramp;
beepval = cfg.duty_ramp;
if ((x = cfg.duty_ramp) < 100 && ++x > 10) x = (x + 4) / 5 * 5;
beepval = cfg.duty_ramp = x;
break;
case 43: // Decrease acceleration ramping
if (cnt != 6) break;
if (cfg.duty_ramp > 0) --cfg.duty_ramp;
beepval = cfg.duty_ramp;
if ((x = cfg.duty_ramp) > 1 && --x > 10) x = x / 5 * 5;
beepval = cfg.duty_ramp = x;
break;
case 47: // Reset settings
if (cnt != 6) break;
beepval = resetcfg();
break;
}
}
Expand Down
Loading

0 comments on commit 289a8de

Please sign in to comment.