Baud rate calculation


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601

    Default Baud rate calculation

    Hi,

    I have a 16F876A transmitting via HSEROUT to a 18F4550 with a 20MHz crystal and I'd like to use the maximum speed possible.
    http://ww1.microchip.com/downloads/e...Doc/39582b.pdf

    I select High Speed (BRGH=1) on table 10.1 on p.115, so I only have the option of SYNC=0 (asynchronous). Asynchronous table 10-3 on p.116 gives a KBAUD rate of 312.5 for a 20 MHz speed and a SPBRG value 0.

    I have absolutely no idea how they got from this formula FOSC/(16 (X + 1)) using the settings I chose. Anyways, how does this relate with the HSER_BAUD command? KBAUD means kilobaud in my mind, that would mean 312.5 x 1000, that value seems waaaaaay too high for me. I wasn't expecting anything higher than 115200 or so based on experience with modems.

    I checked the datasheet for the 18F4550 (table 20-3 on p.245) and that's exactly the top end:
    http://ww1.microchip.com/downloads/e...Doc/39632c.pdf

    So now I'm confused on what setting to take to get the 2 chips working reliably. I'd really like to understand this 'cause I might have to change chip later.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Look at that...
    http://www.picbasic.co.uk/forum/atta...6&d=1118138371

    Yeah the same placed on another website but for PBP... from the same guy
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    I was just going to mention your calculator Steve. Beat me too it.

    Robert,

    I think you're looking at the wrong table. 10-3 is for BRGH=0. For BRGH=1, see table 10-4.

    @ 20mhz, with BRGH=1, and SPBRG= 0, the baud rate is 1250K, that's 1.25 million bits per second. And the formula works with that one.

    DT

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601

    Default

    Crap, and I had checked my work too. Getting old...

    Steve's utility gave this (real cool, can check calculations instantly, saves me from typing that into an Excel sheet):
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 10 ' 115200 Bauds

    I'm not a fan of all-encompassing hex values like that, I like to know what is happening. Is there a significant difference in performance if I set the bits manually like this?
    DEFINE HSER_SPBRG 10 ' 115200 Bauds
    RCSTA.7 = 1 ' SPEN Serial port enable
    RCSTA.4 = 1 ' CREN Continuous receive enable
    TXSTA.5 = 1 ' TXEN Transmit enable
    TXSTA.4 = 0 ' SYNC Asynchronous communication
    TXSTA.2 = 1 ' BRGH High speed baud rate

    I like comments, it helps make up for a miserable memory. I can toggle stuff ON and OFF easily that way. I usually ignore default values, but I make exceptions for important and relevant settings like SYNC in the example above.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601

    Default

    Steve, any chance of letting the baud rate utility accept 1250000? That is a valid speed according to the datasheets, but the utility does not accept it.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601

    Default Examples:

    These values work in the utility:
    FOSC=20
    SPBRG=0
    20/16(0+1) = 1.250 = 1250 KBAUD


    These don't:
    FOSC=48
    SPBRG=0
    48/16(0+1) = 3.000 = 3000 KBAUD

    Don't you hate 18F MCUs?

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. PIC 18f1220 EUSART Baud Rate Cache Problem
    By wklose99 in forum Off Topic
    Replies: 3
    Last Post: - 15th April 2008, 00:39
  3. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 02:17
  4. PIC12F675, accuracy of baud rate with Internal Oscillator
    By Chris Mayhew in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 22:41
  5. Baud Rate and Timing Calculator
    By picnaut in forum General
    Replies: 3
    Last Post: - 23rd January 2004, 16:48

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts