Quickest way to do an If val1 = val2 with Word variables


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126

    Default Quickest way to do an If val1 = val2 with Word variables

    Hi There all,

    I am working on a program that has an interrupt routine that need to do a very fast "if val1 = val2 then", but it seems to be taking a long time for the if..then to evaluate. Based on my measurements it is taking 60uS.

    Yes I said 60uS ! This is a 16f1936 running at 32MHz. Problem is that I am in a serial interrupt routine where each character is only 36uS, so I need to see if I am at the chosen channel and if so to load it into a buffer.

    I have the buffer code and it works as is, but at higher refresh rates I am loosing data and it looks like I am overflowing the buffers in the uart.

    What I really want to know is taking hints from this thread : http://www.picbasic.co.uk/forum/showthread.php?t=12635
    is there an easier way to compare word1 to word 2 and to do something if they are equal ??

    Driving me mad !!

    bill

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


    Did you find this post helpful? Yes | No

    Default

    val1 VAR WORD
    val2 VAR WORD

    SLOW
    Code:
    IF val1 = val2 THEN SomeWhere
    FASTer
    Code:
    IF val1.HighByte = val2.HighByte THEN
        IF val1.LowByte = val2.LowByte THEN
            GOTO SomeWhere
        ENDIF
    ENDIF
    DT

  3. #3
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Nope - same time. 60uS.
    Think something weird might be going on here - might do some bare bones code.

    bill.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Bill

    could you provide the "Guilty" interrupt code ???

    easier to talk about real matter ...

    Alain

    PS: http://www.picbasic.co.uk/forum/show...3&postcount=13 ... obviously raises some questions !!!
    Last edited by Acetronics2; - 18th April 2010 at 13:20.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jun 2007
    Location
    Sydney, Australia
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Hi Bill,

    How about:

    if (A XORNOT B) then something

    XORNOT is a logical comparison testing for equality basically...

    Phil.
    Duck sensing headlights! Quack, quack, Bing!

  6. #6
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default

    Interesting thoughts.
    I think its time to do some bare bones code to see which works out to be quicker.

    Bill.

Members who have read this thread : 1

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