Cordic trig assembly code for PIC18f


Closed Thread
Results 1 to 40 of 55

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: Cordic trig assembly code for PIC18f

    Hmmm,

    Well, I can't test it from here, but this seems like it might work. (If not, I will think harder and do some testing). Thanks for the feedback Martin.

    Code:
    sincos:
        'use angle as deg.dd for example 35999 is 359.99 degrees
        if ang < 9001 then ang = 9000 - ang              'change degrees to radians
        if ang > 9000 then ang = 45000 - ang            'change degrees to crazy radians
        ang = ang * 466
        ang = div32 256
    
     asm
            call sin_cos
    endasm
    return
    http://www.scalerobotics.com

  2. #2
    Join Date
    Jul 2011
    Location
    Hawaii
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: Cordic trig assembly code for PIC18f

    Walter,

    I added three lines as shown in red. With the additions all 4 quadrants are returning correct magnitude and sign values.

    See attached test file.

    - Martin


    ;************************************************* *****************************/


    i var byte BANK0
    j Var byte BANK0
    quad var byte BANK0
    x var word bank0
    y var word bank0
    ang var word bank0
    ang_temp var word bank0
    dy var word bank0
    dx var word bank0
    atans var word[15] bank0


    atans(0) = 16384
    atans(1) = 9672
    atans(2) = 5110
    atans(3) = 2594
    atans(4) = 1302
    atans(5) = 652
    atans(6) = 326
    atans(7) = 163
    atans(8) = 81
    atans(9) = 41
    atans(10) = 20
    atans(11) = 10
    atans(12) = 5
    atans(13) = 3
    atans(14) = 1


    goto overcordic


    atan2:
    asm
    call atan2_sqrt
    endasm
    'convert to degrees.dd y is degrees
    If ang < 16384 then y = 16383 - ang
    if ang > 16383 then
    y = 65535 - ang
    y = y + 16383 'correct 90 degrees for radian
    endif
    y = y * 256 'divides radians to get degrees within 57ppm
    y = div32 466 'degrees.dd is y, radians is ang

    return


    sincos:
    'use angle as deg.dd for example 35999 is 359.99 degrees
    ang_temp = ang ' Store ang.
    if ang < 9001 then ang = 9000 - ang
    if ang > 9000 then ang = 27000 - (36000 - ang)
    ang = ang * 466
    ang = div32 256TRIG.basTrig_example.bas

    asm
    call sin_cos
    endasm
    if ang_temp > 9000 then y = ~y + 1 ' Perform 2's complement of y if ang > 90 for cos(ang).
    return


    asm


    ; Calculates the sine and cosine of the given angle
    sin_cos:

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. 4 Chanel Dmx512 ready assembly code to PBP ?
    By syscoder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 21st March 2007, 23:55
  5. Your Suggestions: Assembly code material?
    By dw_picbasic in forum General
    Replies: 1
    Last Post: - 2nd February 2007, 17:33

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