Cordic trig assembly code for PIC18f


Results 1 to 40 of 55

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    Here are the changes I have made to the assembly code to try to get it to work with PicBasic:


    commented out EXTERN AARGB3, UDATA_ACS, IDATA, CODE, edited variable descriptions so that variables are declared in PicBasic.

    Original Code:
    Code:
      ; Import the address the compiler uses to store 32-bit return values
        EXTERN AARGB3
    
    
        UDATA_ACS
    
    ; Variable declarations
    i       RES 1
    j       RES 1
    quad    RES 1
    x       RES 2
    y       RES 2
    ang     RES 2
    dy      RES 2
    dx      RES 2
    
    
        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
    I edited out where the result is moved to AARGB3, and just use the word variables _x, _y, and _ang to store the results. Commented out Globals and End. And of course added ASM and ENDASM.

    My code:
    Code:
    i       var byte    
    j       Var byte
    quad    var byte
    x       var word
    y       var word
    ang     var word  
    dy      var word
    dx      var word
    
    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
    
    
    -snip
    
      ; 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
    
    -snip
    
      ; 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
        ; Export the functions to the linker
        'GLOBAL sin_cos
        'GLOBAL atan2_sqrt
    
        'END
    Please let me know if you have any suggestions. It does compile without errors, but I do not get useful data out. When I input 5461 as the angle, I get the sin=29998, and cos=405. The result should be 15000, and 25980. But then if I run it again, a different value pops up for cos, that still does not get close to expected values.

    Thanks,

    Walter
    Last edited by ScaleRobotics; - 8th February 2009 at 19:35. Reason: left things out, and forgot a [/code]

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