• AVR Freaks

Hot!AN2520 FLoating point calculations.

Author
microLearner
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
2019/09/14 07:08:25 (permalink)
0

AN2520 FLoating point calculations.

I am referring to the AN2520 application and using the MCLV-2 development board. I am referring to the source code for Clarke, Park transforms implemented in the mc_Lib.c file for example

void mcLib_ClarkeTransform(mcParam_ABC *abcParam, mcParam_AlphaBeta *alphabetaParam)
{
alphabetaParam->alpha = abcParam->a;
alphabetaParam->beta = (abcParam->a * ONE_BY_SQRT3) + (abcParam->b * 2 * ONE_BY_SQRT3);
}

I used the same code the execution time is very high what i measured from scope is
Clarke Transform -> 23.3uS
Park Transform -> 30uS. How to reduce the time. Any suggestions? Please advise.

Clarke Transform 23.3uS
#1

6 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3076
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: AN2520 FLoating point calculations. 2019/09/14 08:19:39 (permalink)
    5 (1)
    Floating point?
    WTF are you trying torun on a dsPIC?
    The above AN is for 32-Bitters with FPU support!
     
    Look for similar ANs for dsPICs (that usually work with fixed-point integer math).

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    microLearner
    Junior Member
    • Total Posts : 110
    • Reward points : 0
    • Joined: 2017/02/27 20:26:37
    • Location: 0
    • Status: offline
    Re: AN2520 FLoating point calculations. 2019/09/14 08:45:00 (permalink)
    0
    I am using the dspic33ep256mc506. I am not trying to run the AN2520 source code as it is, i am trying to take some  important subroutines. I have seen the application note AN1078 but most of the code is in assembly, i am not very comfortable. I will try to implement in fixed point Q15 format will see if i can do it. 
    #3
    du00000001
    Just Some Member
    • Total Posts : 3076
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: AN2520 FLoating point calculations. 2019/09/14 09:38:10 (permalink)
    5 (1)
    On the dsPICs, you'll need to use either some lib(s) written in assembly or write at least the time-critical math in assembly (as IIRC the compiler doesn't make use of the dsp extensions). With the help of the ANs this should be doable.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    microLearner
    Junior Member
    • Total Posts : 110
    • Reward points : 0
    • Joined: 2017/02/27 20:26:37
    • Location: 0
    • Status: offline
    Re: AN2520 FLoating point calculations. 2019/09/15 01:08:08 (permalink)
    0
    I have now able to compile the AN1292 and AN1078 application notes source codes and i measured the execution timings of the clarke and park transformations and they are very less in the range of 1uS. I will continue with this source code some of them are in assembly that is ok as of now. Will try to run the motor first in open loop and then in closed loop. 
    #5
    du00000001
    Just Some Member
    • Total Posts : 3076
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: AN2520 FLoating point calculations. 2019/09/15 02:51:32 (permalink)
    0
    I've been "experimenting" with code from these ANs in 2007.
    These are oldies but goldies, and I have little doubt you'll succeed with these.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    microLearner
    Junior Member
    • Total Posts : 110
    • Reward points : 0
    • Joined: 2017/02/27 20:26:37
    • Location: 0
    • Status: offline
    Re: AN2520 FLoating point calculations. 2019/09/28 23:35:16 (permalink)
    0
    I am going through the AN2520 source code in C to understand. I am struck up at the following

     
    MC_APP_MC_CalculateParkAngle(); and mcLib_SinCosGen(&mcApp_SincosParam); and in the open loop condition.
     
    END_SPEED_RADS_PER_SEC_ELEC_IN_LOOPTIME = 0.013089969
     
    OPENLOOP_RAMPSPEED_INCREASERATE = 2.18166E-07
     

    I get the following results as shown below. The code

     
    y0_Index = (uint32_t)(scParam->Angle/ANGLE_STEP);
     
    //Added this condition which detects if y0_Index is >=256.
        //Earlier the only check was for y0_IndexNext.
        //We observed y0_Index > = 256 when the code to reverse the direction of the motor was added
        if(y0_Index>=TABLE_SIZE)
        {
     
         }
     

    As per my calculations the y0 always below 1 why? Please help.
     
    Startup_Ramp     
    _Angle_Rads
    _Per_Sec               y0_index
     
    2.18166E-07     8.88889E-06
    4.36332E-07    1.77778E-05
    6.54498E-07    2.66667E-05
    1.09083E-06    4.44444E-05
    1.74533E-06    7.11111E-05
    2.83616E-06    0.000115556
    4.58149E-06    0.000186667
    7.41765E-06    0.000302222
    1.19991E-05    0.000488889
    1.94168E-05    0.000791111
    3.14159E-05    0.00128
    5.08327E-05    0.002071111
    8.22486E-05    0.003351111
    0.000133081    0.005422222
    0.00021533    0.008773333
    0.000348411    0.014195556
    0.000563741    0.022968889
    0.000912153    0.037164444
    0.001475894    0.060133333
    0.002388047    0.097297778
    0.003863941    0.157431111
    0.006251988    0.254728889
    0.010115928    0.41216


     I expected y0_Index  to be in the table range from 0 to 256. Am i correct in my understanding? And the function

    mcLib_SinCosGen(&mcApp_SincosParam);

     Would return the sine and cos of that table index with interpolation?
    post edited by microLearner - 2019/09/28 23:40:08
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5