您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 汽车理论 > 基于TMS320F2812的永磁同步电动机SVPWM空间矢量控制算法实现的源代码
/*==============================================================================SystemName:PMSM34FileName:PMSM3_4.CDescription:PrimarysystemfilefortheRealImplementationofPositionControlBasedSensoredFieldOrientationControlforaThreePhasePermanent-MagnetSynchronousMotor(PMSM)usingQEPsensorOriginator:DigitalcontrolsystemsGroup-TexasInstrumentsNote:Inthissoftware,thedefaultinverterissupposedtobeDMC550board.=====================================================================================History:-------------------------------------------------------------------------------------04-15-2005Version3.20:SupportbothF280xandF281xtargets04-25-2005Version3.21:MoveEINTandERTMdowntoensurethatallinitializationiscompletedbeforeinterruptsareallowed.=================================================================================*///Includeheaderfilesusedinthemainfunction#includetarget.h#includeDSP281x_Device.h#includeIQmathLib.h#includepmsm3_4.h#includeparameter.h#includebuild.h#includemath.h//Prototypestatementsforfunctionsfoundwithinthisfile.interruptvoidMainISR(void);interruptvoidQepISR(void);interruptvoidPDPINTAISR(void);//Globalvariablesusedinthissystemfloat32VdTesting=0;//Vdtesting(pu)float32VqTesting=0.25;//Vqtesting(pu)float32IdRef=0;//Idreference(pu)float32IqRef=0.2;//Iqreference(pu)float32SpeedRef=0.1;//Speedreference(pu)float32PositionRef=0.5;//Positionreference(MechanicalrotorAnglele(pu)float32T=0.001/ISR_FREQUENCY;//Sampingperiod(sec),seeparameter.hUint16IsrTicker=0;Uint16BackTicker=0;volatileUint16EnableFlag=FALSE;Uint16LockRotorFlag=FALSE;Uint16SpeedLoopPrescaler=10;//SpeedloopprescalerUint16SpeedLoopCount=1;//Speedloopcounter//InstanceafewtransformobjectsCLARKEclarke1=CLARKE_DEFAULTS;PARKpark1=PARK_DEFAULTS;IPARKipark1=IPARK_DEFAULTS;//InstancePIDregulatorstoregulatethedandqsynchronousaxiscurrents,//speedandpositionPIDREG3pid1_id=PIDREG3_DEFAULTS;PIDREG3pid1_iq=PIDREG3_DEFAULTS;PIDREG3pid1_pos=PIDREG3_DEFAULTS;PIDREG3pid1_spd=PIDREG3_DEFAULTS;//InstanceaPWMdriverinstancePWMGENpwm1=PWMGEN_DEFAULTS;//InstanceaSpaceVectorPWMmodulator.Thismodulatorgeneratesa,bandc//phasesbasedonthedandqstationeryreferenceframeinputsSVGENDQsvgen_dq1=SVGENDQ_DEFAULTS;//InstanceaQEPinterfacedriverQEPqep1=QEP_DEFAULTS;//InstanceaspeedcalculatorbasedonQEPSPEED_MEAS_QEPspeed1=SPEED_MEAS_QEP_DEFAULTS;//InstancearampcontrollertosmoothlyrampthefrequencyRMPCNTLrc1=RMPCNTL_DEFAULTS;//InstancearampgeneratortosimulateanAngleleRAMPGENrg1=RAMPGEN_DEFAULTS;//Createaninstanceofthecurrent/dc-busvoltagemeasurementdriverILEG2DCBUSMEASilg2_vdc1=ILEG2DCBUSMEAS_DEFAULTS;voidmain(void){//******************************************//InitializationcodeforDSP_TARGET=F2812//******************************************//InitializeSystemControlregisters,PLL,WatchDog,Clockstodefaultstate://ThisfunctionisfoundintheDSP281x_SysCtrl.cfile.InitSysCtrl();//HISPCPprescaleregistersettings,normallyitwillbesettodefaultvaluesEALLOW;//ThisisneededtowritetoEALLOWprotectedregistersSysCtrlRegs.HISPCP.all=0x0000;//SYSCLKOUT/1EDIS;//ThisisneededtodisablewritetoEALLOWprotectedregisters//DisableandclearallCPUinterrupts:DINT;IER=0x0000;IFR=0x0000;//InitializePieControlRegistersToDefaultState://ThisfunctionisfoundintheDSP281x_PieCtrl.cfile.InitPieCtrl();//InitializethePIEVectorTableToaKnownState://ThisfunctionisfoundinDSP281x_PieVect.c.//ThisfunctionpopulatesthePIEvectortablewithpointers//totheshellISRfunctionsfoundinDSP281x_DefaultIsr.c.InitPieVectTable();//InitializeGPIO;MUX为0,表示IO;MUX为1表示外围;//DIR为0,表示输入;DIR为1表示输出EALLOW;GpioMuxRegs.GPAMUX.all=0X073F;GpioMuxRegs.GPADIR.all=0XC0C0;GpioMuxRegs.GPBMUX.all=0X0000;GpioMuxRegs.GPBDIR.all=0X0000;GpioMuxRegs.GPDMUX.bit.T1CTRIP_PDPA_GPIOD0=1;//功能PDPINTAGpioMuxRegs.GPDMUX.bit.T2CTRIP_SOCA_GPIOD1=0;//INPUTGpioMuxRegs.GPDDIR.bit.GPIOD1=0;GpioMuxRegs.GPDMUX.bit.T3CTRIP_PDPB_GPIOD5=0;GpioMuxRegs.GPDDIR.bit.GPIOD5=0;GpioMuxRegs.GPDMUX.bit.T4CTRIP_SOCB_GPIOD6=0;GpioMuxRegs.GPDDIR.bit.GPIOD6=0;GpioMuxRegs.GPEMUX.bit.XINT1_XBIO_GPIOE0=0;GpioMuxRegs.GPEMUX.bit.XINT2_ADCSOC_GPIOE1=0;GpioMuxRegs.GPEMUX.bit.XNMI_XINT13_GPIOE2=0;GpioMuxRegs.GPEDIR.bit.GPIOE0=0;GpioMuxRegs.GPEDIR.bit.GPIOE1=0;GpioMuxRegs.GPEDIR.bit.GPIOE2=0;GpioMuxRegs.GPFMUX.all=0X4037;GpioMuxRegs.GPFDIR.all=0X01C8;GpioMuxRegs.GPGMUX.bit.SCITXDB_GPIOG4=0;GpioMuxRegs.GPGMUX.bit.SCIRXDB_GPIOG5=0;GpioMuxRegs.GPGDIR.bit.GPIOG4=1;GpioMuxRegs.GPGDIR.bit.GPIOG5=1;EDIS;//Userspecificfunctions,Reassignvectors(optional),EnableInterrupts://InitializeEVATimer1://SetupTimer1Registers(EVA)EvaRegs.GPTCONA.all=0;//Waitingforenableflagsetwhile(EnableFlag==FALSE){BackTicker++;}//EnableUnderflowinterruptbitsforGPtimer1EvaRegs.EVAIMRA.bit.T1UFINT=1;EvaRegs.EVAIFRA.bit.T1UFINT=1;//EnableCAP3interruptbitsforGPtimer2EvaRegs.EVAIMRC.bit.CAP3INT=1;EvaRegs.EVAIFRC.bit.CAP3INT=1;//ReassignISRs.//ReassignthePIEvectorforT1UFINTandCAP3INTtopointtoadifferent//ISRthentheshellroutinefoundinDSP281x_DefaultIsr.c.//ThisisdoneiftheuserdoesnotwanttousetheshellISRroutine//butinsteadwantstousetheirownISR.EALLOW;//Thisisnee
本文标题:基于TMS320F2812的永磁同步电动机SVPWM空间矢量控制算法实现的源代码
链接地址:https://www.777doc.com/doc-2572436 .html