esphome / esphome/feature-requests

Enable EXTCLK external oscillator on PCA9685

Open
#1,670 0 comments 1 reaction 0 assignees View on GitHub
component: pca9685
Dominant language
No language data
Stars
450
Forks
29
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem you have/What new integration you would like**

I became interested in seeing this enabled after noticing my pca9685 board produces audible noise at frequencies between 900hz and the max frequency using the internal 25mhz oscillator. I have read others having similar issues with audible noise. I would also like to explore increasing the LED frequency higher for other reasons, including persistence of vision stroboscopic effects, and issues with camera shutter speeds picking up the LED frequency. Enabling synchronization with other boards would be another benefit.

Enable the EXTCLK external clock feature of the PCA9685 to extend the max PWM frequency and enable synchronization with other boards. [Page 14 of the datasheet](https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf) gives these instructions for enabling EXTCLK:

To use the EXTCLK pin, this bit must be set by the following sequence:
1. Set the SLEEP bit in MODE1. This turns off the internal oscillator.
2. Write logic 1s to both the SLEEP and EXTCLK bits in MODE1. The switch is
now made. The external clock can be active during the switch because the
SLEEP bit is set.
This bit is a ‘sticky bit’, that is, it cannot be cleared by writing a logic 0 to it. The
EXTCLK bit can only be cleared by a power cycle or software reset.
EXTCLK range is DC to 50 MHz.

**Please describe your use case for this integration and alternatives you've tried:**

There is no obvious ability in the PCA9685 integration to enable to external clock on the board.

**Additional context**

If I read the datasheet correctly, up to a 50mhz clock signal can be sent through the EXTCLK pin. 50mhz is double the on board oscillator, so does this mean the max output frequency doubles to 3052hz? This still results in the an output frequency being in the audible range, but it might help lessen stroboscopic effects and camera shutter speed issues.

The section describing the PRE_SCALE calculation shows that a pre_scale value can be used along with the oscillator frequency to determine output frequency. It seems to me that my max 3052hz understanding is correct, since a PRE_SCALE value of 3 is the minimum, and at 3052hz it would be 3. It also seems to not be possible to achieve an output frequency of 20khz when using a 50mhz clock signal since a PRE_SCALE value of less than one (0.61) must be used. Is it possible to use a lower bit rate than 12 bit? At a lower bit rate significantly higher frequencies could be achieved. I see nothing in the datasheet about this being an option, but I might be missing something.

Aside from the max frequency question, I would also like to figure out how to actually make use of an external oscillator. The PCA9685 datasheet shows that a 1 must be written to the SLEEP and EXTCLK bits in order to enable it.

What is the best way to accomplish this (writing 1s to EXTCLK and SLEEP) for someone preferring to stick with ESPHome?

Willing to do the work and research to figure this out, but I need some guidance as I start. If I can do some work to make this an option for others I'd like to do that.

Contributor guide

No contributing guide indexed for this repository

Research direction

No source files or tests are named. Start with the PCA9685 datasheet page 14 and inspect the existing PCA9685 integration to determine where MODE1 and clock settings are handled. Done means providing a safe ESPHome-facing way to enable EXTCLK and documenting or testing the resulting frequency and synchronization behavior.

Written by the indexing model from the issue text.

Assessment

Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.