Baud rate calculation


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588

    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,588

    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,588

    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,588

    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!

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

    Default

    nope i don't hate them... it's more a matter of updating it to fit with the EUSART.... as already asked a while back.

    Do you really need it as this fast is always my question

    I'll do the EUSART thing one day.

    For now, i'd modified the baud restriction. try it... use it to your own risk and all the usual disclaimer stuff. Didn't test it in real environement so, if it works, it works case not... too bad
    Attached Files Attached Files
    Last edited by mister_e; - 21st July 2006 at 22:08.
    Steve

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

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588

    Default

    Quote Originally Posted by mister_e
    ...Do you really need it as this fast is always my question...
    Well, I don't know exactly how fast I need it the USART to go. All I know is that it has to be fast enough so that I can transfer 2 bytes from the 16F to the 18F without losing the USB connection.

    I had some difficulty in coming up with a baud rate that was compatible between a 16F @ 20MHz and a 18F @ 48MHz. Since I can't change the FOSC for the 18F because of USB, I did the next best thing and adjusted the FOSC on the 16F. I used 16 MHz which is a multiple of 48, I figured I could come up with a compatible SPBRG value that way.

    Sure enough, SPBRG=0 @ 16 MHz and SPBRG=2 @ 48 MHz both give 1000 KBAUD. It's not the maximum of 1250, but it's close. Now I have to make some tests later and see if the USB connection holds up.

    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!

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

    Default

    use the calc and get the lower error % is one of the best trick i can say. Now uncheck the BRGH=1 box to compare both results. Sometime BRGH=1 give a better error % sometimes not. it's all depend of the OSC speed and the BRGH setting. This one of the reason i did this calc. Probably i could add an auto error % feature wich will compare both BRGH=1 and BRGH=0 results and give the best of it. As now it just provide the best error % for the BRGH you choose.

    Using your example, both gave 0% error percentage.. couldn't be better assuming a real 16MHZ and a real 48MHZ
    HTH
    Last edited by mister_e; - 21st July 2006 at 22:56.
    Steve

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

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588

    Default

    Thanks Steve, the new "improved" version works great!

    Robert
    Attached Images Attached Images  
    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!

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

    Default

    How dare you edit the title bar? mon esti'd'chien sale LMAO!

    Great to know it's working
    Steve

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

  12. #12
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588

    Default

    Paint Brush is my friend.

    I was wondering if you'd notice.

    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!

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

    Default

    Hehe... yes i do
    Steve

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

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 21:58
  2. PIC 18f1220 EUSART Baud Rate Cache Problem
    By wklose99 in forum Off Topic
    Replies: 3
    Last Post: - 15th April 2008, 01:39
  3. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 03: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, 23:41
  5. Baud Rate and Timing Calculator
    By picnaut in forum General
    Replies: 3
    Last Post: - 23rd January 2004, 17: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