rotate bytes in array


Results 1 to 19 of 19

Threaded View

  1. #10
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: rotate bytes in array

    Guys,
    May not be the solution for Art's project, but this post interested me because I was also stumped trying to shift bytes of data FIFO and ended up making something work for me.
    I liked the FOR/NEXT approach given here and thought I would try it since it looked faster and smaller since I'm really collecting 32 bytes instead of 12 in this example.

    My kludge: This scheme uses 24 words and takes 12.5us
    Code:
    DEFINE OSC 8
    
    RX      VAR BYTE        ' Buffer data
    XYZ_val VAR BYTE[12]    ' Accelerometer XYZ data
    TC_OUT  VAR PORTC.4     ' Test point to measure loop time
    
    Load_array:
    TC_OUT = 1
        XYZ_val[0] = XYZ_val[1]     ' Oldest data
        XYZ_val[1] = XYZ_val[2]
        XYZ_val[2] = XYZ_val[3]
        XYZ_val[3] = XYZ_val[4]
        XYZ_val[4] = XYZ_val[5]
        XYZ_val[5] = XYZ_val[6]
        XYZ_val[6] = XYZ_val[7]
        XYZ_val[7] = XYZ_val[8]
        XYZ_val[8] = XYZ_val[9]
        XYZ_val[9] = XYZ_val[10]
        XYZ_val[10] = XYZ_val[11]
        XYZ_val[11] = RX            ' Newest data
    TC_OUT = 0    
    RETURN
    Was surprised to to find that this scheme uses 43 words and takes 216us:
    Code:
    DEFINE OSC 8
    
    RX      VAR BYTE        ' Buffer data
    XYZ_val VAR BYTE[12]    ' Accelerometer XYZ data
    TC_OUT  VAR PORTC.4     ' Test point to measure loop time
    
    
    Load_array:
    TC_OUT = 1
        FOR z = 0 to 10
            XYZ_val[Z] = XYZ_val[Z+1]
        NEXT z
        XYZ_val[11] = RX
    TC_OUT = 0
       
    RETURN
    It meant more typing but saved some space and time.
    Last edited by LinkMTech; - 14th March 2012 at 17:22. Reason: Added note
    Louie

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