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

avoid reset of utility timer #101

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tridge
Copy link
Member

@tridge tridge commented Oct 10, 2024

This is broken out of the DroneCAN PR #36

resetting the UTILITY_TIMER makes accurate long term time measurement much harder. We never need to reset it if we treat it as a wrapping 16 bit unsigned number and always do timing maths with 16 bit subtraction
This means that separate parts of the code base can reliably make timing measurements as the UTILITY_TIMER is always incrementing and never reset. So we can get both timing measurements and absolute time in DroneCAN while still using the UTILITY_TIMER in other parts of the code.
It also saves a few bytes of flash, and simplifies the delay code in functions.c

todo:

  • fix F421 TMR17 to be 1MHz
  • check all MCUs have 1MHz UTILITY_TIMER

@freasy
Copy link
Collaborator

freasy commented Oct 12, 2024

Merge when @tridge checked and tested F421

@tridge
Copy link
Member Author

tridge commented Oct 12, 2024

need to change prescaler on F421 to 119, for 120MHz periph clock

@tridge
Copy link
Member Author

tridge commented Oct 13, 2024

@AlkaMotors @freasy I've been through all the MCUs and check the prescaler against the bootloader (which relies on 1MHz for the timer). I've fixed the ones that were not 1MHz, so should be all good now

resetting the UTILITY_TIMER makes accurate long term time measurement
much harder. We never need to reset it if we treat it as a wrapping 16
bit unsigned number and always do timing maths with 16 bit subtraction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants