mirror of
https://github.com/okalachev/flix.git
synced 2025-07-27 09:39:33 +00:00
Better support for ESCs, add PWM_STOP parameter
This commit is contained in:
parent
821e6b105e
commit
b9e30be98c
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user