Usart Questions


Closed Thread
Results 1 to 6 of 6

Thread: Usart Questions

  1. #1
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79

    Default Usart Questions

    Hello
    Everyone

    A couple questions for ya. First of all which of these statements executes faster. Everyone says use hardware USART, but I'm not sure if it would always be as fast. Here is two sets of code which executes fastest and most efficiently out of them. Is one actually better than another.

    Number = 0
    WHILE Number < 3
    TXREG = Data[Number]
    Number = Number + 1
    WEND

    ''''''''''''''or'''''''''''''''''''

    HSEROUT [Data[0],Data[1],Data[2]]


    Next question, which is faster.

    Number = 0
    While Number < 3
    'Code in here converst all three array variables so that they will be display properly
    'whereas the HSEROUT statement bellow does it for you.
    wend

    Number = 0
    WHILE Number < 3
    TXREG = Data[Number]
    Number = Number + 1
    WEND

    ''''''''''''or''''''''''''''

    HSEROUT [Hex2 Data[0],Hex2 Data[1],Hex2 Data[2]]


    Final question, could someone give an example of when or why you would need to poll the TXIF: USART Transmit Interrupt Flag bit. Boring questions I know, but I am just trying to better understand the on board usart.

    Thanks for looking
    Shawn

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by shawn View Post
    Number = 0
    WHILE Number < 3
    TXREG = Data[Number]
    Number = Number + 1
    WEND

    ''''''''''''''or'''''''''''''''''''

    HSEROUT [Data[0],Data[1],Data[2]]
    The first example would execute much quicker.
    Unfortunately, it does so by not sending all 4 bytes like you might anticipate.

    When putting bytes in TXREG, you have to make sure that the USART is finished sending the last byte you put in it.

    Typically, you would check the TXIF bit to make sure it's safe to send, which the first example doesn't do, and the HSEROUT does automatically.


    Next question, which is faster.

    Number = 0
    While Number < 3
    'Code in here converst all three array variables so that they will be display properly
    'whereas the HSEROUT statement bellow does it for you.
    wend

    Number = 0
    WHILE Number < 3
    TXREG = Data[Number]
    Number = Number + 1
    WEND

    ''''''''''''or''''''''''''''

    HSEROUT [Hex2 Data[0],Hex2 Data[1],Hex2 Data[2]]
    Most likely, the HSEROUT will be faster.
    But there's no way of knowing, without the actual ..."Code in here converst all three array variables so that they will be display".

    Final question, could someone give an example of when or why you would need to poll the TXIF: USART Transmit Interrupt Flag bit.
    Because of the first answer.

    hth,
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Unless the compiler optimizes your code, any code written in a high level language is going to be slower than a single function or procedure call for that high level language. Something like the HSEROUT function is probably written in assembly. And as Darrel points out, there are other things HSEROUT is doing that your replacement code does not.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Something like the HSEROUT function is probably written in assembly
    Every single line of code in the PBP library is in assembly.

    any code written in a high level language is going to be slower than a single function or procedure call for that high level language
    OK. I'm a little slow. Could you explain this statement in laymans terms..;o}
    Last edited by Bruce; - 6th March 2008 at 21:20.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Basically, what I mean is if you write code in BASIC to perform a function it will generate more assembly code than the same function written in assembly. That is because typically there is overhead code generated by the BASIC routines that you can avoid when you write directly in assembly.

    So your example of controlling the UART with BASIC code will be more inefficient that the HSEROUT call because of all those extra assembly code lines that the BASIC procedures create.

  6. #6
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    Thanks for the answers guys

    Shawn

Similar Threads

  1. byte Tx w/ USART 16f876a problem
    By GargamelDigi in forum mel PIC BASIC
    Replies: 2
    Last Post: - 15th July 2008, 05:50
  2. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  3. I ammm Looosssst (USART Help)
    By shawn in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th May 2006, 05:05
  4. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07
  5. Replies: 5
    Last Post: - 1st December 2004, 12:49

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts