Skip to content

Commit d8bb4b1

Browse files
authored
Merge pull request #72 from photodude/new-internal-oscillator-notes
Update internal oscillator notes in examples
2 parents f8aa8d8 + df272ce commit d8bb4b1

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

examples/pwmtest/pwmtest.ino

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,23 @@ void setup() {
3131
Serial.println("16 channel PWM test!");
3232

3333
pwm.begin();
34-
// In theory the internal oscillator is 25MHz but it really isn't
35-
// that precise. You can 'calibrate' by tweaking this number till
36-
// you get the frequency you're expecting!
37-
pwm.setOscillatorFrequency(27000000); // The int.osc. is closer to 27MHz
34+
/*
35+
* In theory the internal oscillator (clock) is 25MHz but it really isn't
36+
* that precise. You can 'calibrate' this by tweaking this number until
37+
* you get the PWM update frequency you're expecting!
38+
* The int.osc. for the PCA9685 chip is a range between about 23-27MHz and
39+
* is used for calculating things like writeMicroseconds()
40+
* Analog servos run at ~50 Hz updates, It is importaint to use an
41+
* oscilloscope in setting the int.osc frequency for the I2C PCA9685 chip.
42+
* 1) Attach the oscilloscope to one of the PWM signal pins and ground on
43+
* the I2C PCA9685 chip you are setting the value for.
44+
* 2) Adjust setOscillatorFrequency() until the PWM update frequency is the
45+
* expected value (50Hz for most ESCs)
46+
* Setting the value here is specific to each individual I2C PCA9685 chip and
47+
* affects the calculations for the PWM update frequency.
48+
* Failure to correctly set the int.osc value will cause unexpected PWM results
49+
*/
50+
pwm.setOscillatorFrequency(27000000);
3851
pwm.setPWMFreq(1600); // This is the maximum PWM frequency
3952

4053
// if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode

examples/servo/servo.ino

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,23 @@ void setup() {
4545
Serial.println("8 channel Servo test!");
4646

4747
pwm.begin();
48-
// In theory the internal oscillator is 25MHz but it really isn't
49-
// that precise. You can 'calibrate' by tweaking this number till
50-
// you get the frequency you're expecting!
51-
pwm.setOscillatorFrequency(27000000); // The int.osc. is closer to 27MHz
48+
/*
49+
* In theory the internal oscillator (clock) is 25MHz but it really isn't
50+
* that precise. You can 'calibrate' this by tweaking this number until
51+
* you get the PWM update frequency you're expecting!
52+
* The int.osc. for the PCA9685 chip is a range between about 23-27MHz and
53+
* is used for calculating things like writeMicroseconds()
54+
* Analog servos run at ~50 Hz updates, It is importaint to use an
55+
* oscilloscope in setting the int.osc frequency for the I2C PCA9685 chip.
56+
* 1) Attach the oscilloscope to one of the PWM signal pins and ground on
57+
* the I2C PCA9685 chip you are setting the value for.
58+
* 2) Adjust setOscillatorFrequency() until the PWM update frequency is the
59+
* expected value (50Hz for most ESCs)
60+
* Setting the value here is specific to each individual I2C PCA9685 chip and
61+
* affects the calculations for the PWM update frequency.
62+
* Failure to correctly set the int.osc value will cause unexpected PWM results
63+
*/
64+
pwm.setOscillatorFrequency(27000000);
5265
pwm.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
5366

5467
delay(10);

0 commit comments

Comments
 (0)