-
Notifications
You must be signed in to change notification settings - Fork 978
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
HardwareTimer: support 32 bit timers #2071
Labels
enhancement
New feature or request
Comments
Hi @GianfrancoIU1JSU |
GianfrancoIU1JSU
added a commit
to GianfrancoIU1JSU/Arduino_Core_STM32
that referenced
this issue
Jul 16, 2023
GianfrancoIU1JSU
added a commit
to GianfrancoIU1JSU/Arduino_Core_STM32
that referenced
this issue
Jul 16, 2023
GianfrancoIU1JSU
added a commit
to GianfrancoIU1JSU/Arduino_Core_STM32
that referenced
this issue
Jul 16, 2023
fpistm
changed the title
Setting 32 bit timers overflow value to maximum is not possible
HardwareTimer: support 32 bit timers
Jul 21, 2023
fpistm
added
enhancement
New feature or request
and removed
bug 🐛
Something isn't working
labels
Jul 21, 2023
Hi @GianfrancoIU1JSU Ex of limitation
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug$overflow - 1$ since the function is meant to recieve as argument the overflow value and not the terminal count.
The function
HardwareTimer::setOverflow()
allow to set the overflow value as auint32_t
an then set the value of the STM32 ARR Register to:has shown in the function implementation below.
Arduino_Core_STM32/libraries/SrcWrapper/src/HardwareTimer.cpp
Lines 521 to 557 in 8ff274a
this works fine with 16 bit counters and 32 bit counters when not used in the full range.
but to set the max value of a 32 bit counter the ARR register value should be set to
0xFFFFFFFF
to do so the function argument should be set to0x100000000
but since the argument is defined asuint32_t
the value will not fit and overflow as0
I want to point out that setting the value to the maximum is an important thing, since not only will increase marginally the maximum counter value but more importantly allows to calculate values of thresholds and time elapsed between input capture event easly because
$\mu Controller$
elapsedTicks = capture - oldCapture
if all variables are defined asuint32_t
and the elapsedTicks guaranteed to be under0x100000000
will work even if an overflow occurs.and in the same way when generating a square wave updating the ARR value with the next event value can be done as
nextVal = lastVal + delta
under the same conditions.this methods are common practice on timer usage on any
workaround
In the actual state the problem can be solved by either
neither of these solution are efficient nor elegant.
Suggested Fixes
to me the easiest way to fix this issue is changing the function definition from
to
by using this approach the fix should not cause any compatibility issues with existing code
Constatation
here you can see the serial output of the STM32 when measuring a 1hz pulse over an 80Mhz timebase
both generated by the same oscilltor so they are perfectly coherent.
all the readings are perfect except for when the overflow occurs in that case you sistematically get one count more that is due to the missing code.
after applying one of the above workaround the error never appears again
here there is a the code on witch i've found the bug:
Desktop :
Board:
The text was updated successfully, but these errors were encountered: