Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Oct 07, 2012 2:26 am |
|
|
Normally depends on what the other end wants....
However 'calculation', well there are a lot of things that affect the rates you _can_ use. No calculation as such, except in balancing the factors.
First, cable length. The longer the length you require, the lower the rate you are allowed to use. This is in the RS232 specifications.
Second how much data you want to transfer. Basically 9600bps, gives almost 1000 characters per second. If your application needs more, then you have to go faster.
Then reliability. The noise margins etc., go down with increasing frequency. Generally data error rates rise as you push the rates up.
Fourth hardware limitations. The transceivers used for the bus will have limits, and the faster data is arriving, the quicker your code will have to be.
Then the only PIC hardware limitation. Depending on your clock frequency used by the PIC, there will be a percentage error in the baud rate actually generated. Generally this rises the faster you try to work. So (for instance), working with a 20MHz crystal, and a PIC16, at 19200bps, there is 1.72% error, but at 57600bps, there is 8.51% error. The maximum total error on the bus (both ends) should be kept below about 4% for any hope of reliability, so with this chip/clock, 57600 is unuseable.....). Now this can be avoided by choosing a master oscillator that is a multiple of the standard UART frequencies. So (for instance) using a master clock at 18.432MHz, though slower, gives a 'perfect' baud rate at 57600 (and at most other rates).
Basically data sheets.
Start with the PIC data sheet which shows how baud rate division is done, and usually lists some examples with their rates.
Then an RS232 specification sheet (National Semi do the best).
Then the data sheet for the driver you want to use, and for the wire.
However the 'other end' is the biggest starting point. For instance if you are talking to a GPS, the original standard for their communications is 2400bps, with later moves to 9600bps. Most common instrument protocols use 9600bps, or 19200bps (this is the fastest rate supported at the maximum original specified cable length for RS232 - hence it's popularity).
Best Wishes |
|