SVPWM中电机角度估计问题
下面这段程序是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 getthe 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); 看看看看那,询问一下 本帖最后由 DengKai 于 2016-9-5 15:11 编辑
我目前也还在了解为什么PeriodKFilter =1000常数,以及PeriodFilter右移15位,
但是感觉上是让数值变化缓和的功用,有点类似取平均值的概念。
而 #define PHASE_INC_CALC 448000UL //(FCY/(PDIV*2*FPWM)*65536),这里为什么要乘65536?
是因为将360度以65536来表示。
补充:
程式有提到以下部分,也都是以65536来表示360度
const int PhaseValues =
{PHASE_ZERO, PHASE_ONE, PHASE_TWO, PHASE_THREE, PHASE_FOUR, PHASE_FIVE};
#define PHASE_ZERO 0 0
#define PHASE_ONE ((PHASE_ZERO + 65536/6) % 65536) 10922
#define PHASE_TWO ((PHASE_ONE + 65536/6) % 65536) 21844
#define PHASE_THREE ((PHASE_TWO + 65536/6) % 65536) 32766
#define PHASE_FOUR ((PHASE_THREE + 65536/6) % 65536) 43688
#define PHASE_FIVE ((PHASE_FOUR + 65536/6) % 65536) 54610
页:
[1]