View previous topic :: View next topic |
Author |
Message |
sjharris
Joined: 11 May 2006 Posts: 78
|
Software Serial Port - max speed |
Posted: Wed May 14, 2008 4:48 am |
|
|
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
|
|
Posted: Wed May 14, 2008 5:53 am |
|
|
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
|
|
Posted: Wed May 14, 2008 7:00 am |
|
|
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
|
|
Posted: Wed May 14, 2008 7:45 am |
|
|
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
|
|
Posted: Wed May 14, 2008 7:53 am |
|
|
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 |
|
|
sjharris
Joined: 11 May 2006 Posts: 78
|
|
Posted: Wed May 14, 2008 7:56 am |
|
|
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
|
|
Posted: Wed May 14, 2008 12:54 pm |
|
|
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
|
|
Posted: Wed May 14, 2008 2:17 pm |
|
|
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
|
|
Posted: Thu May 15, 2008 3:06 am |
|
|
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
|
|
Posted: Thu May 15, 2008 4:19 am |
|
|
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
|
|
Posted: Thu May 15, 2008 5:44 am |
|
|
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
|
|
Posted: Thu May 15, 2008 8:43 am |
|
|
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 |
|
|
|