Skip to content

Commit 9ce616b

Browse files
author
jenkie
committed
Increase PWM frequency on motor output pin
Sets PWM frequency to 32 kHz instead of 500 Hz -> removes ripple from motor output
1 parent 4e252c1 commit 9ce616b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Arduino_Pedelec_Controller/Arduino_Pedelec_Controller.ino

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ void setup()
494494
motorservo.attach(throttle_out);
495495
#endif
496496

497+
//increase PWM frequency
498+
#if HARDWARE_REV >= 20
499+
int myEraser = 7;
500+
TCCR4B &= ~myEraser; //reset timer 4 prescaler
501+
int myPrescaler = 1;
502+
TCCR4B |= myPrescaler; //set timer 4 prescaler to 001 --> 32 kHz PWM frequency on motor output pin
503+
#endif
504+
497505
#ifdef DEBUG_MEMORY_USAGE
498506
Serial.print(MY_F("memFree after setup:"));
499507
Serial.print(memFree());
@@ -1412,4 +1420,4 @@ int analogRead_noISR(uint8_t pin) //this function makes sure that analogRead is
14121420
analogRead_in_use = false;
14131421
#endif
14141422
return temp;
1415-
}
1423+
}

0 commit comments

Comments
 (0)