AN2520 FLoating point calculations.https://www.microchip.com/forums/(c) Microchip30Re: AN2520 FLoating point calculations. (microLearner)I am going through the AN2520 source code in C to understand. I am struck up at the following<br/><pre class="prettyprint"><br> <br>MC_APP_MC_CalculateParkAngle(); and mcLib_SinCosGen(&mcApp_SincosParam); and in the open loop condition.<br> <br>END_SPEED_RADS_PER_SEC_ELEC_IN_LOOPTIME = 0.013089969<br> <br>OPENLOOP_RAMPSPEED_INCREASERATE = 2.18166E-07<br> <br></pre><br/>I get the following results as shown below. The code<br/><pre class="prettyprint"><br> <br>y0_Index = (uint32_t)(scParam->Angle/ANGLE_STEP);<br> <br>//Added this condition which detects if y0_Index is >=256.<br /> //Earlier the only check was for y0_IndexNext. <br /> //We observed y0_Index > = 256 when the code to reverse the direction of the motor was added<br /> if(y0_Index>=TABLE_SIZE)<br /> {<br> <br> }<br> <br></pre><br/>As per my calculations the y0 always below 1 why? Please help.<br/> <br/>Startup_Ramp <br/>_Angle_Rads<br/>_Per_Sec y0_index<br/> <br/>2.18166E-07 8.88889E-06<br/>4.36332E-07 1.77778E-05<br>6.54498E-07 2.66667E-05<br>1.09083E-06 4.44444E-05<br>1.74533E-06 7.11111E-05<br>2.83616E-06 0.000115556<br>4.58149E-06 0.000186667<br>7.41765E-06 0.000302222<br>1.19991E-05 0.000488889<br>1.94168E-05 0.000791111<br>3.14159E-05 0.00128<br>5.08327E-05 0.002071111<br>8.22486E-05 0.003351111<br>0.000133081 0.005422222<br>0.00021533 0.008773333<br>0.000348411 0.014195556<br>0.000563741 0.022968889<br>0.000912153 0.037164444<br>0.001475894 0.060133333<br>0.002388047 0.097297778<br>0.003863941 0.157431111<br>0.006251988 0.254728889<br>0.010115928 0.41216<br><br><br/> I expected y0_Index to be in the table range from 0 to 256. Am i correct in my understanding? And the function <br/><pre class="prettyprint"><br>mcLib_SinCosGen(&mcApp_SincosParam);<br></pre><br/> Would return the sine and cos of that table index with interpolation?<br/>https://www.microchip.com/forums/FindPost/1113797Sat, 28 Sep 2019 23:35:16 GMTRe: AN2520 FLoating point calculations. (du00000001)I've been "experimenting" with code from these ANs in 2007.<br/>These are oldies but goldies, and I have little doubt you'll succeed with these.<br/>https://www.microchip.com/forums/FindPost/1112462Sun, 15 Sep 2019 02:51:32 GMTRe: AN2520 FLoating point calculations. (microLearner)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. <br/>https://www.microchip.com/forums/FindPost/1112459Sun, 15 Sep 2019 01:08:08 GMTRe: AN2520 FLoating point calculations. (du00000001)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.<br/>https://www.microchip.com/forums/FindPost/1112426Sat, 14 Sep 2019 09:38:10 GMTRe: AN2520 FLoating point calculations. (microLearner)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. <br/>https://www.microchip.com/forums/FindPost/1112424Sat, 14 Sep 2019 08:45:00 GMTRe: AN2520 FLoating point calculations. (du00000001)Floating point?<br/>WTF are you trying torun on a dsPIC?<br/>The above AN is for 32-Bitters with FPU support!<br/> <br/>Look for similar ANs for dsPICs (that usually work with fixed-point integer math).<br/>https://www.microchip.com/forums/FindPost/1112423Sat, 14 Sep 2019 08:19:39 GMTAN2520 FLoating point calculations. (microLearner)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<br/><pre class="prettyprint"><br>void mcLib_ClarkeTransform(mcParam_ABC *abcParam, mcParam_AlphaBeta *alphabetaParam)<br />{<br /> alphabetaParam->alpha = abcParam->a;<br /> alphabetaParam->beta = (abcParam->a * ONE_BY_SQRT3) + (abcParam->b * 2 * ONE_BY_SQRT3);<br />}<br></pre><br/>I used the same code the execution time is very high what i measured from scope is<br/>Clarke Transform -> 23.3uS<br/>Park Transform -> 30uS. How to reduce the time. Any suggestions? Please advise.<br/><br>Clarke Transform 23.3uS<br/>https://www.microchip.com/forums/FindPost/1112421Sat, 14 Sep 2019 07:08:25 GMT