CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Baud rate tolerance??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

Baud rate tolerance??
PostPosted: Sun Dec 08, 2013 11:05 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 09, 2013 1:06 am     Reply with quote

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: 19360

View user's profile Send private message

PostPosted: Mon Dec 09, 2013 1:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 09, 2013 2:00 am     Reply with quote

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: 19360

View user's profile Send private message

PostPosted: Mon Dec 09, 2013 2:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 09, 2013 3:13 am     Reply with quote

I think I miscalculated the error's.

I was relying on past calculation made when I was using only 4MHz clock.

Thanks
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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