21ic问答首页 - 灵动MM32SPIN0230板子里面的电机驱动代码解释
灵动MM32SPIN0230板子里面的电机驱动代码解释
微凉42322023-08-20
static inline void MCFLIB_InvPark_S16(const MCFLIB_2_DQ_T_S16 *psIn,
const sAngle_Trig *psAnglePos,
MCFLIB_2_ALBE_T_S16 *psOut)
{
register Q31_t s16D;register Q31_t s16Q;register Q31_t s16Sin;register Q31_t s16Cos;register Q31_t s32Temp;
/* Store values for calculation */
s16D = (psIn->s16D);
s16Q = (psIn->s16Q);
s16Sin = (psAnglePos->s16Sin);
s16Cos = (psAnglePos->s16Cos);
/* Calculate beta = d * sin(theta) + q * cos(theta) */
s32Temp = (s16Cos * s16Q + s16Sin * s16D) >> 15;
psOut->s16Beta = (Q15_t)s32Temp ;
/* Calculate alpha = d * cos(theta) - q * sin(theta) */
s32Temp = ((s16Cos * s16D) - (s16Sin * s16Q)) >> 15;
psOut->s16Alpha = (Q15_t) s32Temp ;
}
这里的 s32Temp = (s16Cos * s16Q + s16Sin * s16D) >> 15;代码为什么要进行右移十五位的操作呀?如果是匹配Q15_t数据类型的话,下面不就有个强转嘛,这里的>>15操作,有什么含义呀?初学,想请教各位大佬一下!!感谢!!
const sAngle_Trig *psAnglePos,
MCFLIB_2_ALBE_T_S16 *psOut)
{
register Q31_t s16D;register Q31_t s16Q;register Q31_t s16Sin;register Q31_t s16Cos;register Q31_t s32Temp;
/* Store values for calculation */
s16D = (psIn->s16D);
s16Q = (psIn->s16Q);
s16Sin = (psAnglePos->s16Sin);
s16Cos = (psAnglePos->s16Cos);
/* Calculate beta = d * sin(theta) + q * cos(theta) */
s32Temp = (s16Cos * s16Q + s16Sin * s16D) >> 15;
psOut->s16Beta = (Q15_t)s32Temp ;
/* Calculate alpha = d * cos(theta) - q * sin(theta) */
s32Temp = ((s16Cos * s16D) - (s16Sin * s16Q)) >> 15;
psOut->s16Alpha = (Q15_t) s32Temp ;
}
这里的 s32Temp = (s16Cos * s16Q + s16Sin * s16D) >> 15;代码为什么要进行右移十五位的操作呀?如果是匹配Q15_t数据类型的话,下面不就有个强转嘛,这里的>>15操作,有什么含义呀?初学,想请教各位大佬一下!!感谢!!
您需要登录后才可以回复 登录 | 注册