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

Is it possible to set non integer bit rate?

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



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

Is it possible to set non integer bit rate?
PostPosted: Mon Dec 17, 2012 4:22 am     Reply with quote

Is it possible to set non integer bit rate on H/W UART, for ex., 7812.5?
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon Dec 17, 2012 5:36 am     Reply with quote

The PIC hardware supports it. I don't know if the CCS support routines, such as #use rs232 does, but I think it probably wont as they seem to want an integer baudrate. Even so it is not easy to precisely set most commonly used baudrates unless your crystal is one of frequencies intended for baudrate generation, such as 14.7456MHz. Put another way, when you use a "normal" clock frequency like 8MHz, you cant get 9600 baud: the closest is 9615baud, which is close enough and works fine.

Why do you need 7812.5 baud? It just happens to be 8MHz/1024, which sounds suspiciously like someone else has had the same problem as its very easy to generate it from an 8MHz (probably internal...) clock.

RF Developer
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

PostPosted: Mon Dec 17, 2012 6:13 am     Reply with quote

This is baudrate of Chrysler CCD bus
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Dec 17, 2012 7:12 am     Reply with quote

What is the tolerance on the bit rate? If it is the usual N,8,1 serial format then 2% or 3% is fine. Even if you restrict it to 1% you can use any bit rate from 7734.4 to 7891.4 so the fractional bits are lost in the noise.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Dec 17, 2012 7:27 am     Reply with quote

There is a standard cheat for this.
Assume your CPU clock is (say) 16MHz. Then code as:
Code:

#use delay(clock=32M)
#use rs232(baud=15625, UART1, errors)
#use delay(clock=16M)

You'll find your delays are correct (use the second #use delay), but the UART setup, uses the first, delay, and correctly programs the hardware BRG, for 15625/2 baud.

However have to point out, that the hardware limitations, imply integer dividers only. This will give the correct rate with a 16MHz clock, but if (say) you tried with a 15Mhz clock, the rate will not be possible, and the compiler will give you the nearest 'miss', and not tell you unless this is dangerously in error (just under 3% as standard). Because of the hardware limitations, the compiler will give you exactly the same divisor, using the standard clock, for any rate from 7807bps, to 7818bps. So there is no point in worrying, choose a clock rate that gives this baud rate as the best figure round here (so, 8, 16, 32, or 64MHz), and just ask for 7812baud, and the value given will be what you want....

Best Wishes
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