|
|
View previous topic :: View next topic |
Author |
Message |
charles Guest
|
RS485 - baud rate |
Posted: Tue May 16, 2006 9:13 pm |
|
|
Hi,
I am really new to this world.
I just built a RS485 connection between 2 microcontroller, I use the #use rs232 directive to set up the communication.
Every works fine, I can send and receive data from peer to peer.
The drawback is I can't go higher that 230400 baud (apparently).
I was wondering if there is any other interface that can use a RS485 link and be faster.
Any pieces of information would be really helpfull,
thanks,
Charles. |
|
|
carmarmu
Joined: 09 May 2006 Posts: 15 Location: Valencia (Spain)
|
Re: RS485 - baud rate |
Posted: Wed May 17, 2006 12:07 am |
|
|
Please, can you explain a bit the application?
I now that RS485 have the following specifications:
Max speed at 12 m: 35Mbps
Max speed at 1200 m : 20 kbs
If you say me what you want to do, which is the purpose, whereupon type of devices you want to communicate, maybe i can help you.
Regards.
charles wrote: | Hi,
I am really new to this world.
I just built a RS485 connection between 2 microcontroller, I use the #use rs232 directive to set up the communication.
Every works fine, I can send and receive data from peer to peer.
The drawback is I can't go higher that 230400 baud (apparently).
I was wondering if there is any other interface that can use a RS485 link and be faster.
Any pieces of information would be really helpfull,
thanks,
Charles. |
_________________ **CaRmArMu** Valencia (Spain) |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: RS485 - baud rate |
Posted: Wed May 17, 2006 6:35 am |
|
|
charles wrote: | Hi,
I am really new to this world.
I just built a RS485 connection between 2 microcontroller, I use the #use rs232 directive to set up the communication.
Every works fine, I can send and receive data from peer to peer.
The drawback is I can't go higher that 230400 baud (apparently).
I was wondering if there is any other interface that can use a RS485 link and be faster.
Any pieces of information would be really helpfull,
thanks,
Charles. |
What frequency and PIC are you using. Are you saying that it won't communicate faster than 230400 or that the compiler is complaining? If the latter, its due to the freq. of the PIC. |
|
|
Guest
|
|
Posted: Wed May 17, 2006 11:18 am |
|
|
Hi,
Thank you,
The application is:
I have one master (PIC18F8722) that send data through a serial RS485 link to slaves (PIC18F8627). On the slaves end the rs485 circuitry is build on custom board, on the master end since I use a Microship demo board I built the RS485 circuitry on a breadboard for testing.
I use putc and getc to send and receive data, I modified the rs485 driver provided by the CCS C Compiler to manage a peer to peer communication on the RS485 bus.
I set the microcontrollers frequency to 10MHz.
If I set the communication speed to 230400 it works, if I set it to 460800 or greater. Then if I try to set the clock faster it won't work.
I was wondering if there are other way to send and receive bytes that are not putc and getc that could be faster since apparently the max speed on a 12m rs485 is supposed to be 35Mbps.
Thanks,
Charles. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 17, 2006 12:10 pm |
|
|
Also tell us if you are using hardware or software UARTs with the
#use rs232() statements for master and slave. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed May 17, 2006 12:25 pm |
|
|
The formula for the baud rate with BRGH high is
baud = Fosc(16(X+1))
If you have 10MHz osc then using values of x
x=0, 625000
x=1, 312500
x=2, 208333
x=3, 156250
if 40MHz then
x=0, 2500000
x=1, 1250000
x=2, 833333
x=3, 625000
x=4, 500000
x=5, 416666
x=6, 357142
x=7, 312500
x=8, 277777
x=9, 250000
x=10, 227272
x=11, 208333
So the fastest you can transmit if you were running at 40MHz would be 2.5MBPS. |
|
|
Ttelmah Guest
|
|
Posted: Wed May 17, 2006 2:40 pm |
|
|
Not quite right on the formula.
The chips with later USARTS, support the prescaller going down to 4, rather than 16, giving the formula:
baud=Fosc/(4(X+1))
The problem though is the percentage error in the values. At 230400, with a 10MHz clock, the nearest value is X=10, which gives:
baud =1E7/(4*11) = 227272bps
Now the baud rate must be within an absolute 'worst case' of perhaps 4% of the required frequency to work. This value is about 1.3% out, and is therefore OK.
At twice the rate (460800), the closest possible with the 10MHz clock is a value of X = 5 or 6, giving rates of 500000, and 416666 respectively, which are 8.5%, and 10.5% in error respectively. The compiler knows that these are far to badly off frequency to be acceptable, and will therfore complain.
There are two solutions.
1) Chose baud rates that are generatable from the crystal selected. With a 10MHz crystal, you can actually select 2.5Mbps. With a 40MHz crystal, you can select 10Mbps. This will be fine, if the unit at the other end supports accurate generation of these odd rates.
2) Choose a crystal, that is a binary multiple of the standard baud rates. This is what was historically done on the PC, and on most serial cards.
A crystal of 7.3728MHz, will allow 460800 tobe selected perfectly, and even four times this rate to be used (1.843200Mbps).
Seperately though, there is the issue of actually 'handling' the data. If you are going to receive serial data (and do anything much with it), I'd say that in general, you need at least 100 instruction times for each byte, for the PIC to be able to 'cope'. At the *4 oscillator rate of 29.5MHz, this gives a mximum serial rate that is likely to be practical, of only perhaps 80Kbps...
Just sending the data can go much faster, but receiving characters, storing or reading them, needs much faster handling.
The PC, even with a 1GHz+ processor, needs serial ports using in some cases 1000 character hardware buffers, and will still be unable to handle characters without loss over a couple of hundred thousand bps, without flow control, and carefully written code.
Beware....
Best Wishes |
|
|
Charles Guest
|
|
Posted: Wed May 17, 2006 6:31 pm |
|
|
PCM Programmer:
Concerning the UARTs I don't know what it means. I don't specify anything concerning them. I saw in the rs485.c code concerning UARTs in cases where the INT_RAD interrupts are used, since I am using INT_EXT I didn't specify anything.
I'll have a look into it to know more about it.
May it be a reason why when I set the frequency to 40Mhz on both master and slave the communication doesn't work anymore (even the serial between the computer and the master)?
Charles. |
|
|
Ttelmah Guest
|
|
Posted: Thu May 18, 2006 2:04 am |
|
|
You realise that you have to do two changes to alter the frequency?. The clock source itself (chosing the *4 prescaler for a crystal), and the '#use delay' statement. Also, your source can only be either a crystal at 10MHz, with the prescaler, or an external oscillator at 40MHz (the chip does not support a 40MHz crystal directly).
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
|