-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/stm32/periph/timer: don't stop counter #19263
Conversation
If a timer's channel was set with a really small realtive duration from now, such that it would be missed (underflowed), the driver would stop the timer, potentially causing missed ticks. It was stopped to ensure that the channel's output-compare register could be set to the current counter value, before re-enabling the timer's counter. This is a condition that will ensure that the underflow won't happen again and the interrupt will fire, at the cost of losing some ticks for very high speed clocks. This patch replaces the logic that stopped the timer. Instead it uses a register provided by the timer hardware to trigger timer interrupts via software.
Nice one! |
Both There is an issue (already in master) with the STM32F1 in In any case: All testing suggests that this indeed works and is a clearly superior solution to the stopping the clock workaround. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors merge
Out of curiosity: Did the briefly stopping the timer indeed cause any issues? The nRF5x timer driver is using the same work around. The reasoning is that missing a timeout and waiting for a full period is worse than loosing a timer tick or two whenever one sets a timeout that is to short to work reliably. This is based on the assumption that short relative timeouts (like less than three ticks on a 1 MHz clock) are set rarely and clock drift on the high frequency clock is so high anyway, that for accurate time keeping It would be interesting to know if this reasoning is not correct for all use cases. |
Build succeeded: |
No, I did not encounter any real world problem. I think your reasoning is in-line with what most users would expect too. I am investigating adding more interrupt handling to the periph_qdec module. I want to add the equivalent of something like |
Good to know that the work around didn't cause immediate issues. Thx for the PR :) This indeed way superior compared to the work around used before :) |
Contribution description
From the git comment msg:
If a timer's channel was set with a really small realtive duration from now, such that it would be missed (underflowed), the driver would stop the timer, potentially causing missed ticks. It was stopped to ensure that the channel's output-compare register could be set to the current counter value, before re-enabling the timer's counter. This is a condition that will ensure that the underflow won't happen again and the interrupt will fire, at the cost of losing some ticks for very high speed clocks.
This patch replaces the logic that stopped the timer. Instead it uses a register provided by the timer hardware to trigger timer interrupts via software.
Testing procedure
$ cd tests/periph_timer_short_relative_set $ make BOARD=nucleo-f303ze flash term
patch to intentionally break test
Issues/PRs references