2024-02-09 03:06 AM - last edited on 2024-02-09 08:34 AM by SofLit
This is a request for clarification of the TUR (Time Unit Ratio) calculation in the TTCAN implementation of the FD-CAN peripheral that is part of STM32MP1xxx systems.
Specifically: the TUR is composed of a numerator and a denominator, designated FDCAN_TURNA.NAV and FDCAN_TURCF.DC, respectively, in the documentation.
For example, see RM0436 pages 2994-2995.
The calculation of the NTU (Network Time Unit) is NTU = clock_period * (TUR.numerator / TUR.denominator)
My question: is the division a rounding division or a truncating division? The documentation does not specify this.
As a concrete example, I am analyzing a TTCAN system using the STM32MP157 FD-CAN1 peripheral with:
- numerator = 0x1ffff (= 131071, the maximum allowed)
- denominator = 8192
With rounding division, TUR = 16, with truncating division, TUR = 15.
Truncating divisions are more common in hardware, so what is the FD-CAN1 peripheral using for its TUR calculation?
Any clarification would be appreciated.
Thanks in advance.
2024-02-12 12:08 AM
Hi @tarmasr
Not FDCAN expert, but if I look to examples provided on RM0436 Table 452,
the resulting value for your settings (0x1FFFF and 0x2000) will be 15.99987793
Regards.
2024-02-12 12:32 AM - edited 2024-02-12 03:05 AM
Hi @PatrickF ,
Thanks for taking the trouble to answer my query.
Yes, I agree with the theoretical value (15.999...) and I did see the examples, but I was wondering if any form of rounding or truncation takes place, particularly since this combination of values (0x1FFFF and 0x2000) is so close to a whole number (16) and was probably intended to give exactly that number.
The query came about because it seems unlikely that the TUR uses floating point arithmetic internally -- it's probably all integer arithmetic.
However, based on your answer and the examples, some of which also result in fractional values, I will assume then that little or no rounding or truncation at all takes place and that internally the TUR is used as-is.
My suspicion still is that it operates more like muldiv(period, numerator, denominator) which is approximately:
floor(((period * numerator) + denominator/2) / denominator)
But that we will probably never know, unless one of the designers of the TTCAN portion of FD-CAN1 weighs in.
Best wishes,
David.