-
Notifications
You must be signed in to change notification settings - Fork 1k
HardwareTimer: Allow setting preload enable bits #900
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
Conversation
Hi @matthijskooijman,
As per the reason you mentioned, I would suggest to change default value in constructor to
From my point of view, this feature is really made for experts, and should not be part of Arduino API. What do you think about this proposal ? |
I considered that, but I didn't want to change default behaviour. Also, the hardware default is to have preload disabled, so sticking to that might prevent user surprise. On the other hand, if things just work more reliably out of the box, that might also prevent user surpise, so maybe enabled-by-default is indeed better. But then the question might be: Do we need preload-by-default for CC as well?
I'm pretty sure there are applications that need preload disabled, so it is probably best to offer that (even though for our application right now, just flipping the default would have been sufficient).
I had not realized this (only considered that setMode would set a "default" value, but it can of course also change the value later). Some of this can of course be mitigated by documentation, but that might still leave room for confusion.
This is true, but direct HAL calls are of course a lot less elegant. If we go that route (or maybe regardless), it might be useful to make the
I can certainly live with this proposal. However, since I already wrote and tested the code, how about adding just the method for ARR, since that one is free of complications, and leaving out the CCRx version to prevent confusion? And changing the default is fine too, of course. |
That is fine for me: |
9abbc79
to
0812f70
Compare
Ok, done. I also added a commit to expose some methods that are useful when talking to the HAL directly, and fixed some coding style issues. |
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.
Missing one comment in header.
By the way can you update the wiki API page (new function + new exposed methods):
https://github.com/stm32duino/wiki/wiki/HardwareTimer-library#API
thanks
This changes the default for preload (i.e. delay updating the overflow value until an update event such as timer overflow) to enabled, since this is will probably make the timer output behave as expected as much as possible (e.g. you cannot make it "skip" an overflow and run it all the way up to 0xffff by lowering the overflow value).
These methods allow access to some of the more low-level values and are useful to implement some more advanced usecases, where the HAL is also directly accessed.
0812f70
to
e761507
Compare
I'll update the wiki when it is final (i.e. merged). |
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.
LGTM
Thanks
PR: HardwareTimer: Allow setting preload enable bits stm32duino#900 introduced a regression in servo library.
PR: HardwareTimer: Allow setting preload enable bits stm32duino#900 introduced a regression in servo library.
PR: HardwareTimer: Allow setting preload enable bits #900 introduced a regression in servo library.
This PR adds methods to HardwareTimer to change the "preload" setting of the overflow/ARR and CC registers. By enabling preload, updates to these registers can be made at overflow time rather than halfway a period, which can improve the output waveform, as well as prevent missing an overflow event (when decreasing the overflow value to below the current timer value).
These methods are fairly simple and use the LL_TIM HAL functions. I originally implemented this using the higher-level
TIM_Base_SetConfig
but then found that the prescaler was updated using LL_TIM functions, which did not update_timerObj.handle.Init
, soTIM_Base_SetConfig
would then revert to a 0 prescaler. So, following the example ofsetPrescalerFactor
, these new methods just write to the registers directly with the LL_TIM functions (which are also more specific,TIM_Base_SetConfig
would update a few different registers in addition to the preload enable bit).