Skip to content

Commit

Permalink
Merge pull request #5 from jordojordo/motor-esc
Browse files Browse the repository at this point in the history
Adjust timer freq for mower motor
  • Loading branch information
jordojordo authored Feb 18, 2024
2 parents 5fc66e6 + fe2ba40 commit ea0d4a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lawndon/drive.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ extern Servo leftEsc;
extern Servo rightEsc;

// pin defs
#define ESC_LEFT_PWM 4
#define ESC_LEFT_POWER 3
#define ESC_LEFT_PWM 4

#define ESC_RIGHT_PWM 11
#define ESC_RIGHT_POWER 10
#define ESC_RIGHT_PWM 11

// Throttle positions
#define ESC_MIN_THROTTLE 1000
Expand Down
7 changes: 7 additions & 0 deletions lawndon/motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Motor::Motor() {}
void Motor::setup() {
Console.println(F("Initializing motor config"));

// Setup for changing the PWM frequency of pin 7
setupTimer4();

// Attach Mower ESC
Console.println(F("Attaching mower ESC"));
mowerEsc.attach(ESC_MOWER_PWM, 1000, 2000);
Expand All @@ -35,3 +38,7 @@ void Motor::loop() {
mowerEsc.writeMicroseconds(1000);
}
}

void Motor::setupTimer4() {
TCCR4B = TCCR4B & 0b11111000 | 0x04; // Set prescaler to 256 for Timer 4
}
2 changes: 2 additions & 0 deletions lawndon/motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Motor {

virtual void setup();
virtual void loop();

virtual void setupTimer4();
};

extern Motor motor;
Expand Down

0 comments on commit ea0d4a6

Please sign in to comment.