• AVR Freaks

Hot!pic18f sin cos function

Author
ft.ovah
Starting Member
  • Total Posts : 66
  • Reward points : 0
  • Joined: 2020/01/10 06:17:03
  • Location: 0
  • Status: offline
2020/01/29 03:16:04 (permalink)
0

pic18f sin cos function

Hey,
I have checked the AN660 reference manual for sin and cos function in assembly language for pic18f , but i really can't understand any of it.Also the code in AN660 is for pic16 family. I read a thread on the same topic using taylor series but i dont know what to make of it,even if i use it i'd still have to use a power function .I have to use these functions for motor control operations using Direct torque control method to convert Alpha beta coordinates to dq0 reference frame.Any help would be wonderful.
 
Regards,
 
#1

11 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28363
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pic18f sin cos function 2020/01/29 03:25:44 (permalink)
    5 (1)
    Back here: https://www.microchip.com/forums/m1125209.aspx
    you said you were going to program in C.
    That is by far the easiest way to do it.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    crosland
    Super Member
    • Total Posts : 2041
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 04:48:54 (permalink)
    0
    Have you looked at AN1061?
    #3
    ric
    Super Member
    • Total Posts : 28363
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pic18f sin cos function 2020/01/29 04:58:34 (permalink)
    5 (1)
    To be clear, if you are now looking for PIC18F code, why are you posting in the dsPIC30F forum?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    MBedder
    Circuit breaker
    • Total Posts : 6919
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 05:23:43 (permalink)
    5 (2)
    ricTo be clear, if you are now looking for PIC18F code, why are you posting in the dsPIC30F forum?
    Because he's an idiot.


    #5
    nigelwright7557
    Super Member
    • Total Posts : 471
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 05:58:15 (permalink)
    5 (1)
     I just created a table with 90 entries, one for each angle between 0 and 90.
    The rest of the angles can be worked out from the first 90.
     
    #6
    ft.ovah
    Starting Member
    • Total Posts : 66
    • Reward points : 0
    • Joined: 2020/01/10 06:17:03
    • Location: 0
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 08:38:22 (permalink)
    2 (1)
    Hey,
    Im sorry ric ,My main question was on dspic but I forgot the topic was changed since my main problem is figuring out the trig functions and yess I was talking about C for dspic ,for now I can only program in Assembly in pic18 and this is the first time Im actually using trigonometry. Mbedder Im have a feeling posting on forums is the best thing Ive ever done grin: grin.nigelwright7557 can you explain why 90 entries are enough to work my way around till 360?Im sorry for being a nube in this regard.
     
    Thankyou,
    post edited by Ow19m - 2020/01/29 08:44:40
    #7
    pcbbc
    Super Member
    • Total Posts : 1703
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 09:14:46 (permalink)
    5 (2)
    Ow19mnigelwright7557 can you explain why 90 entries are enough to work my way around till 360?
    I'm sorry for being a nube in this regard.

    If you have a table for sin(x) 0 through 90 then by inversion and reflection you can obtain the other quadrants:
    90 through 180 = sin (180 - x)
    180 through 270 = -sin (x - 180)
    270 through 360 = -sin (360 - x)
    Edit: and in case you haven't realised, cos is just sin offset by 90 degrees.  So you won't need a separate table for cos either.
    post edited by pcbbc - 2020/01/29 09:17:30
    #8
    1and0
    Access is Denied
    • Total Posts : 11132
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 09:15:51 (permalink)
    5 (2)
    Ow19m
    can you explain why 90 entries are enough to work my way around till 360?Im sorry for being a nube in this regard.

    I found it difficult for someone to use trig functions without understanding them. Anyway, for example:
     
    sin(90° < x < 180°) = sin(180° - x)
    sin(180° < x < 270°) = -sin(x - 180°)
    sin(270° < x < 360°) = -sin(360° - x)
    #9
    NKurzman
    A Guy on the Net
    • Total Posts : 18901
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 09:15:57 (permalink)
    5 (2)
    It is basic trig.
    look at a sine wave, the second 180 degrees is a mirror of the first (just a sign change).
    And compare 0-90 to 90 - 180
    And a sine to cosine conversion is 90 degrees
     
    #10
    1and0
    Access is Denied
    • Total Posts : 11132
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 09:25:59 (permalink)
    5 (2)
    ... and
     
    cos(x) = sin(90° - x)
    sin(x) = cos(90° - x)
     
    Edit: The trig functions in <math.h> work with radians instead of degrees, where pi radian = 180°.
    post edited by 1and0 - 2020/01/29 09:35:59
    #11
    crosland
    Super Member
    • Total Posts : 2041
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: pic18f sin cos function 2020/01/29 09:38:13 (permalink)
    5 (3)
    Ow19m
    can you explain why 90 entries are enough to work my way around till 360?



    Are you serious?
     
    And you want to  implement direct torque control?
     
    I think you have a lot to learn.
    #12
    Jump to:
    © 2020 APG vNext Commercial Version 4.5