Skip to content

Commit e64d981

Browse files
jaxxzerlucasdemarchi
authored andcommitted
RCOutput_PCA9685: allow different external clock frequencies
The PCA9685 may use an external clock 0~50MHz Specify the external clock frequency in constructor arguments for each board HAL
1 parent 8561f52 commit e64d981

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

libraries/AP_HAL_Linux/RCOutput_PCA9685.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
* and https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library/issues/11
4949
*/
5050
#define PCA9685_INTERNAL_CLOCK (1.04f * 25000000.f)
51-
#define PCA9685_EXTERNAL_CLOCK 24576000.f
5251

5352
using namespace Linux;
5453

@@ -57,7 +56,7 @@ using namespace Linux;
5756
extern const AP_HAL::HAL& hal;
5857

5958
RCOutput_PCA9685::RCOutput_PCA9685(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev,
60-
bool external_clock,
59+
uint32_t external_clock,
6160
uint8_t channel_offset,
6261
int16_t oe_pin_number) :
6362
_dev(std::move(dev)),
@@ -68,10 +67,11 @@ RCOutput_PCA9685::RCOutput_PCA9685(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev,
6867
_channel_offset(channel_offset),
6968
_oe_pin_number(oe_pin_number)
7069
{
71-
if (_external_clock)
72-
_osc_clock = PCA9685_EXTERNAL_CLOCK;
73-
else
70+
if (_external_clock > 0) {
71+
_osc_clock = _external_clock;
72+
} else {
7473
_osc_clock = PCA9685_INTERNAL_CLOCK;
74+
}
7575
}
7676

7777
RCOutput_PCA9685::~RCOutput_PCA9685()

libraries/AP_HAL_Linux/RCOutput_PCA9685.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Linux {
1515
class RCOutput_PCA9685 : public AP_HAL::RCOutput {
1616
public:
1717
RCOutput_PCA9685(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev,
18-
bool external_clock,
18+
uint32_t external_clock,
1919
uint8_t channel_offset,
2020
int16_t oe_pin_number);
2121

@@ -42,7 +42,7 @@ class RCOutput_PCA9685 : public AP_HAL::RCOutput {
4242

4343
uint16_t *_pulses_buffer;
4444

45-
bool _external_clock;
45+
uint32_t _external_clock;
4646
bool _corking = false;
4747
uint8_t _channel_offset;
4848
int16_t _oe_pin_number;

0 commit comments

Comments
 (0)