Skip to content

Commit

Permalink
Added PCA9685_ACTUAL_CLOCK_FREQUENCY macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Nov 25, 2022
1 parent 96ca74d commit 058ddf0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ServoEasing.h>` must be changed to `#include <ServoEasing.hpp>` in your main program (aka *.ino file with setup() and loop()).
the line `#include <ServoEasing.h>` must be changed to `#include <ServoEasing.hpp>`
in your main program (aka *.ino file with setup() and loop()).

In **all other files** you must use `#include <ServoEasing.h>`, to **prevent `multiple definitions` linker errors**:

Expand All @@ -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. |
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions examples/PCA9685_Expander/PCA9685_Expander.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/ServoEasing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 058ddf0

Please sign in to comment.