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 CCS Technical Support

About "Baud rate out of range"

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



Joined: 12 Aug 2011
Posts: 4
Location: Taiwan

View user's profile Send private message

About "Baud rate out of range"
PostPosted: Mon Sep 26, 2011 4:28 am     Reply with quote

HI, everyone
I encountered a problem about setting the baud rate of rs232.
Code:
code:
#fuse EC
#device *=16 ADC=12
#use delay(clock=10Mhz)
#use I2C(SLAVE, SDA=PIN_G3, SCL=PIN_G2 ,address=0X40 ,I2C1 )
#use rs232(baud=115200, xmit=PIN_F5, rcv=PIN_F4, bits=8, parity=N, stream=PC2)
#use rs232(baud=115200, xmit=PIN_F3, rcv=PIN_F2, bits=8, parity=N, stream=PC) 

I use the configuration of external clock 10Mhz.
The compiler will show the message "Baud rate out of range "
But I use the configuration of FRC. It will OK.

Code:

#fuses FRC,NOPROTECT,NOWDT
#device *=16 ADC=12
#use delay(clock=7.37Mhz)

#use I2C(SLAVE, SDA=PIN_G3, SCL=PIN_G2 ,address=0X40 ,I2C1 )
#use rs232(baud=115200, xmit=PIN_F5, rcv=PIN_F4, bits=8, parity=N, stream=PC2)
#use rs232(baud=115200, xmit=PIN_F3, rcv=PIN_F2, bits=8, parity=N, stream=PC)

Could anyone tell me how to solve it.
I used dspic30f6010A.
Compiler version v4.12
THX
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 4:52 am     Reply with quote

I don't use that PIC but an option called FRC sounds like you're trying to use an internal Resistor-Capacitor module as the 'master oscillator', which has very tight limits of use.

Read the datasheet section that contains the oscillator information as well as the UART setup chapter.
There are several charts,diagram, text that will explain valid combinations of 'clock' vs. baudrates.

Your answer lies in there.
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 7:17 am     Reply with quote

The 'baud rate out of range' error, comes both when the baud rate is beyond the acceptable limits, but also when the baud rate that would be generated, has an error that is too large for reliable operation.

Now, look at equation 16-1 in the data sheet. Try solving with a 10MHz master clock, and 115200baud. Nearest BRG values are, 4 & 5, giving baud rates of:

= 10000000/(16*(4+1)) = 125000bps
and
= 10000000/(16*5+1)) = 104167bps

Errors of 8.5%, and 10.5% respectively!....

Maximum allowable error, is <5% maximum _total_ at both ends and CCS typically allows something like 3% at the PIC before complaining.

Do the same calculation with 7.37Mhz, and you get a BRG value of 3, giving:

= 7370000/(16*(3+1) = 115156bps

An error of less than 0.3%!....

The 115200 bps value, with a 10MHz clock is 'in range' (in the sense that the BRG, can generate clocks 'round' this), but out of acceptable tolerance, and this is what the compiler is telling you.

This is actually one reason for the odd sounding 7.37MHz clock value. It gives very good division ratios with standard baud rates.

A crystal like 9.216MHz, will give you nice accurate baud rates.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Sep 26, 2011 8:15 am     Reply with quote

I use 14.7456 mhz ext oscillators all the time for high baud rate requirements. Gives perfect baud divisors at any standard rate
and is a benefit when I need to cram in an extra software based RS-232
channel too.
mitice



Joined: 12 Aug 2011
Posts: 4
Location: Taiwan

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 9:08 am     Reply with quote

Ttelmah,
Thanks a lot for your answer. If I want this pic work under these condition:
UART baurd rate:115.2K & CAN BUS bit rate 500K.
What frequency of the master clock you recommend ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 9:46 am     Reply with quote

I think you will need to use 22MHz.
That gives perfect 500K Can bus timing, and on the UART, gives a BRG value of 11, giving just a 0.5% error (114583bps). Assuming you are running off 5v, and have the -30I version of the chip, this meets your needs. However if you need lower speed operation, you will need to think again. If you could accept 57600bps then 11MHz, would meet the timing requirements.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Sep 26, 2011 10:29 am     Reply with quote

this is - ironic - and crazy coincidence?

i have several thousand surplus SMT HC149 low profile crystals on reels from a discontinued product that was designed for both canbus and RS-232 baud generation.

the frequency i selected was 22.1184 MHZ - 18pf phaser caps
such that 115200 baud was 0% error and
canbus 500000 was .55% error

it was the best compromise at the time of that design and i have several thousand of these on reels that will probably have to be buried with me LOL ;-)) Razz
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