PDA

View Full Version : Baud Rate and Timing Calculator



picnaut
- 13th January 2004, 04:55
Hello Everyone,

Fred Hillhouse has made a great baud rate and timing calculator using Microsoft Excel. He's been kind enough to email it to me and let me post it for everyone.

Basically, in the Excel spreadsheet you have 3 light blue boxes where you enter in numerical values; one for your oscillator frequency, one for your desired baud rate, and one for your desired timer interrupt frequency (to calculate timer interrupts).
If you only want to do a baud rate calculation, ignore the "Desired Frequency" box. If you only want to do a timer interrupt calculation, ignore the "Baud rate, desired" box.

These values are all tied into tables, with the main calculations hilighted in green. If you change anything in the light blue boxes the data in the tables will change.

I have only used the baud rate portion of the calculator so far, but if Fred has put as much time into the timer portion, I'm sure that it will work great too.

So, if you want to change your PIC's baud rate programmatically (i.e. without using DEFINE), you simply use the following code.


RCSTA = $90 ' Enable USART receive


TXSTA = $20 ' Set USART parameters if BRGH = 0

OR

TXSTA = $24 'Set USART parameters if BRGH = 1


SPBRG = ??? ' Whatever the SPBRG value is on the calculator


That's it!

Those 3 lines (remember to choose only one correct value for TXSTA) are all you need to change your baud rate in code and use HSERIN and HSEROUT at the baud rate you've set.

I've used this calculator for all the standard baud rates from 300 to 115200 and it works great. It even calculates your percentage of error using certain crystals at different baud rates.
Just remember, with a 20MHz oscillator, you're not going to be able to run the USART any lower than 2400 baud. However, a 4MHz oscillator can run the entire range from 300 baud to 115200 baud.

Enjoy.

Fred
- 13th January 2004, 16:15
Be careful using the TIMER0 stuff. I haven't done much testing of it.

Let me know if you have any problems with the file.

bobthebud
- 23rd January 2004, 16:02
Nice one my friend. On behalf of us all -- Thanks!

picnaut
- 23rd January 2004, 17:48
Don't forget about Fred.
He did all the work.
I just posted it.
I'm thinking of making a slick VB version of the calculator at some point.
I'll post it when I do.