Count Bits, Choose High or Low?


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    IF DT's routine is too complicated for you, which usually is for me, then take a look at this one.
    This should be faster then yours I guess.

    Code:
    <font color="#000000">ErrorCheck:
        HighCount = <font color="#FF0000">0
        </font>LowCount  = <font color="#FF0000">8
        </font>i         = <font color="#FF0000">0
    
        </font><font color="#000080"><b>WHILE </b></font>i &lt; <font color="#FF0000">8
              </font>n = testByte.<font color="#FF0000">0</font>[i]          <font color="#000080"><i>'Read bit.
              </i></font>LowCount  = LowCount - n   <font color="#000080"><i>'sub. bits.
              </i></font>HighCount = HighCount + n  <font color="#000080"><i>'add bits.
              </i></font>i = i + <font color="#FF0000">1                  </font><font color="#000080"><i>'incr. bit.
        </i><b>WEND
    
    
        </b></font>testByte = <font color="#FF0000">$00                    </font><font color="#000080"><i>'Assign value.
        </i><b>IF </b></font>HighCount &gt;= LowCount <font color="#000080"><b>THEN </b></font>testByte = <font color="#FF0000">$FF  </font><font color="#000080"><i>'change value if true.
             
    </i><b>RETURN
    </b></font>
    Edit: I did not understand the logic behind this statement:
    "This will eliminate any bit errors as long as it's not more than 3 bit errors per byte."
    You may cut the loop off if this is true and reduce the time into half of what it takes.

    -------------------
    Last edited by sayzer; - 2nd January 2009 at 09:22.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Very much appreciated guys. That worked perfectly.

    Darrel's code wins though. Indeed, about 16uS. Sayzer's loop took about 112uS. An improvement but still not quite fast enough.

    If there was ever any question about the efficiency of assembly or the lack of efficiency of PBP, I guess we see it right here. lol.

    Anyway, that totally solves my problem - thank you both very much!

Similar Threads

  1. SERIN MIDI out of Synch?
    By jncortes in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th June 2009, 20:08
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 02:37
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

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