Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC UART Rates

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hello all i wanted to ask something that may be simple...

I wanted to send data at 4800bps i usually just get the info from the data sheet but this isnt a common speed i guess heh...

So i need to do the calculations. Now the issue is :

1. Im not sure if im right...
2. I have 2 speeds 1 micro is 20mhz and the other is 40mhz so im doing it for both..

The PIC in question is a 18F2525..
From Datasheet:
For a device with FOSC of 16 MHz, desired baud rate of 9600, Asynchronous mode, 8-bit BRG:
Desired Baud Rate = FOSC/(64 ([SPBRGH:SPBRG] + 1))
Solving for SPBRGH:SPBRG:
X = ((FOSC/Desired Baud Rate)/64) – 1
= ((16000000/9600)/64) – 1
= [25.042] = 25
Calculated Baud Rate = 16000000/(64 (25 + 1))
= 9615
Error = (Calculated Baud Rate – Desired Baud Rate)/Desired Baud Rate
= (9615 – 9600)/9600 = 0.16%

20Mhz:
20000000/4800 = 4166.666666666667
4166.666666666667 / 64 = 65.10416666666667
65.10416666666667 - 1 = 64.10416666666667
64.10416666666667 = 64
((20000000/4800)/64)-1 = 64

20000000/(64(64+1)) = 4807.692307692308
(4807.692307692308 - 4800)/4800 = 0.0016025641025642 %

Correct?

40Mhz:
40000000/4800 = 8333.333333333333
8333.333333333333 / 64 = 130.2083333333333
130.2083333333333 - 1 = 129.2083333333333
129.2083333333333 = 129
((40000000/4800)/64)-1 = 129

40000000/(64(129+1)) = 4807.692307692308
(4807.692307692308 - 4800)/4800 = 0.0016025641025642 %

Correct?

Exact same speed.... Would these values work ? I find it a pain in the butt to test 2 PICs communicating.... so i want to ask before i go nuts if i get some bad results heh i know it wasnt this...

EDIT:
I remember there being a calculator of some sort or a speed sheet formula... i dont know how to use those really to make my own but would love if someone can repost them heh
 
Last edited:
Hi atom, look at this.;)
 

Attachments

  • PicMultiCalc..exe
    340 KB · Views: 706
Last edited:
YAY!!!! thanks... just tested it and works fine!!! my calculations was spot on ... i did something right!! i feel great now heh... Thanks again Eric...
 
Find the value for 9600 and divide by two, much simpler math =)
 
Last edited:
Jason,

I wrote a stand-alone SPBRG Calculator several years ago that supports 16-bit and legacy 8-bit SPBRG solutions (on Forum.Microchip). The code generator portion of the program is not completed.

Revised SPBRG Calculator (spreadsheet and stand-alone program)

Mike

**broken link removed**
 

Attachments

  • SPBRG Prog Screen&#32.JPG
    SPBRG Prog Screen&#32.JPG
    63.4 KB · Views: 366
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top