Cordic trig assembly code for PIC18f


Closed Thread
Results 1 to 40 of 55

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Oh! It wasn't as hard as I thought it would be.

    And yup, it's trying to pull the parameters off the stack, and would be overwriting the variables with random values from RAM.
    I assume you've set those variables before calling the routine.

    Commenting these should help...
    Code:
      ; Set up the stack
    ;  movff FSR2L, POSTINC1
    ;  movff FSR1L, FSR2L
    
    
      ; Initialize _ang to passed parameter
    ;  movlw 0xfd
    ;  movff PLUSW2, _ang
    ;  movlw 0xfe
    ;  movff PLUSW2, _ang+1<hr>; Calculates the magnitude and direction of the given ordered pair
    atan2_sqrt:
    
      ; Set up the stack
    ;  movff FSR2L, POSTINC1
    ;  movff FSR1L, FSR2L
    
      ; Initialize _x to passed parameter
    ;  movlw 0xfb
    ;  movff PLUSW2, _x
    ;  movlw 0xfc
    ;  movff PLUSW2, _x+1
    ;  movff POSTINC2, _x
    ;  movff POSTDEC2, _x+1
    
      ; Initialize _y to passed parameter
    ;  movlw 0xfd
    ;  movff PLUSW2, _y
    ;  movlw 0xfe
    ;  movff PLUSW2, _y+1
    ;  movlw 0x03
    ;  movff PLUSW2, _y+1
    ;  movlw 0x02
    ;  movff PLUSW2, _y
    ADDED: OOPs, missed a couple ...
    Code:
      ; Restore the stack to its previous state
    ;  movf POSTDEC1
    ;  movff INDF1, FSR2L
    and there's another banksel atans in the as_loop_start: part.
    Last edited by Darrel Taylor; - 9th February 2009 at 10:48. Reason: Missed some
    DT

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


    Did you find this post helpful? Yes | No

    Default

    And then there's another problem. Or actually the same problem.

    Those banksel atans ...

    Somehow in C, the atans table that's in Flash by the DW statements, gets copied to RAM. Then it uses FSR0 to read the array. But it's strange that it uses the same label.

    I think you'll have to create a WORD array in PBP and load it with the values from the atans data.
    Either read the data or just have a few atans(0) = xxxx statements.

    If the array's in BANK0 then you still won't need the banksel statements.

    Mañana
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for all your work on this Darrel. I used all your suggestions, and the hypotenuse seems to work, but the angle and sin, cos do not. It seems to be doing something fishy because it is taking a few seconds to give me a result. Here is what I have done. If there are no glaring errors, perhaps I should try converting the cordic code that worked for the PIC16 to PIC18 code? This sounds like a very complex issue with the way the PIC18 is handling the addresses, so I very much appreciate the time you have spent on it.

    Code:
    define OSC 20
    
    include "TRIG.inc"
    
    main:
    define       LED     PortD.3
    
    'LCD defines taken out so that this code would fit in limited size 
    
    ADCON1=15
    
    TRISA=%00000011                         ' Set PORTA  
    TRISB=%00000000                         ' Set PortB
    TRISC=%00000000  
    TRISD=%00000100  
    '       Vdd     5 volts
    '       Vss     Ground
    '       Vo      20K potentiometer (or ground)
    '       DB0-3   No connect
    
    ang=5461
    x=0
    y=0
    
    asm
        call sin_cos
    endasm
        
    Lcdout $fe, 1   ' Clear LCD screen
    'toggle portd.3
            Pause 500       ' Wait for LCD to startup
    lcdout $FE,1,#x,",",#y
    lcdout $FE,$C0,#ang
    
    end
    
    'trig.inc here_________________________________________________
    i       var byte     BANK0
    j       Var byte     BANK0
    quad    var byte     BANK0
    x       var word     bank0
    y       var word     bank0
    ang     var word     bank0
    dy      var word     bank0
    dx      var word     bank0
    atans   var word[14] 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 main
    
    asm
        ;IDATA
    
    ; Table of arctan values
    
    ;atans   DW D'16384', D'9672', D'5110', D'2594', D'1302', D'652', D'326', D'163'
    ;        DW D'81', D'41', D'20', D'10', D'5', D'3', D'1'
    
        ;CODE
    
    ; Calculates the sine and cosine of the given angle
    sin_cos:
    
      ; Set up the stack
      ;movff FSR2L, POSTINC1
      ;movff FSR1L, FSR2L
    
      ; Initialize _x to 18218
      movlw 0x2a
      movwf _x
      movlw 0x47
      movwf _x+1
    
      ; Initialize _y to 0
      clrf _y
      clrf _y+1
    
      ; Initialize _ang to passed parameter
      ;movlw 0xfd
      ;movff PLUSW2, _ang
      ;movlw 0xfe
      ;movff PLUSW2, _ang+1
    
      ; Initialize _quad to 0
      clrf _quad
    
      ; Check if the angle is greater than 16383 (90°)
    sc_check_greaterthan:
      btfss _ang+1, 7
      btfss _ang+1, 6
      bra sc_check_lessthan
      bra sc_adjust_quad2
      
      ; Check if the angle is less than -16384 (-90°)
    sc_check_lessthan:
      btfsc _ang+1, 7
      btfsc _ang+1, 6
      bra sc_setup_end
    
      ; If the angle is in quadrant 3, adjust it to quadrant 4
    sc_adjust_quad3:
      negf _ang
      bc sc_negate_quad3
      comf _ang+1
      bra sc_adjust_end
    
      ; If the low byte negation causes a carry, negate the upper byte
    sc_negate_quad3:
      negf _ang+1
      bra sc_adjust_end
    
      ; If the angle is in quadrant 2, adjust it to quadrant 1
    sc_adjust_quad2:
      comf _ang
      comf _ang+1
    
      ; Toggle the sign bit and set the '_quad' flag
    sc_adjust_end:
      btg _ang+1, 7
      setf _quad
    
      ; Multiply the angle by 2 to get better resolution
    sc_setup_end:
      bcf STATUS, 0
      rlcf _ang
      rlcf _ang+1
    
      ; Set up the main loop
    sc_loop_start:
      clrf _i
      ;CHK?RP _atans    ;was banksel _atans
      lfsr FSR0, _atans
    
        ; The main loop label
    sc_loop:
        movff _x, _dy
        movff _x+1, _dy+1
        movff _i, _j
        movf _j
        bz sc_bs_x_done
    
          ; Loop to shift _dy right
    sc_bs_x_loop:
          bcf STATUS, 0
          rrcf _dy+1
          rrcf _dy
          btfsc _x+1, 7
          bsf _dy+1, 7
          decfsz _j
          bra sc_bs_x_loop
    
        ; Calculate what needs to be added to _x
    sc_bs_x_done:
        movff _y, _dx
        movff _y+1, _dx+1
        movff _i, _j
        movf _j
        bz sc_do_rotation
    
          ; Loop to shift _dx right
    sc_bs_y_loop:
          bcf STATUS, 0
          rrcf _dx+1
          rrcf _dx
          btfsc _y+1, 7
          bsf _dx+1, 7
          decfsz _j
          bra sc_bs_y_loop
    
        ; Perform adding operations on _x, _y and _ang
    sc_do_rotation:
        btfss _ang+1, 7
        bra sc_sub_angle
    
        ; If _ang is negative
        movf POSTINC0, W
        addwf _ang
        movf POSTINC0, W
        addwfc _ang+1
        movf _dx, W
        addwf _x
        movf _dx+1, W
        addwfc _x+1
        movf _dy, W
        subwf _y
        movf _dy+1, W
        subwfb _y+1
        bra sc_loop_bottom
    
        ; If _ang is positive
    sc_sub_angle:
        movf POSTINC0, W
        subwf _ang
        movf POSTINC0, W
        subwfb _ang+1
        movf _dx, W
        subwf _x
        movf _dx+1, W
        subwfb _x+1
        movf _dy, W
        addwf _y
        movf _dy+1, W
        addwfc _y+1
    
        ; Increment the counter and exit the loop if done
    sc_loop_bottom:
        incf _i
        movlw 0x0f
        cpfseq _i
        bra sc_loop
    
      ; Negate _x if it was initially in quadrant 2 or 3
    sc_finished:
      btfss _quad, 7
      bra sc_output
      negf _x
      bc sc_negate_x
      comf _x+1
      bra sc_output
    
      ; If the low byte negation causes a carry, negate the upper byte
    sc_negate_x:
      negf _x+1
    
      ; Output the calculated _x and _y values
    sc_output:
      ;movff _y, AARGB3
      ;movff _y+1, AARGB3+1
      ;movff _x, AARGB3+2
      ;movff _x+1, AARGB3+3
    
      ; Restore the stack to its previous state
      ;movf POSTDEC1
      ;movff INDF1, FSR2L
    
      return
    
    
    ; Calculates the magnitude and direction of the given ordered pair
    atan2_sqrt:
    
      ; Set up the stack
      ;movff FSR2L, POSTINC1
      ;movff FSR1L, FSR2L
    
      ; Initialize _x to passed parameter
      ;movlw 0xfb
      ;movff PLUSW2, _x
      ;movlw 0xfc
      ;movff PLUSW2, _x+1
    ;  movff POSTINC2, _x
    ;  movff POSTDEC2, _x+1
    
      ; Initialize _y to passed parameter
      ;movlw 0xfd
      ;movff PLUSW2, _y
      ;movlw 0xfe
      ;movff PLUSW2, _y+1
    ;  movlw 0x03
    ;  movff PLUSW2, _y+1
    ;  movlw 0x02
    ;  movff PLUSW2, _y
    
      ; Initialize _ang to 0
      clrf _ang
      clrf _ang+1
    
      ; Initialize _quad to 0
      clrf _quad
    
      ; If the point is in quadrant 2 or 3, make _x positive and set flag
    as_check_negative:
      btfss _x+1, 7
      bra as_shift_x
      setf _quad
      negf _x
      bc as_negate_x
      comf _x+1
      bra as_shift_x
    
      ; If the low byte negation causes a carry, negate the upper byte
    as_negate_x:
      negf _x+1
    
      ; Divide the _x coordinate by 2 to prevent overflowing
    as_shift_x:
      bcf STATUS, 0
      rrcf _x+1
      rrcf _x
    
      ; Divide the _y coordinate by 2 to prevent overflowing
    as_shift_y:
      bcf STATUS, 0
      rrcf _y+1
      rrcf _y
      btfsc _y+1, 6
      bsf _y+1, 7
    
      ; Set up the main loop
    as_loop_start:
      clrf _i
      ;CHK?RP _atans    ;was banksel _atans
      lfsr FSR0, _atans
    
        ; The main loop label
    as_loop:
        movff _x, _dy
        movff _x+1, _dy+1
        movff _i, _j
        movf _j
        bz as_bs_x_done
    
          ; Loop to shift _dy right
    as_bs_x_loop:
          bcf STATUS, 0
          rrcf _dy+1
          rrcf _dy
          btfsc _x+1, 7
          bsf _dy+1, 7
          decfsz _j
          bra as_bs_x_loop
    
        ; Calculate what needs to be added to _x
    as_bs_x_done:
        movff _y, _dx
        movff _y+1, _dx+1
        movff _i, _j
        movf _j
        bz as_do_rotation
    
          ; Loop to shift _dx right
    as_bs_y_loop:
          bcf STATUS, 0
          rrcf _dx+1
          rrcf _dx
          btfsc _y+1, 7
          bsf _dx+1, 7
          decfsz _j
          bra as_bs_y_loop
    
        ; Perform adding operations on _x, _y and _ang, shifting the _atans right one
    as_do_rotation:
        movff POSTINC0, PRODL
        movff POSTINC0, PRODH
        bcf STATUS, 0
        rrcf PRODH
        rrcf PRODL
        btfsc  _y+1, 7
        bra as_sub_angle
    
        ; If _y is positive
        movf PRODL, W
        addwf _ang
        movf PRODH, W
        addwfc _ang+1
        movf _dx, W
        addwf _x
        movf _dx+1, W
        addwfc _x+1
        movf _dy, W
        subwf _y
        movf _dy+1, W
        subwfb _y+1
        bra as_loop_bottom
    
        ; If _y is negative
    as_sub_angle:
        movf PRODL, W
        subwf _ang
        movf PRODH, W
        subwfb _ang+1
        movf _dx, W
        subwf _x
        movf _dx+1, W
        subwfb _x+1
        movf _dy, W
        addwf _y
        movf _dy+1, W
        addwfc _y+1
    
        ; Increment the counter and exit the loop if done
    as_loop_bottom:
        incf _i
        movlw 0x0e
        cpfseq _i
        bra as_loop
    
      ; Multiply the _x value by 19898 and divide by 2^14 to scale it
    as_scale_x:
      movff _x, _dx
      movff _x+1, _dx+1
      movlw 0xba
      mulwf _dx
      movff PRODH, _x
      movlw 0x4d
      mulwf _dx+1
      movff PRODH, _dy
      movff PRODL, _x+1
      movlw 0xba
      mulwf _dx+1
      movf PRODL, W
      addwf _x, F
      movf PRODH, W
      addwfc _x+1, F
      clrf WREG
      addwfc _dy, F
      movlw 0x4d
      mulwf _dx
      movf PRODL, W
      addwf _x, F
      movf PRODH, W
      addwfc _x+1, F
      clrf WREG
      addwfc _dy, F
      movlw 0x06
      movwf _j
    as_scale_bs_loop:
        bcf STATUS, 0
        rrcf _dy
        rrcf _x+1
        rrcf _x
        decfsz _j
        bra as_scale_bs_loop
    
      ; Check if the quadrant was originally changed
    as_check_quad:
      btfss _quad, 7
      bra as_output
      btfss _ang+1,7
      bra as_adjust_quad1
    
      ; If the angle is in quadrant 4, adjust it to quadrant 3
    as_adjust_quad4:
      negf _ang
      bc as_negate_quad4
      comf _ang+1
      bra as_adjust_end
    
      ; If the low byte negation causes a carry, negate the upper byte
    as_negate_quad4:
      negf _ang+1
      bra as_adjust_end
    
      ; If the angle is in quadrant 1, adjust it to quadrant 2
    as_adjust_quad1:
      comf _ang
      comf _ang+1
    
      ; Toggle the sign bit
    as_adjust_end:
      btg _ang+1, 7
    
      ; Output the calculated angle and hypotenuse values
    as_output:
      ;movff _ang, AARGB3
      ;movff _ang+1, AARGB3+1
      ;movff _x, AARGB3+2
      ;movff _x+1, AARGB3+3
    
      ; Restore the stack to its previous state
      ;movf POSTDEC1
      ;movff INDF1, FSR2L
    
      return
    
    endasm
    Last edited by ScaleRobotics; - 10th February 2009 at 17:36.

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


    Did you find this post helpful? Yes | No

    Default

    There are 15 elements in the array (0-14).

    Might be overwriting another variable.
    <br>
    Last edited by Darrel Taylor; - 10th February 2009 at 18:15. Reason: .
    DT

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


    Did you find this post helpful? Yes | No

    Talking

    Once again you saved the day!

    IT WORKS! I will clean it up a little bit and repost, so others may enjoy it. Looks to be about the same speed as the original author posted. Around 9,000 times per second on a 48mhz chip.
    Last edited by ScaleRobotics; - 10th February 2009 at 19:00.

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


    Did you find this post helpful? Yes | No

    Default

    IT WORKS!
    SWEET!

    You make it easy Walter.

    I know you just got it working, so you probably don't know this yet ...
    I'm curious about the accuracy.

    If I remember correctly, the last version could calculate a bearing within ~200 miles.

    What's the new resolution?
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Resolution is pretty good!

    180 degrees is covered by 0 to 32,767.

    So thats .00549 degrees per unit. Now I have not tested the total error, but I have seen it vary from expected by .015 degrees or so, but that is pretty close!

    Sin and cos return between -30,000 and +30,000 for -1 and 1. One of the cool things about the cordic, is that it returns cos AND sin at the same time. I have heard that it is 90 times faster than math.h.

    Also, this allows atan2 for a point x, y and accepts values from 0 to 32,767, and gives the hypotenuse to x,y which for me is the distance. It also gets these values at the same time!

    This way my distance values should be spot on. I am still limited to about 200 miles between waypoints, the way I am measuring the change in x, and the change in y. But I could do a divide function to break the units into something it could handle. I just have not needed to do this for my application.

    What I was using it for was navigation between waypoints. The first cordic for PIC16 did a pretty good job. It was accurate for bearing by about half a degree or so. My distance calculations did a simple square and square root that gave me errors on the hypotenuse. For long distances, I got pretty reliable results, less than 1 percent off of predicted results, but close range I could be off by a lot more. I could have cleaned this up with some higher math, but I was running out of speed trying to read two NMEA sentences, convert to decimal degrees for lat/lon, and fly a model plane, at 5 hertz gps readings. I gave up one sentence, and all is working well with the PIC16. This will allow me to break into the PIC18 world, and I am sure it will handle both NMEA sentences, plus a few more things. Nice!
    Last edited by ScaleRobotics; - 11th February 2009 at 05:48.

  8. #8
    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

    Thanks Martin,

    That works! But there is a little less math in post 49. It makes the rest of the cordic do what its supposed to for the rest of the quadrants. Thanks for pointing it out.

    Here is TRIG.inc V1.5
    Attached Files Attached Files
    http://www.scalerobotics.com

  9. #9
    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

  10. #10
    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:

  11. #11
    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

    I think I found my error in sincos. I had 36000 where 27000 now is. This did not compensate for the 90 degree shift for radians. Let me know if this works better.

    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 = 27000 - (36000 - ang)   'change degrees to radians
        ang = ang * 466
        ang = div32 256
        
        asm
            call sin_cos
        endasm
    return
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default Re: Cordic trig assembly code for PIC18f

    This is getting closer. The magnitude and sign values for the sin(ang) are all good. The magnitude term for the cos(ang) is good except the sign ,msb is incorrect for quadrants 2,3 and 4. Here is a list of what I get FOR ang = 0 to 350 STEP 1000 ;



    ang = 0 sin(ang) = 5 cos(ang) = 30000
    ang = 1000 sin(ang) = 5209 cos(ang) = 29544
    ang = 2000 sin(ang) = 10266 cos(ang) = 28188
    ang = 3000 sin(ang) = 15004 cos(ang) = 25981
    ang = 4000 sin(ang) = 19287 cos(ang) = 22981
    ang = 5000 sin(ang) = 22983 cos(ang) = 19285
    ang = 6000 sin(ang) = 25983 cos(ang) = 14998
    ang = 7000 sin(ang) = 28188 cos(ang) = 10264
    ang = 8000 sin(ang) = 29544 cos(ang) = 5207
    ang = 9000 sin(ang) = 30000 cos(ang) = 3
    ang = 10000 sin(ang) = 29544 cos(ang) = 5207
    ang = 11000 sin(ang) = 28188 cos(ang) = 10264
    ang = 12000 sin(ang) = 25983 cos(ang) = 14998
    ang = 13000 sin(ang) = 22983 cos(ang) = 19285
    ang = 14000 sin(ang) = 19287 cos(ang) = 22981
    ang = 15000 sin(ang) = 15004 cos(ang) = 25981
    ang = 16000 sin(ang) = 10266 cos(ang) = 28188
    ang = 17000 sin(ang) = 5209 cos(ang) = 29544
    ang = 18000 sin(ang) = 5 cos(ang) = 30000
    ang = 19000 sin(ang) = -5207 cos(ang) = 29544
    ang = 20000 sin(ang) = -10260 cos(ang) = 28190
    ang = 21000 sin(ang) = -14998 cos(ang) = 25983
    ang = 22000 sin(ang) = -19283 cos(ang) = 22985
    ang = 23000 sin(ang) = -22981 cos(ang) = 19287
    ang = 24000 sin(ang) = -25981 cos(ang) = 15004
    ang = 25000 sin(ang) = -28188 cos(ang) = 10266
    ang = 26000 sin(ang) = -29544 cos(ang) = 5213
    ang = 27000 sin(ang) = -30000 cos(ang) = 5
    ang = 28000 sin(ang) = -29549 cos(ang) = -5195
    ang = 29000 sin(ang) = -28199 cos(ang) = -10258
    ang = 30000 sin(ang) = -25986 cos(ang) = -14992
    ang = 31000 sin(ang) = -22987 cos(ang) = -19275
    ang = 32000 sin(ang) = -19296 cos(ang) = -22976
    ang = 33000 sin(ang) = -15013 cos(ang) = -25977
    ang = 34000 sin(ang) = -10271 cos(ang) = -28184
    ang = 35000 sin(ang) = -5216 cos(ang) = -29544


    - Martin

  13. #13
    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

    Thanks Martin,

    I'll take a look at it tonight. It should be easy enough to switch them around. With the pic16 solution, you have to work in quadrants. So that's probably where my error is.
    http://www.scalerobotics.com

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, 22:31
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  4. 4 Chanel Dmx512 ready assembly code to PBP ?
    By syscoder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd March 2007, 00:55
  5. Your Suggestions: Assembly code material?
    By dw_picbasic in forum General
    Replies: 1
    Last Post: - 2nd February 2007, 18: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