This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Algorithm clarification

I am writing code to calculate the baud rate registers for UART1. There is a flow chart on page 336 of the manual that I am using as a guide. There is a block that says:

int(PCLK / (16 * BR * FREST)

What do they mean by int? Does that mean convert the floating point result to an integer by casting? Please clarify.

I know the table part means find the closest value to the calculated decimal result in the lookup table. I am representing those values as constant ints and doubles.

  • "the manual" - don't you think you should tell us what "the manual" is? You haven't even told us what processor you have.

    "on page 336" - even if we do know what processor you are using, we would still not know which revision of "the manual" you are using.

    There are no type casting in the manual. But the manual do tell you to use the integer part of the equation presented. Most probably, the manual suggests that you should truncate the result of the division - especially if the processor also have a fractional baudrate divisor register for more exact baudrate generation.

    If the processor do not have a fractional baudrate divider, then it is meaningful to perform proper rounding to use the closest value.

    No, I can not see why you should represent any values as doubles - no microcontroller I have seen has a baudrate generator that expects any floating point values. They always take an integer baudrate divisor. And an optional fractional part, normally expressed as a quotient of two integers (but potentially stored in the same register)

  • "page 336 of the manual"

    What manual? And what version/issue/release of that manual?

    "What do they mean by int?"

    Who is "they"? Why don't you ask "them"?

    Since the expression is a division, its result is likely to have a fractional part.

    Putting int(...) like that is a pretty conventional way to say, "the integer part of ..."