Skip to content

Commit

Permalink
Merge pull request #28 from loicreboursiere/master
Browse files Browse the repository at this point in the history
Use of different min, max and default timer bit depth width depending on ESP32 versions
  • Loading branch information
madhephaestus authored Oct 3, 2022
2 parents 6807249 + 4cbb434 commit 7034577
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ESP32Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ bool Servo::attached()

void Servo::setTimerWidth(int value)
{
// only allow values between 16 and 20
if (value < 16)
value = 16;
else if (value > 20)
value = 20;
// only allow values between 10 and 14 for ESP32-C3
// only allow values between 16 and 20 for other ESP32
if (value < MINIMUM_TIMER_WIDTH )
value = MINIMUM_TIMER_WIDTH;
else if (value > MAXIMUM_TIMER_WIDTH)
value = MAXIMUM_TIMER_WIDTH;

// Fix the current ticks value after timer width change
// The user can reset the tick value with a write() or writeUs()
Expand Down
8 changes: 8 additions & 0 deletions src/ESP32Servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@
//#define DEFAULT_uS_LOW 400
//#define DEFAULT_uS_HIGH 2400

#ifdef ARDUINO_ESP32C3_DEV
#define MINIMUM_TIMER_WIDTH 10
#define MAXIMUM_TIMER_WIDTH 14
#define DEFAULT_TIMER_WIDTH 10
#else
#define MINIMUM_TIMER_WIDTH 16
#define MAXIMUM_TIMER_WIDTH 20
#define DEFAULT_TIMER_WIDTH 16
#endif
#define DEFAULT_TIMER_WIDTH_TICKS 65536

#define ESP32_Servo_VERSION 1 // software version of this library
Expand Down

0 comments on commit 7034577

Please sign in to comment.