Skip to content

Commit

Permalink
Firmware revision 7
Browse files Browse the repository at this point in the history
+ Maximum duty cycle ramp
+ Increased acceleration slew rate above 60kERPM
+ Fixed throttle mode

Independent fixed/analog throttle mode
Flexible analog throttle pin assignment
Strict desync detection condition
  • Loading branch information
neoxic committed Sep 20, 2023
1 parent f15f62e commit ac0c7e5
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 94 deletions.
2 changes: 1 addition & 1 deletion mcu/AT32F421/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void init(void) {
ADC1_SQR3 = SENS_CHAN;
len = SENS_CNT;
if (IO_ANALOG) {
ADC1_SQR3 |= THROT_CHAN << (len++ * 5);
ADC1_SQR3 |= AIN_PIN << (len++ * 5);
ain = 1;
}
ADC1_SQR3 |= 0x230 << (len * 5); // CH16 (temp), CH17 (vref)
Expand Down
4 changes: 0 additions & 4 deletions mcu/AT32F421/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
#define SENS_CHAN 0x66
#endif

#ifndef THROT_CHAN
#define THROT_CHAN 2 // A2
#endif

#define CLK 120000000
#define IO_PA2
#define IO_TYPE 0
Expand Down
2 changes: 1 addition & 1 deletion mcu/GD32E230/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void init(void) {
ADC1_SQR3 = SENS_CHAN;
len = SENS_CNT;
if (IO_ANALOG) {
ADC1_SQR3 |= THROT_CHAN << (len++ * 5);
ADC1_SQR3 |= AIN_PIN << (len++ * 5);
ain = 1;
}
ADC1_SQR3 |= 0x230 << (len * 5); // CH16 (temp), CH17 (vref)
Expand Down
4 changes: 0 additions & 4 deletions mcu/GD32E230/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
#define SENS_CHAN 0x3
#endif

#ifndef THROT_CHAN
#define THROT_CHAN 2 // A2
#endif

#define CLK 72000000
#define IO_PA2
#define IO_TYPE 0
Expand Down
2 changes: 1 addition & 1 deletion mcu/GD32F350/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void init(void) {
ADC1_SQR3 = SENS_CHAN;
len = SENS_CNT;
if (IO_ANALOG) {
ADC1_SQR3 |= THROT_CHAN << (len++ * 5);
ADC1_SQR3 |= AIN_PIN << (len++ * 5);
ain = 1;
}
ADC1_SQR3 |= 0x230 << (len * 5); // CH16 (temp), CH17 (vref)
Expand Down
4 changes: 0 additions & 4 deletions mcu/GD32F350/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
#define SENS_CHAN 0x3
#endif

#ifndef THROT_CHAN
#define THROT_CHAN 2 // A2
#endif

#define CLK 104000000

#define IFTIM TIM2
Expand Down
6 changes: 3 additions & 3 deletions mcu/STM32F051/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void init(void) {
ADC1_CHSELR = SENS_CHAN | 0x30000; // CH16 (temp), CH17 (vref)
len = SENS_CNT + 2;
if (IO_ANALOG) {
ADC1_CHSELR |= THROT_CHAN;
ADC1_CHSELR |= 1 << AIN_PIN;
ain = 1;
++len;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ void dma1_channel1_isr(void) {
DMA1_IFCR = DMA_IFCR_CTCIF(1);
DMA1_CCR(1) = 0;
int i = 0, v = 0, c = 0, x = 0;
#ifndef THROT_LAST
#ifndef AIN_LAST
if (ain) x = buf[i++];
#endif
#ifdef SENS_SWAP
Expand All @@ -171,7 +171,7 @@ void dma1_channel1_isr(void) {
v = buf[i++];
#endif
#endif
#ifdef THROT_LAST
#ifdef AIN_LAST
if (ain) x = buf[i++];
#endif
int r = ST_VREFINT_CAL * 3300 / buf[i + 1];
Expand Down
4 changes: 0 additions & 4 deletions mcu/STM32F051/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
#define SENS_SWAP
#endif

#ifndef THROT_CHAN
#define THROT_CHAN 0x4 // A2
#endif

#define CLK 48000000

#define IFTIM TIM2
Expand Down
2 changes: 1 addition & 1 deletion mcu/STM32G071/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void init(void) {
ADC1_CHSELR = SENS_CHAN;
len = SENS_CNT;
if (IO_ANALOG) {
ADC1_CHSELR |= THROT_CHAN << (len++ << 2);
ADC1_CHSELR |= AIN_PIN << (len++ << 2);
ain = 1;
}
ADC1_CHSELR |= 0xfdc << (len << 2); // CH12 (temp), CH13 (vref)
Expand Down
8 changes: 0 additions & 8 deletions mcu/STM32G071/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
#define SENS_CHAN 0x64
#endif

#ifndef THROT_CHAN
#ifdef IO_PA2
#define THROT_CHAN 2 // A2
#else
#define THROT_CHAN 6 // A6
#endif
#endif

#define CLK 64000000

#define IFTIM TIM2
Expand Down
2 changes: 1 addition & 1 deletion mcu/STSPIN32F0/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void init(void) {
ADC1_CHSELR = 0x30000; // CH16 (temp), CH17 (vref)
len = 2;
if (IO_ANALOG) {
ADC1_CHSELR |= THROT_CHAN;
ADC1_CHSELR |= 1 << AIN_PIN;
ain = 1;
++len;
}
Expand Down
4 changes: 0 additions & 4 deletions mcu/STSPIN32F0/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

#pragma once

#ifndef THROT_CHAN
#define THROT_CHAN 0x40 // A6
#endif

#define CLK 48000000
#define SENSORED
#define IO_PA6
Expand Down
45 changes: 24 additions & 21 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,29 @@
XX( 8, val, duty_min) \
XX( 9, val, duty_max) \
XX(10, val, duty_spup) \
XX(11, val, duty_rate) \
XX(12, val, duty_drag) \
XX(13, val, throt_mode) \
XX(14, val, throt_cal) \
XX(15, val, throt_min) \
XX(16, val, throt_mid) \
XX(17, val, throt_max) \
XX(18, val, input_mode) \
XX(19, val, input_chid) \
XX(20, val, telem_mode) \
XX(21, val, telem_phid) \
XX(22, val, telem_poles) \
XX(23, val, prot_temp) \
XX(24, val, prot_volt) \
XX(25, val, prot_cells) \
XX(26, val, prot_curr) \
XX(27, str, music) \
XX(28, val, volume) \
XX(29, val, beacon) \
XX(30, val, led) \
XX(31, val, brushed) \
XX(11, val, duty_ramp) \
XX(12, val, duty_rate) \
XX(13, val, duty_drag) \
XX(14, val, throt_mode) \
XX(15, val, throt_set) \
XX(16, val, throt_cal) \
XX(17, val, throt_min) \
XX(18, val, throt_mid) \
XX(19, val, throt_max) \
XX(20, val, input_mode) \
XX(21, val, input_chid) \
XX(22, val, telem_mode) \
XX(23, val, telem_phid) \
XX(24, val, telem_poles) \
XX(25, val, prot_temp) \
XX(26, val, prot_volt) \
XX(27, val, prot_cells) \
XX(28, val, prot_curr) \
XX(29, str, music) \
XX(30, val, volume) \
XX(31, val, beacon) \
XX(32, val, led) \
XX(33, val, brushed) \

static int beep = -1;

Expand Down Expand Up @@ -211,6 +213,7 @@ CFG_MAP(XX)
case 8: // 'throt <value>'
if (narg != 2 || !getval(args[1], &val) || val < -2000 || val > 2000) goto error;
throt = val;
analog = 0;
break;
case 9: // 'beep'
if (narg != 1) goto error;
Expand Down
14 changes: 12 additions & 2 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@
#define CLK_MHZ (CLK / 1000000)

#ifdef ANALOG
#define IO_ANALOG (ANALOG_THROT < 100)
#elif defined IO_PA2 || defined IO_PA6
#define IO_ANALOG (cfg.throt_set < 100)
#elif defined IO_PA2 || defined IO_PA6 || defined ANALOG_PIN
#define IO_ANALOG (cfg.input_mode == 1)
#else
#define IO_ANALOG 0
#endif

#ifdef ANALOG_PIN
#define AIN_PIN ANALOG_PIN
#elif defined IO_PA6
#define AIN_PIN 6
#else
#define AIN_PIN 2
#endif

typedef struct {
const uint16_t id;
const char revision;
Expand All @@ -66,9 +74,11 @@ typedef struct {
char duty_min;
char duty_max;
char duty_spup;
char duty_ramp;
char duty_rate;
char duty_drag;
char throt_mode;
char throt_set;
char throt_cal;
short throt_min;
short throt_mid;
Expand Down
9 changes: 6 additions & 3 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@
#ifndef ANALOG_MAX
#define ANALOG_MAX 3200 // mV
#endif
#ifndef ANALOG_THROT
#define ANALOG_THROT 0 // %
#endif

// Default settings

Expand Down Expand Up @@ -167,6 +164,9 @@
#ifndef DUTY_SPUP
#define DUTY_SPUP 10
#endif
#ifndef DUTY_RAMP
#define DUTY_RAMP 0
#endif
#ifndef DUTY_RATE
#define DUTY_RATE 25
#endif
Expand All @@ -176,6 +176,9 @@
#ifndef THROT_MODE
#define THROT_MODE 0
#endif
#ifndef THROT_SET
#define THROT_SET 0
#endif
#ifndef THROT_CAL
#ifdef USE_HSE
#define THROT_CAL 0
Expand Down
12 changes: 9 additions & 3 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static void dshotdma(void) {
cfg.led &= ~8;
break;
#endif
case 40: // Select timing
case 40: // Select motor timing
if (cnt != 6) break;
if ((x = cfg.timing + 1) > 7) x = 1;
beepval = cfg.timing = x;
Expand All @@ -420,12 +420,18 @@ static void dshotdma(void) {
cfg.freq_max = x << 3;
beepval = x - 5;
break;
case 42: // Increase acceleration slew rate
case 42: // Select maximum duty cycle ramp
if (cnt != 6) break;
if ((x = cfg.duty_ramp / 10 + 1) > 10) x = 0;
cfg.duty_ramp = x * 10;
beepval = x;
break;
case 43: // Increase acceleration slew rate
if (cnt != 6) break;
if ((x = cfg.duty_rate) < 100 && ++x > 10) x = (x + 4) / 5 * 5;
beepval = cfg.duty_rate = x;
break;
case 43: // Decrease acceleration slew rate
case 44: // Decrease acceleration slew rate
if (cnt != 6) break;
if ((x = cfg.duty_rate) > 1 && --x > 10) x = x / 5 * 5;
beepval = cfg.duty_rate = x;
Expand Down
Loading

0 comments on commit ac0c7e5

Please sign in to comment.