Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust timer freq for mower motor #5

Merged
merged 1 commit into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading