• AVR Freaks

Hot!AN1078 DELTA_STARTUP_RAMP calculate problem

Author
yelang1124
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2018/12/02 20:15:42
  • Location: 0
  • Status: offline
2018/12/04 19:53:44 (permalink)
0

AN1078 DELTA_STARTUP_RAMP calculate problem

Hi, all friends:
 i can't understand why DELTA_STARTUP_RAMP  should multiplication  65536 two times.
 
#define OPENLOOPTIMEINSEC 3.0 // Open loop time in seconds.
#define LOOPTIMEINSEC (1.0/PWMFREQUENCY) // PWM Period = 1.0 / PWMFREQUENCY
#define DELTA_STARTUP_RAMP (unsigned int)(MINSPEEDINRPM*POLEPAIRS*LOOPTIMEINSEC* \
LOOPTIMEINSEC*65536*65536/(60*OPENLOOPTIMEINSEC))
 
if(uGF.bit.OpenLoop)
{
if (Startup_Lock < MotorParm.LockTime)
          Startup_Lock += 1; // This variable is incremented until
else if (Startup_Ramp < MotorParm.EndSpeed)
         Startup_Ramp += DELTA_STARTUP_RAMP;
else{
....
}
       ParkParm.qAngle += (int)(Startup_Ramp >> 16);
}
 
 
i think it used for float to Q15 convertion, but  multiplication 65536 two times , equal to << 32bit
and the qAngle I think is Q15 format,   i know float to Q15 should multiplication 32768, 2^15,  
so i think ParkParm.qAngle += (int)(Startup_Ramp >> 17);   is right,  because <<32 ,  then >> 17 ,  equal to << 15.
right?????  so what's the correct understanding for multiplication  65536 two times.
 
 
thank you for your reply!
 
#1

6 Replies Related Threads

    yelang1124
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2018/12/02 20:15:42
    • Location: 0
    • Status: offline
    Re: AN1078 DELTA_STARTUP_RAMP calculate problem 2018/12/04 22:24:41 (permalink)
    0
    oh, omega = 2pi*rpm,   
     
    #define DELTA_STARTUP_RAMP (unsigned int)(MINSPEEDINRPM*POLEPAIRS*LOOPTIMEINSEC* \
    LOOPTIMEINSEC*65536*32768*2*PI/(60*OPENLOOPTIMEINSEC))
    32768 used for Q15 conversion.
     
    #define DELTA_STARTUP_RAMP (unsigned int)(MINSPEEDINRPM*POLEPAIRS*LOOPTIMEINSEC* \
    LOOPTIMEINSEC*65536*65536*PI/(60*OPENLOOPTIMEINSEC))
     
    where is the PI  ?  i think  it should be * PI ?   pink: pink
    #2
    yelang1124
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2018/12/02 20:15:42
    • Location: 0
    • Status: offline
    Re: AN1078 DELTA_STARTUP_RAMP calculate problem 2018/12/04 22:46:56 (permalink)
    0
    oh!  new find.
    #define OMEGA8 (float)(SPEED8 * LOOPTIMEINSEC * \
    IRP_PERCALC * POLEPAIRS * 2.0 / 60.0)
    #define OMEGA9 (float)(SPEED9 * LOOPTIMEINSEC * \
    IRP_PERCALC * POLEPAIRS * 2.0 / 60.0)
    #define OMEGA10 (float)(SPEED10 * LOOPTIMEINSEC * \
    IRP_PERCALC * POLEPAIRS * 2.0 / 60.0)
     
    the SPEED10 uint is RPM,    IRP_PERCALC   is how many foc_calc_loops  in  speed_loop.
    i found in the code,,,  RPM  to omega All are less PI,,,why?
    #3
    xn45862060
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2019/01/09 01:57:36
    • Location: 0
    • Status: offline
    Re: AN1078 DELTA_STARTUP_RAMP calculate problem 2019/01/10 00:05:15 (permalink)
    0
    because the DELTA_STARTUP_RAMP use the Q31 format ;
    when calculating the Angle, use the high 16 bit  ==>ParkParm.qAngle += (int)(Startup_Ramp >> 16);
    #4
    _dex
    Starting Member
    • Total Posts : 72
    • Reward points : 0
    • Joined: 2008/03/19 13:57:34
    • Location: 0
    • Status: offline
    Re: AN1078 DELTA_STARTUP_RAMP calculate problem 2019/08/07 15:59:10 (permalink)
    0
    33F is a 16 bit family so why they use q31 instead of q15 ?.
    #5
    ric
    Super Member
    • Total Posts : 24205
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: AN1078 DELTA_STARTUP_RAMP calculate problem 2019/08/07 16:31:13 (permalink)
    0
    Probably because they need that precision.
    16 bit processors can do 32 bit calculations, just not in a single instruction cycle.
    It's the same as 8 bit processors being able to work on 16 and 32 bit variables. They can do it, just not as fast as their native size. It's still much quicker than floating point.
     

    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!
    #6
    _dex
    Starting Member
    • Total Posts : 72
    • Reward points : 0
    • Joined: 2008/03/19 13:57:34
    • Location: 0
    • Status: offline
    Re: AN1078 DELTA_STARTUP_RAMP calculate problem 2019/08/08 03:38:50 (permalink)
    0
    Really ? Not because the code was ported from 32 bit processor and the Preprocessor is making it 'compatible' with 16 bit uC?
    The PWM duty registers are 16 bit long, so they are not ready for such accuracy or are they?. 32 bit accuracy for an angle?> I do not belive.
    I ma really asking this is very important for the beginners because advanced programmers do make a lot of tricks while the beginners are wondering 2 weeks why something simple and obvious was done in such or other way.
    post edited by _dex - 2019/08/08 05:06:16
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5