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

Local merge #1

Merged
merged 12 commits into from
Nov 3, 2019
Merged

Local merge #1

merged 12 commits into from
Nov 3, 2019

Conversation

Bolukan
Copy link
Owner

@Bolukan Bolukan commented Nov 3, 2019

Thank you for creating a pull request to contribute to Adafruit's GitHub code!
Before you open the request please review the following guidelines and tips to
help it be more easily integrated:

  • Describe the scope of your change--i.e. what the change does and what parts
    of the code were modified.
    This will help us understand any risks of integrating
    the code.

  • Describe any known limitations with your change. For example if the change
    doesn't apply to a supported platform of the library please mention it.

  • Please run any tests or examples that can exercise your modified code. We
    strive to not break users of the code and running tests/examples helps with this
    process.

Thank you again for contributing! We will try to test and integrate the change
as soon as we can, but be aware we have many GitHub repositories to manage and
can't immediately respond to every request. There is no need to bump or check in
on a pull request (it will clutter the discussion of the request).

Also don't be worried if the request is closed or not integrated--sometimes the
priorities of Adafruit's GitHub code (education, ease of use) might not match the
priorities of the pull request. Don't fret, the open source community thrives on
forks and GitHub makes it easy to keep your changes in a forked repo.

After reviewing the guidelines above you can delete this text from the pull request.

photodude and others added 12 commits October 29, 2019 10:03
Checked the calculations by hand

Use Datasheet 7.3.5 Equation 1 for frequency from prescale
https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf
Frequency = (ClockFrequency/(PreScale+1))*(1/BitRate)
and from the rest of the calculation
us per period = PulseLength/Frequency
us per bit = us per period/BitRate
 we can combine to get
us per bit = (PulseLength/((ClockFrequency/(PreScale+1))*(1/BitRate)))*(1/BitRate)

This can be simplified to (PulseLength (PreScale + 1))/ClockFrequency 
this formula was implemented in proposed code

checked by setting chip frequency to 60Hz
read prescale = 105
us per bit = 4.069 with 25Mhz (a PWM frequency of about 57.3hz)
Choosing the FREQUENCY_CALIBRATED constant listed at 104.3% higher or 26.075MHz
we get 
us per bit = 4.1035 or a PWM frequency of about 60.056Hz much closer to the set 60Hz 

Overall this change makes less calculation steps, and uses fewer variables. The change should be faster and more accurate to the intended results.
debug statements should be Wrapped in `#ifdef ENABLE_DEBUG_OUTPUT`
Prescale values are integers 3 to 255 with a maximum of 255+1 for the calculations.
@Bolukan Bolukan merged commit 83d42b9 into Bolukan:master Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants