From 058ddf029bfdb30e0af288f733b35f1bc1b35638 Mon Sep 17 00:00:00 2001 From: Armin Date: Fri, 25 Nov 2022 21:05:11 +0100 Subject: [PATCH] Added `PCA9685_ACTUAL_CLOCK_FREQUENCY` macro --- README.md | 7 +++++-- examples/PCA9685_Expander/PCA9685_Expander.ino | 1 + .../PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino | 1 + .../PCA9685_ExpanderFor32Servos.ino | 1 + src/ServoEasing.h | 6 +++++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3faa7f9..6fa0462 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,8 @@ Every other extension e.g. *cinclude* would do, but *hpp* seems to be common sen # Using the new *.hpp files In order to support [compile options](#compile-options--macros-for-this-library) more easily, -the line `#include ` must be changed to `#include ` in your main program (aka *.ino file with setup() and loop()). +the line `#include ` must be changed to `#include ` +in your main program (aka *.ino file with setup() and loop()). In **all other files** you must use `#include `, to **prevent `multiple definitions` linker errors**: @@ -259,6 +260,7 @@ Modify them by enabling / disabling them, or change the values if applicable. | Name | Default value | Description | |-|-|-| | `USE_PCA9685_SERVO_EXPANDER` | disabled | Enables the use of the PCA9685 I2C expander chip/board. | +| `PCA9685_ACTUAL_CLOCK_FREQUENCY` | 25000000L | Change it, if your PCA9685 has another than the default 25 MHz internal clock. See chapter 2 and 5 of the PCA9685 Datasheet "25 MHz typical internal oscillator requires no external components". | | `USE_SOFT_I2C_MASTER` | disabled | Saves up to 1756 bytes program memory and 218 bytes RAM for PCA9685 I2C communication compared with Arduino Wire. | | `USE_SERVO_LIB` | disabled | Use of PCA9685 normally disables use of regular servo library. You can force additional using of regular servo library by defining `USE_SERVO_LIB`. See [below](https://github.com/ArminJo/ServoEasing#using-pca9685-16-channel-servo-expander). | | `PROVIDE_ONLY_LINEAR_MOVEMENT` | disabled | Disables all but LINEAR movement. Saves up to 1540 bytes program memory. | @@ -394,7 +396,8 @@ This will print internal information visible in the Arduino *Serial Monitor* whi # Revision History ### Version 3.1.1 - Added function `getCurrentMicroseconds()`. -- Improved many examples. +- Improved many and added workaround for ESP32 bug in while loops in examples. +- Added `PCA9685_ACTUAL_CLOCK_FREQUENCY` macro. ### Version 3.1.0 - SAMD51 support by Lutz Aumüller. diff --git a/examples/PCA9685_Expander/PCA9685_Expander.ino b/examples/PCA9685_Expander/PCA9685_Expander.ino index 644c587..af74de8 100644 --- a/examples/PCA9685_Expander/PCA9685_Expander.ino +++ b/examples/PCA9685_Expander/PCA9685_Expander.ino @@ -29,6 +29,7 @@ // Must specify this before the include of "ServoEasing.hpp" #define USE_PCA9685_SERVO_EXPANDER // Activating this enables the use of the PCA9685 I2C expander chip/board. +//#define PCA9685_ACTUAL_CLOCK_FREQUENCY 26000000L // Change it, if your PCA9685 has another than the default 25 MHz internal clock. //#define USE_SOFT_I2C_MASTER // Saves 1756 bytes program memory and 218 bytes RAM compared with Arduino Wire //#define USE_SERVO_LIB // If USE_PCA9685_SERVO_EXPANDER is defined, Activating this enables force additional using of regular servo library. //#define USE_LEIGHTWEIGHT_SERVO_LIB // Makes the servo pulse generating immune to other libraries blocking interrupts for a longer time like SoftwareSerial, Adafruit_NeoPixel and DmxSimple. diff --git a/examples/PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino b/examples/PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino index 96030b8..c8184dc 100644 --- a/examples/PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino +++ b/examples/PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino @@ -39,6 +39,7 @@ // Must specify this before the include of "ServoEasing.hpp" #define USE_PCA9685_SERVO_EXPANDER // Activating this enables the use of the PCA9685 I2C expander chip/board. +//#define PCA9685_ACTUAL_CLOCK_FREQUENCY 26000000L // Change it, if your PCA9685 has another than the default 25 MHz internal clock. //#define USE_SOFT_I2C_MASTER // Saves 1756 bytes program memory and 218 bytes RAM compared with Arduino Wire #define USE_SERVO_LIB // If USE_PCA9685_SERVO_EXPANDER is defined, Activating this enables force additional using of regular servo library. //#define PROVIDE_ONLY_LINEAR_MOVEMENT // Activating this disables all but LINEAR movement. Saves up to 1540 bytes program memory. diff --git a/examples/PCA9685_ExpanderFor32Servos/PCA9685_ExpanderFor32Servos.ino b/examples/PCA9685_ExpanderFor32Servos/PCA9685_ExpanderFor32Servos.ino index 966a6e7..d175021 100644 --- a/examples/PCA9685_ExpanderFor32Servos/PCA9685_ExpanderFor32Servos.ino +++ b/examples/PCA9685_ExpanderFor32Servos/PCA9685_ExpanderFor32Servos.ino @@ -38,6 +38,7 @@ // Must specify this before the include of "ServoEasing.hpp" #define USE_PCA9685_SERVO_EXPANDER // Activating this enables the use of the PCA9685 I2C expander chip/board. +//#define PCA9685_ACTUAL_CLOCK_FREQUENCY 26000000L // Change it, if your PCA9685 has another than the default 25 MHz internal clock. //#define USE_SOFT_I2C_MASTER // Saves 1756 bytes program memory and 218 bytes RAM compared with Arduino Wire //#define USE_SERVO_LIB // If USE_PCA9685_SERVO_EXPANDER is defined, Activating this enables force additional using of regular servo library. //#define PROVIDE_ONLY_LINEAR_MOVEMENT // Activating this disables all but LINEAR movement. Saves up to 1540 bytes program memory. diff --git a/src/ServoEasing.h b/src/ServoEasing.h index dfe0bd5..9dbc4d2 100644 --- a/src/ServoEasing.h +++ b/src/ServoEasing.h @@ -390,8 +390,12 @@ extern const char *const easeTypeStrings[] PROGMEM; #define PCA9685_MODE_1_SLEEP 4 #define PCA9685_FIRST_PWM_REGISTER 0x06 #define PCA9685_PRESCALE_REGISTER 0xFE +#if !defined(PCA9685_ACTUAL_CLOCK_FREQUENCY) +// See chapter 2 and 5 of the PCA9685 Datasheet "25 MHz typical internal oscillator requires no external components" +#define PCA9685_ACTUAL_CLOCK_FREQUENCY 25000000L // 25 MHz this is the default frequency +#endif -#define PCA9685_PRESCALER_FOR_20_MS ((25000000L /(4096L * 50))-1) // = 121 / 0x79 at 50 Hz +#define PCA9685_PRESCALER_FOR_20_MS ((PCA9685_ACTUAL_CLOCK_FREQUENCY /(4096L * 50)) - 1) // = 121 / 0x79 at 50 Hz // to be used as values for parameter bool aStartUpdateByInterrupt #define START_UPDATE_BY_INTERRUPT true