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

CCS (PCW C compiler IDE) baud error

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



Joined: 28 Sep 2009
Posts: 5

View user's profile Send private message

CCS (PCW C compiler IDE) baud error
PostPosted: Thu Oct 01, 2009 11:03 am     Reply with quote

Hey, I'm currently in a situation which I'm trying to solve. Currently I am using the PCW compiler version 4. Everytime I compile my program, it pops a baud rate out of range error. Whereas if I use the older version, PCW compiler version 3, it does not have this error.

This is the code:
Code:

use rs232 (baud=115200, xmit=PIN_C6, rcv=PIN_C7,ERRORS,STREAM=COM1)
#use rs232 (baud=115200, xmit=PIN_G1, rcv=PIN_G2,ERRORS,STREAM=COM2)
#use rs232 (baud=57600, xmit=PIN_E3, rcv=PIN_E4,ERRORS,STREAM=COM3)

The part where I am using baud 115200 there will be a baud rate out of range error. The microchip I am using is PIC18F8720 and the micro controller has a internal UART. I was reading the help content it says:

The compiler could not create code for the specified baud rate. If the internal UART is being used the combination of the clock and the UART capabilities could not get a baud rate within 3% of the requested value. If the built in UART is not being used then the clock will not permit the indicated baud rate. For fast baud rates, a faster clock will be required.

Anyone knows how to solve this problem? Would be greatly appreciated. Thanks in advance.

Regards,
Joel
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Oct 01, 2009 11:35 am     Reply with quote

This depends on what frequency your crystal is running at. Your #use delay() tells the compiler what frequency to use. If this frequency is not close enough to bring the baud rate within range then you will get this error.

What frequency is your crystal and is your #use delay() statement correct?

Ronald
xxjoelxx



Joined: 28 Sep 2009
Posts: 5

View user's profile Send private message

Freqency of crystal
PostPosted: Thu Oct 01, 2009 8:05 pm     Reply with quote

Thanks Ronald for the reply. My motherboard is using a M.Crystal 25 MHZ frequency.
In my program I did a "#use delay(clock=25000000)", which matches with the clock frequency I am using. Thus, the fault should not be there correct?

Joel
xxjoelxx



Joined: 28 Sep 2009
Posts: 5

View user's profile Send private message

PostPosted: Mon Oct 05, 2009 7:56 pm     Reply with quote

HEY people. Is there anyone who can help? Would be greatly appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 05, 2009 8:02 pm     Reply with quote

Quote:

Currently I am using the PCW compiler version 4.

Whereas if I use the older version, PCW compiler version 3,

Post the exact compiler versions that you used (both of them).
Then we can test it.
Ttelmah
Guest







PostPosted: Tue Oct 06, 2009 2:30 am     Reply with quote

As a general comment though:

Sync serial, requires the baud clocks at each end to be fairly close. Just how close, depends on a lot of factors (the sampling strategy used, the word length being used, etc. etc..). Historically, the older V3 compilers, allowed a fractionally bigger error in the clock actually being generated, from what was requested, than the V4 compilers allow. However the change is tiny, and if V4 complains, it is borderline on whether the clock will be reliable. The allowable error, is just under 4%, with a 3.1% error being accepted by both, but an early compiler accepting 4.2%, while the latter compilers complain by about 4%. The change was 'pre V4', with latter V3 compilers having similar limits to V4.
You can always 'cheat' to avoid the problem. If (for instance), you want to generate a 300Kbaud serial, witha 40MHz clock, you sit down and calculate the BRG yourself. So:

40MHz/300000 = 133.33333

With BRGH, the prescaler is 16, so you get 133.3333/16 = 8.33333

Nearest possible divider is 8 (7 in the BRG), giving division by 128 (8*16), and a baud rate of 312500. A 4.16% error, beyond the level that anyone would accept as 'sensible', and the compiler _will_ therefore reject the 300K rate. However if you were totally confident that the system will work OK with this error, all you need do, is set the baud rate in the #use RS232 statement, to the 312500 rate that the hadware can manage. The compiler wll then stop complaining, and accept the rate, and program this rate....

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 06, 2009 1:14 pm     Reply with quote

Download PicBaud. It will quickly show you the percent error in your
selected baud rates, for your given oscillator frequency.
http://www.ccsinfo.com/forum/viewtopic.php?t=37250&start=1
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