|
|
View previous topic :: View next topic |
Author |
Message |
caddy
Joined: 24 Jun 2007 Posts: 14
|
Baud Rate Equations in UART |
Posted: Wed Jul 25, 2007 11:24 pm |
|
|
Hi
I'm trying to calculate the minimum Fosc speed for an application.
The application is MIDI. It transfers at 31250 bps. Each midi 'symbol' consists of 8 bits of data with a start and stop bit making the total 10 bits. If I am correct this means the application needs to run at 31250/10 = 3125 baud. (It is confusing because in the CCS #USE RS232 directive it treats bps and baud as the same thing..)
Currently I am using a PIC18F2620 with 20MHz crystal and the hardware UART. And I want to determine, mathematically, the theoretical minimum speed of crystal I can use. In the 18F2620 datasheet there is a chart on page 206 (example 18-1) that shows how to calculate the baud rate error. However, I've examined these equations and I think the 'error' that they are referring to is actually the accuracy/rounding error of SPBRGH:SPBRG.
Anyway, basically, I would like to know how to calculate the minimum crystal speed I'd need to transfer data at 31250 bps. Any help would be great. I would like to understand how it is worked out, not just get the answer.
Thanks |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 26, 2007 2:54 am |
|
|
Quote: | The application is MIDI. It transfers at 31250 bps. Each midi 'symbol' consists of 8 bits of data with a start and stop bit making the total 10 bits. If I am correct this means the application needs to run at 31250/10 = 3125 baud. (It is confusing because in the CCS #USE RS232 directive it treats bps and baud as the same thing..) | Not confusing at all; in RS232 bps and baud are the same thing! In other, more sophisticated, modulation schemes like QPSK a single baud can contain multiple bits but in RS232 a single baud equals 1 bit.
Note: bps = bits per second, not bytes.
31250 bps / 10 = 3125 bytes per second.
Quote: | In the 18F2620 datasheet there is a chart on page 206 (example 18-1) that shows how to calculate the baud rate error. However, I've examined these equations and I think the 'error' that they are referring to is actually the accuracy/rounding error of SPBRGH:SPBRG. | True.
Quote: | Anyway, basically, I would like to know how to calculate the minimum crystal speed I'd need to transfer data at 31250 bps. Any help would be great. I would like to understand how it is worked out, not just get the answer. | The formula for calculating the baud rate settings is Code: | desired baudrate = FOSC/[4 (n + 1)] |
To get the required clock frequency for your baudrate this can be rewritten to Code: | FOSC = desired baudrate * [4 (n + 1)] | From this you can see that for the lowest possible clock frequency we will have to set n as low as possible, i.e. zero.
Code: | FOSC = 31250 * [4 (0 + 1)]
= 31250 * 4
= 125kHz |
|
|
|
Ttelmah Guest
|
|
Posted: Thu Jul 26, 2007 2:55 am |
|
|
On a signalling system, using just two transmission 'states' (on/off), bps, and baud _are_ the same. This is true of the Midi interface, and the PIC async serial interface.
Where the two concepts 'differ', is over something like an audio link, where if (for instance), you sent 16 different 'tones' and could detect all 16, changing tones 1000 times per second, the 'baud' rate would be 1000/sec, but the bps rate, would then potentially be 4* this. (16 states, can transfer 4 bits).
Your baud rate, and your bps rate, are 31250. The _character per second_ rate (cps), is the 3125 figure you derive.
Potentially the slowest clock that could generate this rate, would be this frequency*16. 500000Hz. With the divider set to '0', you get a division by '1', and with BRGH set to one, the prescaler is /16.
At this clock rate, the selectable bps rates, are:
31250(/1), 15625(/2), 10416(/3) etc.. If you wanted a rate of 9600bps (a standard serial rate), the nearest you could get, would be 10416bps (using the /3 divider), or 7812.5bps using /4. The errors for this rate, would then be 8.5% ((10416/9600)-1), or 22.88% for the second possibility.
Slow clocks, bring with them the limitations that you may not be able to do the required work between the characters...
Best Wishes |
|
|
Ttelmah Guest
|
|
Posted: Thu Jul 26, 2007 2:58 am |
|
|
Ckielstra, /4 for the BRG, is only available for sync operation on most PICs. The dividers supported are /16, and /64. The lowest clock is therefore 4* your value.
Again we post simultaneously!...
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 26, 2007 4:13 am |
|
|
Quote: | Ckielstra, /4 for the BRG, is only available for sync operation on most PICs. The dividers supported are /16, and /64. The lowest clock is therefore 4* your value. Smile | Thanks for this additional info. I only checked the datasheet for the mentioned 18F2620 which turns out to be one of the newer chips supporting a 4* divider for async operation as well (table 18-1).
So, for this chip, my calculation is valid. It is good to know this is only true for the newer chips with EUSART module.
Quote: | Again we post simultaneously!... | Yes. Seems like we are here at the same working hours. |
|
|
caddy
Joined: 24 Jun 2007 Posts: 14
|
|
Posted: Thu Jul 26, 2007 5:02 pm |
|
|
Thank you guys, these posts really educated me!
Could someone just explain, how do you set the prescaler to /16 vs /64 within CCS?
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Fri Jul 27, 2007 2:35 am |
|
|
It is set automatically to get the closest rate to the one you request.
Basically, you have a range of possible dividers (on the normal PICs), of 1*16 to 256*16. In steps of '16'. Once the divider needed goes above 4096, the /64 prescaler is selected, and the possible dividers then go from 64*65 to 64*256, in the larger 64 steps. Maximum divider of 16384. If the division is possible using the smaller divider, you get finer control, so this will be automatically selected.
Now, the chip you have (must admit, I missed the chip number...), allows the main divider, to have a range of 1 to 65536, instead of 1 to 256. With this larger range, the prescaler can be smaller, and these chips allow the /4 prescaler to be selected, _only when used with the 16bit divider_, in asynch mode. This gives the value that Ckielstra posted.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|