Designer III Blog (home) Designer III Blog RSS Feed

Designer III Blog January Archive

Favorite Posts:
, :
##OFC##



(Login / Register)



Advertisement:
Increase your sales



FFF5D6,FFF5D6,FFF5D6,FFE699
Tags

Blog Roll:


interger truncation Designer III Blog; January, 2009 Archive; Designer III Blog
  • -- ../../local/design/interger_truncation

    Why is my AVR baud rate wrong?

    By Bob Paddock at 01/11/09 20:13

    Recent AVR-LibC FAQ submission of mine:

    Why is my AVR baud rate wrong?

    Some AVR datasheets give the following formula for calculating baud rates:

    (F_CPU/(UART_BAUD_RATE*16L)-1)

    Unfortunately that formula does not work with all combinations of clock speeds and baud rates due to integer truncation during the division operator.

    When doing integer division it is usually better to round to the nearest integer, rather than to the lowest. To do this add 0.5 (i.e. half the value of the denominator) to the numerator before the division, resulting in the formula:

    ((F_CPU + UART_BAUD_RATE * 8L) / (UART_BAUD_RATE * 16L) - 1)

     


    Tags: avr baud rate • interger truncation • round to nearest integer • avr libc •
    0 Comments. - Permalink


    interger truncation Archives: • January, 2009





  • * com * top 100 * 10 * 1108562404 * Blog * Espanol *

    Have you added a link to us from your website? (1108562404):

    • <a href="http://blog.designer-iii.com">Designer III Blog</a>
    interger truncation Designer III Blog; January, 2009 Archive; Designer III Blog

    Web site copyright (c) 2007-2011 GLR Sales LLC.



    (rozwqizwipzerw)

    Privacy & DMCA Policy
    interger truncation Designer III Blog January Archive