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

fix(PeriphDrivers): Improve accuracy of timer stop watch #1187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

perkinsmg
Copy link
Contributor

@perkinsmg perkinsmg commented Sep 20, 2024

Pull Request Template

Description

When the timer frequency is small, e.g. 1.8MHz, then dividing this frequency by 1000000 as an integer gives a huge error since it will round down to 1. Improve things by only dividing by 1000 rather than 1000000. We can multiply by 1000 in the numerator, because the prescale value is at most 128, and so 128 * 1000000 fits in uint32_t, and this is then multiplied by ticks which is also 32 bits but widened to 64 bits for the multiply. So the numerator won't overflow.

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

PR Title Guidelines

The MSDK repo follows a custom rule set based on the Conventional Commits standard. The pull request titles will follow this format:

type(scope)<!>: Subject

Types

The list of possible types are:

  1. fix – a bug fix has occurred
  2. feat – a new feature was introduced
  3. chore – changes that do not relate to a fix or feature, or a catch-all type for changes that don’t really fit under any of the other types
  4. refactor – refactored code that neither fixes a bug nor adds a new feature
  5. docs – updates to documentation
  6. style – code styling changes (linter or clang-format)
  7. test – changes involving test code (not changes like deleting a line of code to test if your application works or not)
  8. perf – performance improvements
  9. ci – changes related to continuous integration
  10. build – changes that affect the build system, toolchain, or any other external dependencies
  11. revert – reverts a commit

Appending an ! at the end of the title prefix signifies the PR is a breaking or major change. The <!> is optional in the PR format.

NOTE: The type is case-sensitive and must match one of the listed types.

Scopes

The scopes are dependent on the changes based on their location in the MSDK. The list of possible scopes are:

  1. BLE – Any Bluetooth related changes (i.e. Cordio)
  2. Documentation – Any changes in msdk/Documentation folder
  3. Examples – Any changes in msdk/Examples
  4. Tools – Any changes in msdk/Tools
  5. Boards – Any board file changes
  6. CMSIS – Any CMSIS/Register file changes
  7. MiscDrivers – Any MiscDrivers changes (e.g. TFT Display, PB, LED, External Flash Drivers)
  8. PeriphDrivers – Any changes in msdk/Libraries/PeriphDrivers
  9. ThirdParty – Any third-party library changes (e.g. FreeRTOS, LVGL, lwIP)
  10. MAXUSB – Any MAXUSB changes
  11. SDHC – Any SDHC changes
  12. Build – Any changes involving the build system
  13. ignore – Small and quick miscellaneous fixes (should not be used often)
  14. workflow – Any GitHub workflow-related changes
  15. Other – Any changes that may not fit in the other scopes

NOTE: The scope is case-sensitive and must match one of the listed scopes.

Subject Rules

  1. Use the imperative mood in the Subjects - meaning the tone of the Subject should be like giving an order or request.
  2. The Subject should have useful and concise wording.
  3. The Subject should include what parts are affected in numerical order, if any. Only the parts’ CHIP NAME should be used in the Subject. No die names are allowed.
  4. If the PR title is related to a Jira ticket or an issue, the Subject should begin with the ticket designation.
  5. The first letter must be capitalized and the subject must not end with any punctuation.

More Info

Please refer to the CONTRIBUTING.md for more information regarding the PR Title.

When the timer frequency is small, e.g. 1.8MHz, then dividing this frequency
by 1000000 as an integer gives a huge error since it will round down to 1.
Improve things by only dividing by 1000 rather than 1000000. We can multiply
by 1000 in the numerator, because the prescale value is at most 128,
and so 128 * 1000000 fits in uint32_t, and this is then multiplied by
ticks which is also 32 bits but widened to 64 bits for the multiply.
So the numerator won't overflow.

Signed-off-by: Michael Perkins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant