Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct PWM frequency prescale computation #59

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions adafruit_pca9685.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ def frequency(self) -> float:
raise ValueError(
"The device pre_scale register (0xFE) was not read or returned a value < 3"
)
return self.reference_clock_speed / 4096 / prescale_result
return self.reference_clock_speed / 4096 / (prescale_result + 1)

@frequency.setter
def frequency(self, freq: float) -> None:
prescale = int(self.reference_clock_speed / 4096.0 / freq + 0.5)
prescale = int(self.reference_clock_speed / 4096.0 / freq + 0.5) - 1
if prescale < 3:
raise ValueError("PCA9685 cannot output at the given frequency")
old_mode = self.mode1_reg # Mode 1
Expand Down