From b9e30be98c958f9b5cf2797f163245fb61034140 Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Fri, 10 Jan 2025 10:49:40 +0300 Subject: [PATCH] Better support for ESCs, add PWM_STOP parameter --- flix/motors.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flix/motors.ino b/flix/motors.ino index 0458228..a2ef586 100644 --- a/flix/motors.ino +++ b/flix/motors.ino @@ -2,7 +2,7 @@ // Repository: https://github.com/okalachev/flix // Motors output control using MOSFETs -// In case of using ESCs, change PWM_MIN and PWM_MAX definitions to appropriate values in μs +// In case of using ESCs, change PWM_STOP, PWM_MIN and PWM_MAX to appropriate values in μs, decrease PWM_FREQUENCY (to 400) #include "util.h" @@ -13,6 +13,7 @@ #define PWM_FREQUENCY 500 #define PWM_RESOLUTION 12 +#define PWM_STOP 0 #define PWM_MIN 0 #define PWM_MAX 1000000 / PWM_FREQUENCY @@ -38,6 +39,7 @@ void setupMotors() { int getDutyCycle(float value) { value = constrain(value, 0, 1); float pwm = mapff(value, 0, 1, PWM_MIN, PWM_MAX); + if (value == 0) pwm = PWM_STOP; float duty = mapff(pwm, 0, 1000000 / PWM_FREQUENCY, 0, (1 << PWM_RESOLUTION) - 1); return round(duty); }