View previous topic :: View next topic |
Author |
Message |
aaea
Joined: 11 Jan 2010 Posts: 8
|
UART software versus hardware and Interrupts? |
Posted: Mon Oct 04, 2010 4:36 am |
|
|
Hi
I have two simple questions:
(a) Can a software UART transmit at 57.6kBaud using a 12MHz Xstal? and What is the fastest that the software UART can transmit with a 12MHz Xstal?
(b) If I have various interrupts, what will occur with the UART transmission?
Thank you in advance.
a. |
|
|
niktab
Joined: 20 Jul 2010 Posts: 2
|
|
Posted: Mon Oct 04, 2010 5:01 am |
|
|
i strongly recommend, do not use software uart simulation, especially if you use any interrupts. this probably will cause real mess. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Oct 04, 2010 5:28 am |
|
|
If you search the forum, you will find that some time ago, the 'instructions per bit' for the software UART was posted. I think 57600, is 'pushing it'. My memory was somewhere around 60 instructions 'worst case'. At 57600, on a processor at 3MIPS, you have 52 instructions per bit.
On interrupts, you _cannot_ have interrupts enabled while transmitting, especially at a rate like this (it takes more time than a single bit, to get into, and out of an interrupt handler, even 'doing nothing' in the handler). You can though use the 'DISABLE_INTS' option in the use RS232 declaration, so that they are disabled on a 'per character' basis, which will allow your interrupts to occur 'between' the characters (if you have an older compiler, you can instead encapsulate the transmission to do this).
Best Wishes |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Oct 04, 2010 8:26 am |
|
|
I agree. Software UARTs in a pinch only.
Hardware UARTs are good.
Interrupts are fabulous. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Oct 04, 2010 8:48 am |
|
|
Software UARTs are perfectly legitimate. They do take a lot of CPU time and a little ROM space. But for a project that has a specific "setup" or "download" phase when the CPU would be idle anyway, software UARTs allow you to use PICs that don't have hardware UARTs, or not enough UARTs.
Also software UARTs are sometimes a lifesaver for debug. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Oct 04, 2010 8:56 am |
|
|
I still only use them in a pinch.
So many PIC's come with HW UART's now...
what the decision making process comes down to this:
Will the PIC be busy enough where you can't afford to miss RS232 data and you can't afford to stop doing other things.
If the answer is yes, then hardware UARTs.
If the answer is no, then software is ok.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Oct 04, 2010 9:02 am |
|
|
Remember though that the original poster, was asking about transmit, not receive. So the comments about 'missing data', don't apply. Software UART's, used with care are fine for transmit. For receive, they are much more of a problem. Though 90% of PICs 'come with a UART'. if you have multiple serial streams involved, a software UART may be useful.
Best Wishes |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Oct 04, 2010 9:05 am |
|
|
Ttelmah wrote: | Remember though that the original poster, was asking about transmit, not receive. So the comments about 'missing data', don't apply. Software UART's, used with care are fine for transmit. For receive, they are much more of a problem. Though 90% of PICs 'come with a UART'. if you have multiple serial streams involved, a software UART may be useful.
|
I know, I just just describing how I usually decide the soft/hard UART question.
If TX is all he's doing.. then software might be fine. 'specially in a loop controlled environment. (no IRQ's.. just a main that does item 1, then 2, then 3 then repeat.)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|