Skip to content

Commit

Permalink
eliminate pwm_failsafe_time
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Jul 5, 2023
1 parent 6dce2d2 commit 7b8aae1
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 24 deletions.
4 changes: 0 additions & 4 deletions src/driver/at32/motor_dshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef struct {
} dshot_gpio_port_t;

extern uint16_t dshot_packet[MOTOR_PIN_MAX];
extern uint32_t pwm_failsafe_time;
extern motor_direction_t motor_dir;

volatile uint32_t dshot_dma_phase = 0; // 0: idle, 1 - (gpio_port_count + 1): handle port n
Expand Down Expand Up @@ -168,9 +167,6 @@ void motor_dshot_init() {
}

tmr_counter_enable(TMR1, TRUE);

// set failsafetime so signal is off at start
pwm_failsafe_time = time_micros() - 100000;
motor_dir = MOTOR_FORWARD;
}

Expand Down
16 changes: 0 additions & 16 deletions src/driver/motor_dshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ typedef enum {
} dir_change_state_t;

uint16_t dshot_packet[MOTOR_PIN_MAX]; // 16bits dshot data for 4 motors
uint32_t pwm_failsafe_time = 1;
motor_direction_t motor_dir = MOTOR_FORWARD;

static bool dir_change_done = true;
Expand Down Expand Up @@ -46,27 +45,12 @@ void motor_dshot_write(float *values) {
if (dir_change_done) {
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++) {
uint16_t value = 0;

if (values[i] >= 0.0f) {
const float pwm = constrainf(values[i], 0.0f, 1.0f);
value = mapf(pwm, 0.0f, 1.0f, 48, 2047);
} else {
value = 0;
}

if (flags.failsafe && !flags.motortest_override) {
if (!pwm_failsafe_time) {
pwm_failsafe_time = time_micros();
} else if (time_micros() - pwm_failsafe_time > 4000000) {
// 1s after failsafe we turn off the signal for safety
// this means the escs won't rearm correctly after 2 secs of signal lost
// usually the quad should be gone by then
value = 0;
}
} else {
pwm_failsafe_time = 0;
}

dshot_make_packet(profile.motor.motor_pins[i], value, false);
}

Expand Down
4 changes: 0 additions & 4 deletions src/driver/stm32/motor_dshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef struct {
} dshot_gpio_port_t;

extern uint16_t dshot_packet[MOTOR_PIN_MAX];
extern uint32_t pwm_failsafe_time;
extern motor_direction_t motor_dir;

volatile uint32_t dshot_dma_phase = 0; // 0: idle, 1 - (gpio_port_count + 1): handle port n
Expand Down Expand Up @@ -198,9 +197,6 @@ void motor_dshot_init() {
}

LL_TIM_EnableCounter(TIM1);

// set failsafetime so signal is off at start
pwm_failsafe_time = time_micros() - 100000;
motor_dir = MOTOR_FORWARD;
}

Expand Down

0 comments on commit 7b8aae1

Please sign in to comment.