+ Post New Thread
Results 1 to 12 of 12
  1. #1
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    AN1292 Application Note Microchip

    I am referring to the AN1292 application note source code. I have few questions in the fuction
    Code:
    OPENLOOP_RAMPSPEED_INCREASERATE = 10
    void CalculateParkAngle(void)
    {
         else if (Startup_Ramp < END_SPEED)
    			Startup_Ramp+=OPENLOOP_RAMPSPEED_INCREASERATE;
    
    ParkParm.qAngle += (int)(Startup_Ramp >> 10);
    
    }
    and the function
    Code:
    SinCos();
    I am bit confused of the above function. I have shown the calculations in the excel file. My main question is the output of the sincos function. Please help.

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 260,308, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,462
    Helped
    13829 / 13829
    Points
    260,308
    Level
    100

    Re: AN1292 Application Note Microchip

    SinCos() is updating ParkParm.qSin and ParkParm.qCos from ParkParm.qAngle. The code is in trig.s



  3. #3
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    Re: AN1292 Application Note Microchip

    Thank you very much for the reply. If you can tell me one conversion it will greatly help. First thing i am not very familiar with assembly language.
    As per my calculations
    Code:
    #define END_SPEED (END_SPEED_RPM * NOPOLESPAIRS * LOOPTIME_SEC * 65536 / 60.0)*1024
    END_SPEED_RPM 500
    NOPOLESPAIRS  5
    LOOPTIME_SEC  0.00005  (20kHz)
    
    END_SPEED = 139810
    I am taking the NOPOLEPAIRS as 5

    if Startup_Ramp = 0;
    then as per the code
    Code:
    ParkParm.qAngle += (int)(Startup_Ramp >> 10);
    ParkParm.qAngle = 0;
    then how to calculate to get the values of sin and cos in parkparm ParkParm.qSin=SincosParm.qSin; ParkParm.qCos=SincosParm.qCos; with example will help me after passing through the function
    Code:
    sincos();
    and when ParkParm.qAngle = 1; how the calculations will look like? So that i can try for all the other values.



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 260,308, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,462
    Helped
    13829 / 13829
    Points
    260,308
    Level
    100

    Re: AN1292 Application Note Microchip

    You don't need to understand the assembler code because you know the result, it's converting angle into sin and cos values. The scaling is specified in trig.s, so you can reproduce operation easily in Excel.



  5. #5
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    Re: AN1292 Application Note Microchip

    I have not understood the concept in the program. I think the program is using a sine look up table size of 128. I am trying in excel file , i am doing in open loop and as of now to understand the system i am not trying in closed loop. So my calculations are some thing like this
    Click image for larger version. 

Name:	cal1.JPG 
Views:	0 
Size:	18.7 KB 
ID:	155780
    So if you see the qAngle gets incremented and will go beyond the table index value of 128 or 360degrees. I really do not understand the conversion. Can you help me. So if i get a qangle of 1 does it mean i have to pick the element 1 of the sine table that is 1608.
    Code:
    SinTable: 
      .word 0,1608,3212,4808,6393,7962,9512,11039
      .word 12540,14010,15446,16846,18205,19520,20787,22005
      .word 23170,24279,25330,26319,27245,28106,28898,29621
      .word 30273,30852,31357,31785,32138,32413,32610,32728
      .word 32767,32728,32610,32413,32138,31785,31357,30852
      .word 30273,29621,28898,28106,27245,26319,25330,24279
      .word 23170,22005,20787,19520,18205,16846,15446,14010
      .word 12540,11039,9512,7962,6393,4808,3212,1608
      .word 0,-1608,-3212,-4808,-6393,-7962,-9512,-11039
      .word -12540,-14010,-15446,-16846,-18205,-19520,-20787,-22005
      .word -23170,-24279,-25330,-26319,-27245,-28106,-28898,-29621
      .word -30273,-30852,-31357,-31785,-32138,-32413,-32610,-32728
      .word -32767,-32728,-32610,-32413,-32138,-31785,-31357,-30852
      .word -30273,-29621,-28898,-28106,-27245,-26319,-25330,-24279
      .word -23170,-22005,-20787,-19520,-18205,-16846,-15446,-14010
      .word -12540,-11039,-9512,-7962,-6393,-4808,-3212,-1608



    •   AltAdvertisement

        
       

  6. #6
    Super Moderator
    Points: 260,308, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,462
    Helped
    13829 / 13829
    Points
    260,308
    Level
    100

    Re: AN1292 Application Note Microchip

    You apparently did not read the range specification. It says qAngle uses full 16 bit range. The size of the sine lookup table isn't related to qAngle range, the table is interpolated.

    In Excel, you'll calculate
    qSin = 2^15*sin(qAngle*2^-15/(2*pi()))


    1 members found this post helpful.

  7. #7
    Super Moderator
    Points: 77,915, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,796
    Helped
    3593 / 3593
    Points
    77,915
    Level
    68

    Re: AN1292 Application Note Microchip

    Hi,

    I see the valuse of your table are from -32768 ... 0 ...+32768
    But a signed _16_bit range is: -32768 ... 0 ... +32767

    Thus I recommend: qSin = (2^15 -1) * sin(Angle)

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.


    1 members found this post helpful.

  8. #8
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    Re: AN1292 Application Note Microchip

    Quote Originally Posted by KlausST View Post
    Hi,

    I see the valuse of your table are from -32768 ... 0 ...+32768
    Klaus
    I do not see +32768. I am doing any mistake? Please correct me.
    Code:
    SinTable: 
      .word 0,1608,3212,4808,6393,7962,9512,11039
      .word 12540,14010,15446,16846,18205,19520,20787,22005
      .word 23170,24279,25330,26319,27245,28106,28898,29621
      .word 30273,30852,31357,31785,32138,32413,32610,32728
      .word 32767,32728,32610,32413,32138,31785,31357,30852
      .word 30273,29621,28898,28106,27245,26319,25330,24279
      .word 23170,22005,20787,19520,18205,16846,15446,14010
      .word 12540,11039,9512,7962,6393,4808,3212,1608
      .word 0,-1608,-3212,-4808,-6393,-7962,-9512,-11039
      .word -12540,-14010,-15446,-16846,-18205,-19520,-20787,-22005
      .word -23170,-24279,-25330,-26319,-27245,-28106,-28898,-29621
      .word -30273,-30852,-31357,-31785,-32138,-32413,-32610,-32728
      .word -32767,-32728,-32610,-32413,-32138,-31785,-31357,-30852
      .word -30273,-29621,-28898,-28106,-27245,-26319,-25330,-24279
      .word -23170,-22005,-20787,-19520,-18205,-16846,-15446,-14010
      .word -12540,-11039,-9512,-7962,-6393,-4808,-3212,-1608



  9. #9
    Super Moderator
    Points: 77,915, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,796
    Helped
    3593 / 3593
    Points
    77,915
    Level
    68

    Re: AN1292 Application Note Microchip

    Hi,

    Sorry, my mistake, I read the values next to 32767 as 32768, but they are 32728.
    So the range seems to be correct.

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  10. #10
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    Re: AN1292 Application Note Microchip

    Sorry for dragging it but i will explain my understanding as per the code which includes the assembler code, hope you will correct it if any mistake.
    As per the code let us say ParkParm.qAngle = 1000. This corresponds to an actual angle of (1000/32767)*PI()= 0.0958; The sine look up table consists of 128 elements so each increment radian is 2*PI()/128 = 0.0490. The index in which the ParkParm.qAngle falls is 0.0958/0.0490 = 1.95 ~ 2. So as per the lookup table it should return 3211. This is what the trig.s should return am i correct? But as per the formula shared in the previous post does not match the calculations

    qSin = 2^15*sin(qAngle*2^-15/(2*pi())) the excel returns 159.1494603

    Ex:
    Step1: ParkParm.qAngle = 1000
    Step2: (1000/32767)*PI() = 0.0958 Actual angle in radian
    Step3: 2*PI()/128 = 0.0490 Increment angle
    Step4: Sine lookup table index = 0.0958/0.0490 ~2;
    Step5: Sine value = 3211 .
    Code:
    SinTable: 
    .word 0,1608,3212,4808,6393,7962,9512,11039
    Please help.



    •   AltAdvertisement

        
       

  11. #11
    Advanced Member level 3
    Points: 7,460, Level: 20
    Achievements:
    7 years registered

    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    997
    Helped
    383 / 383
    Points
    7,460
    Level
    20

    Re: AN1292 Application Note Microchip

    Edit:

    qSin(2) = (2^15-1) * sin((2 / 128) * 2 * pi) = 3211.727637 ~ 3212
    Last edited by std_match; 30th September 2019 at 14:17.



  12. #12
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    Re: AN1292 Application Note Microchip

    Finally i debugged and the data are matching with qAngle and qSin thank you all for the first step. Long way to go before i run the motor and need your support.Click image for larger version. 

Name:	Result.JPG 
Views:	2 
Size:	14.0 KB 
ID:	155804



--[[ ]]--