Description
The HardwareTimer class applies a -1 to the timer tick values it sets. e.g. in setOverflow()
:
Arduino_Core_STM32/cores/arduino/HardwareTimer.cpp
Lines 465 to 474 in cc05df9
And similarly in setCaptureCompare()
.
This is a bit unexpected. When using TICK_FORMAT
, I would expect that the value you pass is set into the hardware directly. One might say that the tick number passed to these function identifies the number of the tick and is 1-based and must be translated to 0-based when writing to the register, but I did not expect this. I passed 0 to this function only to find that the capture never triggered, apparently since -1 was written to the register.
Furthermore, when using TICK_MICROSECONDS
, it would also make sense to pass 0. If you do that now, the -1 also causes an underflow and the compare never triggers. This also happens when you pass a non-zero but low value (depending on the value of the prescaler), so just passing a fixed low value is not always helpful either.
So: I would think that all these -1's should just be removed? Or is there any compelling argument I'm missing?