@@ -33,9 +33,9 @@ Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
33
33
// have!
34
34
#define SERVOMIN 150 // This is the 'minimum' pulse length count (out of 4096)
35
35
#define SERVOMAX 600 // This is the 'maximum' pulse length count (out of 4096)
36
- #define USMIN 611 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
37
- #define USMAX 2441 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
38
- #define FREQ 60 // Analog servos run at ~60 Hz updates
36
+ #define USMIN 600 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
37
+ #define USMAX 2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
38
+ #define SERVO_FREQ 60 // Analog servos run at ~60 Hz updates
39
39
40
40
// our servo # counter
41
41
uint8_t servonum = 0 ;
@@ -45,8 +45,11 @@ void setup() {
45
45
Serial.println (" 8 channel Servo test!" );
46
46
47
47
pwm.begin ();
48
-
49
- pwm.setPWMFreq (FREQ); // Analog servos run at ~60 Hz updates
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
52
+ pwm.setPWMFreq (SERVO_FREQ); // Analog servos run at ~60 Hz updates
50
53
51
54
delay (10 );
52
55
}
@@ -57,7 +60,7 @@ void setServoPulse(uint8_t n, double pulse) {
57
60
double pulselength;
58
61
59
62
pulselength = 1000000 ; // 1,000,000 us per second
60
- pulselength /= FREQ ; // Analog servos run at ~60 Hz updates
63
+ pulselength /= SERVO_FREQ ; // Analog servos run at ~60 Hz updates
61
64
Serial.print (pulselength); Serial.println (" us per period" );
62
65
pulselength /= 4096 ; // 12 bits of resolution
63
66
Serial.print (pulselength); Serial.println (" us per bit" );
@@ -94,6 +97,6 @@ void loop() {
94
97
95
98
delay (500 );
96
99
97
- servonum ++;
100
+ servonum++;
98
101
if (servonum > 7 ) servonum = 0 ; // Testing the first 8 servo channels
99
- }
102
+ }
0 commit comments