A Bit manipulation brain teaser for you :)


Results 1 to 14 of 14

Threaded View

  1. #8
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    Hi CagDask,
    Thanks for the post.
    I ended up using a combination of PBC and assembler.
    I put bit multipliers into eeprom and read them based on a bit test for each of the 15 bits. All values greater than 999 go into W2 and all above that into W3. I'm reading the serial data in at 57.6K also with an assembly routine and 20Mhz crystal.

    Here is one of the routines.( W2 collecting Mhz & Khz ) from byte 3. (the one that is has 65536 as its multiplier). I played around with simple division, but I kept loosing remainder values and with them resolution, so this seemed pretty easy. Its basic double precision addition in assembly, with each bit multiplier value being read from eeprom. W3 >= 1000 carrys into W2 and I'm getting really good resolution.

    Code:
     
    B0 = 0 'start of eeprom
    B15 = B12 'take copy of byte 3 into B15
    W2_B12:
    B1 = B0 + 1
    Read B0,B2
    Read B1,B3
    IF B2 = 0 AND B3 = 0 Then exit_W2_b12
     
    asm
        btfss    47,7 ;ram 47 = B15 ;if the bit is high add its multiplier
        GoTo    NO_W2_B12
        movf    34,w    ;ram 34 = B2 which now has LSB from eeprom
        addwf    36,f    ;add this value to ram 36 = W2.LSB
        btfsc    3,0    ;check status register carry bit
        incf    37,f    ;if carry occured, increment ram 37 which is W2.MSB
        movf    35,w    ;ram 35 = B3 which now has MSB from eeprom
        addwf    37,f    ;add MSB to W2
    NO_W2_B12
        rlf        47,f    ;rotate B15 left one bit
     
    ENDASM
    B0 = B0 + 2
    GoTo W2_B12
     
    exit_W2_b12:
    Last edited by ScaleRobotics; - 19th July 2010 at 00:16. Reason: added code tags

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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