Skip to content

Commit

Permalink
Merge pull request #59 from bdlucas1/main
Browse files Browse the repository at this point in the history
Correct PWM frequency prescale computation
  • Loading branch information
jepler committed Jan 2, 2024
2 parents fcc8ced + b683f99 commit f2dd719
Showing 1 changed file with 2 additions and 2 deletions.
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

0 comments on commit f2dd719

Please sign in to comment.