1、 /*初始化系统*/ InitSysCtrl(); /*关中断*/ DINT; IER = 0x0000; IFR = 0x0000; /*初始化PIE控制寄存器*/ InitPieCtrl(); /*初始化PIE矢量表*/ InitPieVectTable(); /*初始化SCIb寄存器*/ InitSci(); /初始化24Vxx/ Init24Cxx(); /*设置CPU定时器*/ InitCpuTimers(); ConfigCpuTimer(&CpuTimer2, 150, 20000);CpuTimer1, 150, 100000);/每0.1秒加1Hz,每秒加Y*1000000赫
2、兹 StartCpuTimer1(); StartCpuTimer2(); /*初始化IO口*/ InitGpio(); /*初始化EV*/ eva.Init(&eva); evb.Init(&evb); /*设置中断服务程序入口地址*/ EALLOW; / This is needed to write to EALLOW protected registers PieVectTable.T1UFINT = &T1UFINT_ISR; PieVectTable.TXBINT = &SCITXINTB_ISR; /设置串口B发送中断的中断向量 PieVectTable.RXBINT = &SC
3、IRXINTB_ISR; /设置串口B接受中断的中断向量 PieVectTable.TXAINT = &SCITXINTA_ISR; /设置串口A发送中断的中断向量 PieVectTable.RXAINT = &SCIRXINTA_ISR; /设置串口A接受中断的中断向量 PieVectTable.TINT2 = &ISRTimer2; PieVectTable.XINT13= &ISRTimer1;/定时器1和外部中断合用一个中断标志位 /此处为XINT13并不是TINT1 EDIS; / This is needed to disable write to EALLOW protected
4、 registers /*使能位于PIE中组2的第6个中断 定时器1下溢中断*/ PieCtrl.PIEIER2.bit.INTx6=1; /*开中断*/ IER |= M_INT2; /EVA IER |= M_INT9; /SCI /允许串口中断 IER |= M_INT14; /cputimer2 IER |= M_INT13; /cputimer1 EINT; / Enable Global interrupt INTM ERTM; / Enable Global realtime interrupt DBGM eva.Close(& evb.Open(& rampgen.StepAn
5、gleMax = _IQ(0.0128); /最大频率128hz 中断频率10k while(1) / hc= _IQmpy(ha,hb);只进行保留整数位,对于小数位不进行四舍五入。hc=(ha*hb)/65536 /=/ 定时器1下溢中断服务程序.interrupt void T1UFINT_ISR(void) / EV-A/ asm ( ESTOP0); / PieCtrl.PIEACK.bit.ACK2=1; / EvaRegs.EVAIFRA.bit.T1UFINT=1; /清中断标志位 /rampgen模块 产生矢量旋转的角度 需要设置StepAngleMax这里是控制转速的。/
6、rampgen.Freq = _IQ(50)7; rampgen.Freq = _IQ(float)f_now)/ 因为最大频率128Hz,是2的7次方,那么除以128就是以最大频率来看的标幺值 rampgen.calc(&rampgen); /vhzprof模块 vvvf控制,根据频率比例控制输出电压的量/ vhzprof.Freq = _IQ(50); vhzprof.Freq = _IQ(float)f_now)+_IQ(0.11); vhzprof.calc(&vhzprof); /RotateVector模块 产生旋转矢量对应的Ualpha Ubeta if(TurnFlag=0)
7、rotatevector.Angle = rampgen.Angle; /停止标志 else rotatevector.Angle = -rampgen.Angle; rotatevector.k = vhzprof.VoltOut; rotatevector.calc(&rotatevector) ; /svgendq模块 根据Ualpha Ubeta 产生比较器需要的TA TB TC svgendq.Ualpha = rotatevector.Ualpha; svgendq.Ubeta = rotatevector.Ubeta ; svgendq.calc(&svgendq) ; happ
8、y=rotatevector.Angle ; /ev模块 eva.Ta = svgendq.Ta; eva.Tb = svgendq.Tb; eva.Tc = svgendq.Tc; eva.SetPwm(& evb.Ta = svgendq.Ta; evb.Tb = svgendq.Tb; evb.Tc = svgendq.Tc; evb.SetPwm(& PieCtrl.PIEACK.bit.ACK2=1; EvaRegs.EVAIFRA.bit.T1UFINT=1;interrupt void SCIRXINTA_ISR(void) PieCtrl.PIEACK.bit.ACK9 = 1
9、; RABuf=SciaRegs.SCIRXBUF.all; switch(RABuf) interrupt void SCIRXINTB_ISR(void) / SCI-B/相应PIE组9的其他中断 RBBuf=ScibRegs.SCIRXBUF.all; switch(RBBuf) case 0: /增加输入电压百分比 break; case 1: /运行 case 2: /增加频率 case 3:/增加频率 case 4:/减少输入电压百分比 case 5:/停止 f_given = 0; case 6: /减小频率 case 7:interrupt void ISRTimer1(voi
10、d) /内部定义的计数变量 if(RABuf =0) CpuTimer1.InterruptCount=0; f_given=0; SciaRegs.SCITXBUF = (unsigned int)f_now; f_given_disp= f_now; if(RABuf =1)/FWD Auto /unsigned int a; RunFlag = 1; eva.Open(& TurnFlag=0; CpuTimer1.InterruptCount+; if(CpuTimer1.InterruptCount0) f_given+; f_now = f_given; /f_given = f_
11、now ; SciaRegs.SCITXBUF = (unsigned int)f_now; if(CpuTimer1.InterruptCount=20)&(CpuTimer1.InterruptCount=30)&50) f_given- ; f_now=f_given; if(CpuTimer1.InterruptCount=50) f_given=0; f_now=0; / RABuf =0 ; if(RABuf =2)/REV Auto RunFlag = 1; TurnFlag=1; f_now=f_given;40) if(CpuTimer1.InterruptCount=40)
12、 f_given = 0 ; if(RABuf =3)/FWD High CpuTimer1.InterruptCount=0; TurnFlag=0; f_now=10; f_given=10; / CpuTimer1.InterruptCount+; / if (CpuTimer1.InterruptCount=10 ) / / RABuf =0; / CpuTimer1.InterruptCount=0; / if(RABuf =4)/REV High TurnFlag=1; /if (CpuTimer1.InterruptCount if(RABuf =5)/FWD Low f_now
13、=5; f_given=5; if(RABuf =6)/REV Low if(RABuf =7)/All Pause /CpuTimer1Regs.TCR.bit.TRB=1;/*暂停*/ /f_now=50; eva.Close(& CpuTimer1Regs.TCR.bit.TIF=1; ShowDisp(); PieCtrl.PIEACK.all=PIEACK_GROUP1; /SciaRegs.SCITXBUF = (unsigned int)f_now;interrupt void ISRTimer2(void) CpuTimer2.InterruptCount+; if(CpuTi
14、mer2.InterruptCount1) /20ms if(f_givenf_now) if(f_now1) f_now=1; else f_now+; else if(f_given RunFlag = 0; f_now-; SciaRegs.SCITXBUF = (unsigned int)f_now; CpuTimer2.InterruptCount=0;void ShowDisp(void) /更新显示 static unsigned int i=0; switch(i) i+; ScibRegs.SCITXBUF =(ku&0xf)+(35); if(RunFlag) ScibRe
15、gs.SCITXBUF =23+(2 else ScibRegs.SCITXBUF =24+(2 if(RunFlag) ScibRegs.SCITXBUF =f_now/10+(1 else ScibRegs.SCITXBUF =f_given_disp/10+(1 if(RunFlag) ScibRegs.SCITXBUF =f_now%10; else ScibRegs.SCITXBUF =f_given_disp%10; i=0; default:/ No more./ Dont forget to set a proper GLOBAL_Q in IQmathLib.h file v
16、hzprof.h#include void vhz_prof_calc(VHZPROF *v) _iq VfSlope, AbsFreq;/ Take absolute frequency to allow the operation of both rotational directions AbsFreq = labs(v-Freq); if (AbsFreq LowFreq) / Compute output voltage in profile #1 v-VoltOut = v-VoltMin; else if (AbsFreq LowFreq)&(AbsFreq VoltMax -
17、v-VoltMin),(v-HighFreq - v-LowFreq);/就是压频比的斜率 / Compute output voltage in profile #2VoltOut =v-VoltMin + _IQmpy(VfSlope,(AbsFreq-v-HighFreq)&FreqMax) / Compute output voltage in profile #3VoltMax; /最大的VoltMax线电压就是直流侧的电压DC直流,可以看思路图,任意时刻是上下桥臂导通。RotateVector.hiqmathlib.hvoid RotateVecotr_calc(RotateVec
18、otr_Handle v) _iq Ua,Ub;/ Using look-up IQ sine table Ub = _IQsinPU(v-Angle);/正弦函数标幺值,你站着个圆周的几分之几 Ua = _IQcosPU(v-Ualpha = _IQmpy(v-k,Ua);Ubeta = _IQmpy(v-k,Ub); / Include header for IQmath library filerampgen.hvoid rampgen_calc(RAMPGEN *v)/ Compute the angle rateAngle += _IQmpy(v-StepAngleMax,v- /这里“v-Freq”是以最大频率(128Hz)来看的给定频率标幺值,乘最大频率再乘中 /断周期就是每一个中短周期增加给定频率那么多的角度(只是线性对应关系,给定越 /大增加越快,给定越小增加就小) / Saturate the angle rate within (-1,1) if (v-Angle_IQ(1.0)Ang
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1