patchAVR C Runtime Library - Patches: patch #5343, Add a util/setbaud.h...


You are not allowed to post comments on this tracker with your current authentication level.

patch #5343: Add a util/setbaud.h "helper" file

Submitted by:  Cliff Lawson <clawson>
Submitted on:  Tue 29 Aug 2006 09:13:30 AM UTC  
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  Joerg Wunsch <joerg_wunsch> Open/Closed:  Closed

Thu 31 Aug 2006 04:25:34 PM UTC, comment #3: 


There were overflow problems with baud rates lower than 32768 in C expressions. I couldn't see the problem before because my F_CPU and BAUD were defined long. This is solved in version 1.3 submitted by tacking UL at the end of the constants involved to force the compiler to use long type arithmetics. cpp expressions (#if's) are supposed to operate in 64 bit precision and they shouldn't overflow for reasonable frequency and baud rate values.

The rounding errors were issued previously and they should not give different results to hand calculated.

UBRR values delivered had the same error tolerance, 2% default. Obviously when there was no overflow errors.

U2X=0 was always used when possible.

Anyway, I can't see advantages in using a "short" lookup table for this case of so many possible F_CPU/BAUD combinations.


Carlos Lamas <carloslamas>
Wed 30 Aug 2006 02:16:16 PM UTC, comment #2: 


Thanks for that but it kind of misses the point of what this header file was intended for. The problem it hopes to avoid is that using just the datasheet formula for calculating UBRR you:

a) run the risk of numerical rounding errors
b) you deliver UBRR values for F_CPU/BAUD combinations in which the Error% is outside the -2%..+2% range
c) you don't necessarily use U2X=0 where possible and only offer U2X=1 when it's the only way to stay within requirement (b)

The hand crafted lookup-table approach that the original setbaud.h offers means that the user is alerted to unachievable baud rates for F_CPU and BAUD and is only instructed to use U2X=1 when absolutely necessary.

If it lacks anything it is support for MORE common F_CPU values.


Cliff Lawson <clawson>
Wed 30 Aug 2006 01:46:27 PM UTC, comment #1: 

With the same philosophy of the last submission I've modified the static approach of the header to let the preprocessor calculate the appropriated values without limiting the processor or baud rate frequencies. Maybe this is more versatile.

Carlos Lamas <carloslamas>
Tue 29 Aug 2006 09:13:30 AM UTC, original submission:  

This is a header file to aid the setting of UBRR for an AVR UART. Rather than calculating the UBRR value to use based on F_CPU and BAUD (which is prone to rounding errors) it uses a look up table for popular F_CPU and BAUD values. A further advantage is that ONLY baud rates that can operate with less than +/-2% error are offered. Attempts to use an out of range baud rate will just produce a #error. The file also know when a selected baud rate can only be achieved using U2X=1 mode and in this case it defines a USE_2X value so that code to set U2X=1 mode can be wrapped in a #ifdef USE_2X/#endif

Cliff Lawson <clawson>


Attached Files
file #10659:  setbaud.h added by carloslamas (4KiB - application/octet-stream - V1.3 header to set UBRR from given F_CPU/BAUD values)
file #10638:  setbaud.h added by carloslamas (4KiB - text/plain - V1.2 header to set UBRR from given F_CPU/BAUD values)
file #10626:  setbaud.h added by clawson (11KiB - application/octet-stream - V1.1 header to set UBRR from given F_CPU/BAUD values)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by joerg_wunsch (Updated the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-10-28 joerg_wunsch StatusIn Progress => Done
        Open/ClosedOpen => Closed
    2007-10-28 joerg_wunsch StatusNone => In Progress
        Assigned toNone => joerg_wunsch
    2006-08-31 carloslamas Attached File- => Added setbaud.h, #10659
    2006-08-30 carloslamas Attached File- => Added setbaud.h, #10638
    2006-08-29 clawson Attached File- => Added setbaud.h, #10626

    Back to the top

    Powered by Savane 3.6