View previous topic :: View next topic |
Author |
Message |
hello188
Joined: 02 Jun 2010 Posts: 74
|
Baud rate tolerance?? |
Posted: Sun Dec 08, 2013 11:05 pm |
|
|
Hi, I am using PIC18F47J53 for USB application.
At the same time I want to implement Modbus RTU over the USART.
However, the nature of USB forbids me from using baud rate friendly X-tals.
Using 12MHz crystal to generate proper USB clock leaves me with about
2% error in baud rate for popular modbus baud rates.
1) how large of an error is tolerable?? I couldn't find the specification regarding date-rate error in the modbus specification.
2) Is receiving end of UART transmission synchronized on every start bit? so that the 2% error don't accumulate with successive bytes when sending large data?
Thank you in advance!!!! |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Dec 09, 2013 1:06 am |
|
|
2) Yes, the synchronization is restarted at every new received byte. That is the whole purpose of having a start bit.
1) Within the byte all errors do accumulate.
The allowed error tolerance depends on the method used by the receiver chips. Values will vary, but many use the same 16x oversampling as introduced in the old 16C550 UART.
With 16x sampling per bit time you have a resolution of 6.25%
You require at least halve a bit being received correct, that gives 6.25% / 2 = 3.125% error margin.
Note that this error margin is for both the sender and receiver combined. When sender is 2% too fast and receiver is 2% too slow, then you are out of specifications.
However, when both systems are, for example, 5% too fast then they are out of specifications, but the absolute difference between both is 0% and it'll work perfectly together. So, error margin is easier to manage when you control the design of both the transmitter and receiver.
The CCS compiler generates an error message when the selected baudrate can not be created within 3% error margin. This assumes the other side has 0% error.
Your 2% error margin should work with most devices, but there will be a few devices that fail if these have more than 1% error in the 'wrong' direction.
I don't know your project so you have to decide if this is acceptable.
For a perfect baud rate you will have to add an extra crystal to the PIC. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Mon Dec 09, 2013 1:56 am |
|
|
I assume you are talking about the default 19200bps?.
Modbus over serial line, _specifies_ that receivers must accept 2% error, and transmitters be better than 1%. Section 3.2 'Data signalling rates'.
However Using a 12MHz crystal, does not give you 2% error.
With a 12MHz crystal, you can opt to clock the CPU at 12Mhz, 6MHz, 4MHz, 48MHz, 24MHz, and a few other rates. At 48MHz, the Baud error is just -0.16%, and most other rates can be done just as well (including faster rates).
So what rate are you clocking the CPU, and what Modbus rates do you require?.
Best Wishes |
|
|
hello188
Joined: 02 Jun 2010 Posts: 74
|
|
Posted: Mon Dec 09, 2013 2:00 am |
|
|
Thanks. I think I can get by with 12MHz crystal PLL'ed 4x.
that will give me just about 1% error. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Mon Dec 09, 2013 2:23 am |
|
|
Just to explain what 'ckielstra' mentions 'add an extra crystal'. You can run the USB off the primary oscillator, and the CPU off the secondary.
However, for 19200bps, with 48MHz clock:
X=((48000000/19200)/64)-1
= 38
Baud=48000000/(64*39)
= 19230.8
Error = (19230.8-19200)/19200
= 0.001604
*100
0.1604%
Even if you go to 57600bps
X=12
Baud=57692.3
Error=0.16%
Are you sure you are doing the calculation right?. With the fast CPU clock it is normal to be able to get within a fraction of a percent for most rates.
Best Wishes |
|
|
hello188
Joined: 02 Jun 2010 Posts: 74
|
|
Posted: Mon Dec 09, 2013 3:13 am |
|
|
I think I miscalculated the error's.
I was relying on past calculation made when I was using only 4MHz clock.
Thanks |
|
|
|