Shop OBEX P1 Docs P2 Docs Learn Events
atan of the cordicobject — Parallax Forums

atan of the cordicobject

LandryLandry Posts: 17
edited 2008-04-28 07:37 in Propeller 1
Hey,

I'trying to use the codicobject written by Gaham Stabler. However, I'm not really sure what value I should pass to the atan function of the object.

I have two pins that are getting values from two A/D converter, namely the sine and cosine, and I want to use these values to track my motor.

should I use the following code: after including and starting all the objects.

cordic.atan(convertToDec(ina[noparse][[/noparse]cosPin])/convertToDec(ina[noparse][[/noparse]sinPin]))


where I transform the value retrieved in cosPin and sinPin into decimal values

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-18 22:44
    Hi Landry, has anyone helped you with this, or did you figure out what is needed?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • LandryLandry Posts: 17
    edited 2008-04-21 07:37
    I haven't figure out how to use the object. I used an alternative which is the Floath32Full object.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-04-21 17:03
    There is discussion of the input arguments here, along with early versions of the code that Graham was developing.

    As you will see if you look back at that thread, the choice of number to represent unity or pi is somewhat arbitrary, and I am not sure what Graham chose in the end. But it will certainly be a binary signed integer, and not involve any conversion to decimal. ATAN2 will involve two integers, and the ratio will be calculated by the program. Where did you download the object you are using?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • LandryLandry Posts: 17
    edited 2008-04-22 07:36
    Thanks Tracy,

    The object that i'm using, i got it from the thread you are referring to in your post. I did read and re-read that thread as well as the example (Gaphics_cordic.spin).

    not really subject related, but I don't really think that it deserves a full threat.
    If I want to check the execution time of my spin code can I do the following:
    [color=purple]starttime := cnt 
    'code lines 
    'code lines 
    endtime := cnt[/color]
    

    ·If yes isn't this suppose to return the execution time each time.

    Post Edited (Landry) : 4/22/2008 7:46:22 AM GMT
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2008-04-22 08:39
    sorry I have been away for the past four days, I'll have a look this evening when I get home from work.

    Graham
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2008-04-24 21:21
    Sorry for taking so long to get back to this.

    Firstly doing a simple division in Spin will not provide you with the fraction required for the atan where 1 = $FFFF_FFFF

    So you should use the cordic.cart2polar function. This has two arguments, one is a pointer to the input arguments and another is a pointer to where you want the result to be placed.

    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    VAR
    
      long    R, theta ,x, y
    
    OBJ
    
      text     : "pc_text"
      cordic   : "cordicobject"
    
    PUB start | i
    
    '  start term
      text.start(12)
      cordic.start
    
      x := 100000
      y := 100000
    
      cordic.cart2polar(@x,@R)
    
      repeat
        text.dec(theta)
        text.out($0D)
        text.dec(R)    
        waitcnt(cnt+1000000)
        text.out(0)
    
    



    The variables are defined in the order, R, theta, x, y when using cart2polar x is supplied as the pointer to the input arguments and the values stored in x and y are loaded in to the function. When complete the answers are loaded in to R and theta.

    For the example above you get 141421 as the result for R and 536880225 for the angle, why because $FFFF_FFFF equates to 360 degrees and zero degrees. So 536880225 is actually 45 degrees (well 45.0007).

    Perhaps interger maths is not really what you want but I hope this clears up how to use the (still unfinished) object.

    Graham

    p.s. Notice my code uses PropTerminal so you don't need a display for TV outputs.
  • LandryLandry Posts: 17
    edited 2008-04-28 07:37
    Thnak you for your help.
Sign In or Register to comment.