Skip to content

Commit

Permalink
Bring back possibility to use ESCs for motors
Browse files Browse the repository at this point in the history
  • Loading branch information
okalachev committed Jan 9, 2025
1 parent 87cf443 commit 5d10446
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions flix/motors.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Repository: https://github.com/okalachev/flix

// Motors output control using MOSFETs
// In case of using ESC, use this version of the code: https://gist.github.com/okalachev/8871d3a94b6b6c0a298f41a4edd34c61.
// Motor: 8520 3.7V
// In case of using ESCs, change PWM_MIN and PWM_MAX definitions to appropriate values in μs

#define MOTOR_0_PIN 12 // rear left
#define MOTOR_1_PIN 13 // rear right
Expand All @@ -12,6 +11,8 @@

#define PWM_FREQUENCY 500
#define PWM_RESOLUTION 8
#define PWM_MIN 0
#define PWM_MAX 1000000 / PWM_FREQUENCY

void setupMotors() {
Serial.println("Setup Motors");
Expand All @@ -28,7 +29,8 @@ void setupMotors() {

uint8_t getDutyCycle(float value) {
value = constrain(value, 0, 1);
float duty = mapff(value, 0, 1, 0, (1 << PWM_RESOLUTION) - 1);
float pwm = mapff(value, 0, 1, PWM_MIN, PWM_MAX);
float duty = mapff(pwm, 0, 1000000 / PWM_FREQUENCY, 0, (1 << PWM_RESOLUTION) - 1);
return round(duty);
}

Expand Down

0 comments on commit 5d10446

Please sign in to comment.