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

Software Serial Port - max speed

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



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

Software Serial Port - max speed
PostPosted: Wed May 14, 2008 4:48 am     Reply with quote

Hello all,

Can anyone tell me where I can find information on the maximum BAUD rate for a software defined serial port used in CCS compiler.
I have defined a serial port use on pins 2 and 3 on 16f688 (A4 and A5 osc pins)
I am able to use the serial port up to 9600 but after that there is no communications at all from the port, I would like to use 19200 and I am using a 20 MHz internal clock configuration.

Thanks in advance
Steve
sohailkhanonline



Joined: 06 Mar 2008
Posts: 35
Location: pakistan

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Wed May 14, 2008 5:53 am     Reply with quote

check the data-sheet of your micro-controller because i think that 9600 is the maximum baud you can achieve using 20Mhz clock. There is a formulae for maximum baud rate dependent on frequency.
I think it does not make the difference to baud rate whether your port is software defined or hardware defined.
hope it answer your question.
_________________
sohail khan
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Wed May 14, 2008 7:00 am     Reply with quote

The hardware serial port is running at 19200 and the software is running at 9600, I should be able to reach 19200 on the software port if it is running 19200 on the hardware port??

(8 bit timer

FOsc
-------------------- - 1
Baud / timer size

20 000 000
------------- - 1 = 15
19200 / 64

Actual =
20 000 000
------------- = 19531
64 x (15 + 1)


Error =
(19531 - 19200)
------------------ = 0.017 %
19200

Error is well withinn boundary therefor 20 MHz will handle 19200 easily!!

Thanks
Steve
Ttelmah
Guest







PostPosted: Wed May 14, 2008 7:45 am     Reply with quote

Some time ago, I posted the number of instruction cycles 'round' the loop used by the software port. It is on the group somewhere. However 9600bps, is not even 'close' to the limit using a 20MHz clock. It would be somewhere up in the 100Kbaud area, rather than down at 9600bps...
Remember though, that you must generally, not have any interrupts running during the receive or transmit, when using the software 'port', and the effect of an interrupt, will get worse, the faster the baud rate.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed May 14, 2008 7:53 am     Reply with quote

Quote:
I think it does not make the difference to baud rate whether your port is software defined or hardware defined.
This is not true, there is no relation between the software UART and the internal hardware UART & baudrate generator.

The soft UART is a software implementation of a UART, it generates the output signal in a loop with delay routines. The CCS implementation of the soft UART is not very sophisticated, there is room for optimization. I have never done any speed measurements on the soft UART, but running at 20MHz transmitting at 19k2 should be no problem. Receiving requires a bit more CPU power but even then 19k2 shouldn't be a problem.

Is it possible you have an interrupt occurring during transmission? This will mess up the timing of the soft UART. A simple test is to add DISABLE_INTS to the #use rs232 line.

I should learn to type faster... Ttelmah beats me again Smile
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Wed May 14, 2008 7:56 am     Reply with quote

There is a possiblity of an interrupt ocurring, I will disable interrupts before this point and try that!!
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Wed May 14, 2008 12:54 pm     Reply with quote

One thing I can say is, it makes a very large difference if your software serial port has to be full duplex rather than half. If you don't need to transmit while you're receiving, you can easily achieve 19.2KB. If you need full duplex, then I'm doubtful if it can work.
Ttelmah
Guest







PostPosted: Wed May 14, 2008 2:17 pm     Reply with quote

The software serial port, is half duplex only. The code sending, or receiving, is the _only_ task that can be operating at the time. No reception is possible while sending, or vice versa.
Full duplex can be done, but requires a much more complex approach than that used by the CCS code.

Best Wishes
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Thu May 15, 2008 3:06 am     Reply with quote

The serial port is only either receiving OR transmitting, it is never doing both!!

I am trying to find out where the interrupts may be going off and if any are going of while the software serial port is communicating.

Could that be causing some problems with strings being 'Garbled' ??
i.e.

Instead of :
Checking Port

I get :
jkfcking Po8f
Ttelmah
Guest







PostPosted: Thu May 15, 2008 4:19 am     Reply with quote

Yes.
On reception, if an interrupt 'fires' during the receive, time will be used for the interrupt handler, which will result in the next bit being sampled 'late', by this amount. Provided the time is _less_ than half a bit time, reception may still be OK, but if it is more, the data _will_ be corrupted. This is why the problem is worse at higher baud rates, since if the interrupt takes (say) 30uSec, at 9600bps, this is 'only' just under 1/3rd a bit time. However at 19200, it reaches 60% of a bit time.
On transmission, the effect may be worse (depends on the sampling algorithm being used by the receive UART).
Have you tried with the DISABLE_INTS keyword in the UART setup?. Provided your code, doesn't mind the interrupts being delayed for at most one character time, this is the best way to handle this.

Best Wishes
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Thu May 15, 2008 5:44 am     Reply with quote

I will add the disable_ints in the uart setup, the program only uses the interrupts for sensing change on port a and input on hardware port, but they can be disabled while the software port is TX / RX 'ing.
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Thu May 15, 2008 8:43 am     Reply with quote

Adding the disable_int does not fix the problem.

I will try and add some code for ppl to look at, just as a quick question, do I need to enable any bits before I can transmit properly??

TIA

Steve
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