- 积分
- 48
- 回帖
- 0
- 西莫币
-
- 贡献
-
- 威望
-
- 存款
-
- 阅读权限
- 5
- 最后登录
- 1970-1-1
该用户从未签到
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
下面这段程序是microchip文档A1017中的一段代码,见附件,下面一个红色地方没看明白,请各位兄台帮我理解理解
说明:程序是在T1定时1ms中断中,主要是用来计算是电机速度,我角度增量(在SVPWM中使用)
static int PeriodKFilter = PERIOD_FILTER_CONST;
static long int PeriodStateVar;
Period = ActualCapture - PastCapture; // 获取180度电角度周期所用的时间,读取T3定时器的捕获值This is an UNsigned substraction to get the Period between one hall effect sensor transition
// These operations limit the Period value to a range from 60 to 6000 rpm
if (Period < (unsigned int)MINPERIOD) // MINPERIOD or 6000 rpm
Period = MINPERIOD;
else if (Period > (unsigned int)MAXPERIOD) // MAXPERIOD or 60 rpm
Period = MAXPERIOD;
//这里没看明白,PeriodKFilter =1000常数(程序中宏定义及注释#define PERIOD_FILTER_CONST 1000 /* the smaller the value, the higher the filter and the delay introduced */),为什么要乘1000,结果为什么要右移15位呢,为什么这样处理?
PeriodStateVar+= (((long int)Period - (long int)PeriodFilter)*(int)(PeriodKFilter));
PeriodFilter = (int)(PeriodStateVar>>15);
// PhaseInc is a value added to the Phase variable to generate the sine
// voltages. 1 electrical degree corresponds to a PhaseInc value of 184,
// since the pointer to the sine table is a 16bit value, where 360 Elec
// Degrees represents 65535 in the pointer.
// __builtin_divud(Long Value, Int Value) is a function of the compiler
// to do Long over Integer divisions.
//#define PHASE_INC_CALC 448000UL //(FCY/(PDIV*2*FPWM)*65536),这里为什么要乘65536?
PhaseInc = __builtin_divud((long unsigned int)PHASE_INC_CALC,(unsigned int)PeriodFilter);
MeasuredSpeed = __builtin_divud((long unsigned int)SPEED_RPM_CALC,(unsigned int)PeriodFilter); |
|