很详细的dspic逆变svpwm程序.docx

上传人:b****5 文档编号:6202384 上传时间:2023-01-04 格式:DOCX 页数:37 大小:27.24KB
下载 相关 举报
很详细的dspic逆变svpwm程序.docx_第1页
第1页 / 共37页
很详细的dspic逆变svpwm程序.docx_第2页
第2页 / 共37页
很详细的dspic逆变svpwm程序.docx_第3页
第3页 / 共37页
很详细的dspic逆变svpwm程序.docx_第4页
第4页 / 共37页
很详细的dspic逆变svpwm程序.docx_第5页
第5页 / 共37页
点击查看更多>>
下载资源
资源描述

很详细的dspic逆变svpwm程序.docx

《很详细的dspic逆变svpwm程序.docx》由会员分享,可在线阅读,更多相关《很详细的dspic逆变svpwm程序.docx(37页珍藏版)》请在冰豆网上搜索。

很详细的dspic逆变svpwm程序.docx

很详细的dspic逆变svpwm程序

F:

\dspic\CE003_Sinusoidal_BLDC_010908\CE003_Sinusoidal_BLDC\source\SinusoidalBLDCv1.1.c

/*SOFTWARELICENSEAGREEMENT:

*MicrochipTechnologyIncorporated("Microchip")retainsallownershipand

*intellectualpropertyrightsinthecodeaccompanyingthismessageandinall

*derivativeshereto.Youmayusethiscode,andanyderivativescreatedby

*anypersonorentitybyoronyourbehalf,exclusivelywithMicrochip's

*proprietaryproducts.Youracceptanceand/oruseofthiscodeconstitutes

*agreementtothetermsandconditionsofthisnotice.

*

*CODEACCOMPANYINGTHISMESSAGEISSUPPLIEDBYMICROCHIP"ASIS".NO

*WARRANTIES,WHETHEREXPRESS,IMPLIEDORSTATUTORY,INCLUDING,BUTNOTLIMITED

*TO,IMPLIEDWARRANTIESOFNON-INFRINGEMENT,MERCHANTABILITYANDFITNESSFORA

*PARTICULARPURPOSEAPPLYTOTHISCODE,ITSINTERACTIONWITHMICROCHIP'S

*PRODUCTS,COMBINATIONWITHANYOTHERPRODUCTS,ORUSEINANYAPPLICATION.

*

*YOUACKNOWLEDGEANDAGREETHAT,INNOEVENT,SHALLMICROCHIPBELIABLE,WHETHER

*INCONTRACT,WARRANTY,TORT(INCLUDINGNEGLIGENCEORBREACHOFSTATUTORYDUTY),

*STRICTLIABILITY,INDEMNITY,CONTRIBUTION,OROTHERWISE,FORANYINDIRECT,SPECIAL,

*PUNITIVE,EXEMPLARY,INCIDENTALORCONSEQUENTIALLOSS,DAMAGE,FORCOSTOREXPENSEOF

*ANYKINDWHATSOEVERRELATEDTOTHECODE,HOWSOEVERCAUSED,EVENIFMICROCHIPHASBEEN

*ADVISEDOFTHEPOSSIBILITYORTHEDAMAGESAREFORESEEABLE.TOTHEFULLESTEXTENT

*ALLOWABLEBYLAW,MICROCHIP'STOTALLIABILITYONALLCLAIMSINANYWAYRELATEDTO

*THISCODE,SHALLNOTEXCEEDTHEPRICEYOUPAIDDIRECTLYTOMICROCHIPSPECIFICALLYTO

*HAVETHISCODEDEVELOPED.

*

*Youagreethatyouaresolelyresponsiblefortestingthecodeand

*determiningitssuitability.Microchiphasnoobligationtomodify,test,

*certify,orsupportthecode.

*

*REVISIONHISTORY:

*/

//

//---------------------------------------------------------------------

//File:

sinusoidalBLDCv1.1.c

//

//WrittenBy:

JorgeZambada,MicrochipTechnology

//

//ThefollowingfilesshouldbeincludedintheMPLABproject:

//

//sinusoidalBLDCv1.1.c--Mainsourcecodefile

//SVM.c--SpaceVectorModulationfile

//SVM.h

//p30f4012.gld--Linkerscriptfile

//---------------------------------------------------------------------

//

//RevisionHistory

//

//July/5/2005--firstversion

//----------------------------------------------------------------------

#include"p30f4012.h"

#include"svm.h"

//--------------------------DeviceConfiguration------------------------

_FOSC(CSW_FSCM_OFF&XT_PLL16);

_FWDT(WDT_OFF);

_FBORPOR(PBOR_ON&BORV_20&PWRT_64&MCLR_EN);

//----------------------------------------------------------------------

//HurstMotorTerminals|MCLVPICDEMBoardConnection

//-----------------------|---------------------------------

//GroundPhase---------|--G

//PhaseRed---------|--M1

//PhaseBlack---------|--M2

//PhaseWhite---------|--M3

//HallWhite---------|--HA

//HallBrown---------|--HB

//HallGreen---------|--HC

typedefsignedintSFRAC16;

#defineCLOSED_LOOP//ifdefinedthespeedcontrollerwillbeenabled

#definePHASE_ADVANCE//forextendedspeedrangesthisshouldbedefined

#defineFCY20000000//xtal=5Mhz;PLLx16->20MIPS

#defineFPWM20000//20kHz,sothatnoaudiblenoiseispresent.

#define_10MILLISEC10//Usedasatimeoutwithnohalleffectsensors

//transitionsandForcingstepsaccordingtothe

//actualpositionofthemotor

#define_100MILLISEC100//afterthistimehaselapsed,themotoris

//considerstalledandit'sstopped

1

F:

\dspic\CE003_Sinusoidal_BLDC_010908\CE003_Sinusoidal_BLDC\source\SinusoidalBLDCv1.1.c

#define_1000MILLISEC1000

//ThesePhasevaluesrepresentthebasePhasevalueofthesinewaveforeach

//oneofthesectors(eachsectorisatranslationofthehalleffectsensors

//reading

#definePHASE_ZERO57344

#definePHASE_ONE((PHASE_ZERO+65536/6)%65536)

#definePHASE_TWO((PHASE_ONE+65536/6)%65536)

#definePHASE_THREE((PHASE_TWO+65536/6)%65536)

#definePHASE_FOUR((PHASE_THREE+65536/6)%65536)

#definePHASE_FIVE((PHASE_FOUR+65536/6)%65536)

#defineMAX_PH_ADV_DEG40//Thisvaluerepresentsthemaximumallowedphase

//advanceinelectricaldegrees.Setavaluefrom

//0to60.Thisvaluewillbeusedtocalculate

//phaseadvanceonlyifPHASE_ADVANCEisdefined

//Thisisthecalculationfromtherequiredphaseadvancetotheactual

//valuetobemultipliedbythespeedofthemotor.So,ifPHASE_ADVANCEis

//enabled,acertainamountofshitanglewillbeaddedtothegenerated

//sinewave,uptoamaximumofthespecifiedvalueonMAX_PH_ADV_DEG.This

//maximumphaseshiftwillbepresentwhentheMeasuredSpeedvariableisa

//fractional1.0(forCW)or-1.0(forCCW).

#defineMAX_PH_ADV(int)(((float)MAX_PH_ADV_DEG/360.0)*65536.0)

#defineHALLA1//ConnectedtoRB3

#defineHALLB2//ConnectedtoRB4

#defineHALLC4//ConnectedtoRB5

#defineCW0//CounterClockWisedirection

#defineCCW1//ClockWisedirection

#defineSWITCH_S2(!

PORTCbits.RC14)//PushbuttonS2

//PeriodCalculation

//Period=(TMRClock*60)/(RPM*Motor_Poles)

//Forexample>

//Motor_Poles=10

//RPM=6000(MaxSpeed)

//Period=((20,000,000/64)*60)/(6000*10)=312.5

//RPM=60(MinSpeed)

//Period=((20,000,000/64)*60)/(60*10)=31250

#defineMINPERIOD313//For6000maxrpmand10polesmotor

#defineMAXPERIOD31250//For60minrpmand10polesmotor

//UsethisMACROwhenusingfloatstoinitializesigned16-bitfractional

//variables

#defineSFloat_To_SFrac16(Float_Value)\

((Float_Value<0.0)?

(SFRAC16)(32768*(Float_Value)-0.5)\

:

(SFRAC16)(32767*(Float_Value)+0.5))

voidInitADC10(void);//InitializationofADCusedforSpeedCommand

voidInitMCPWM(void);//InitializationforPWMat20kHz,Centeraligned,

//Complementarymodewith1usofdeadtime

voidInitTMR1(void);//InitializationforTIMER1usedforspeedcontrol

//andmotorstalledprotection

voidInitTMR3(void);//InitializationforTIMER3usedasatimebase

//forthetwoinputcapturechannels

voidInitUserInt(void);//Thisfunctioninitializesallports

//(inputsandoutputs)fortheapplication

voidInitICandCN(void);//Initializesinputcapturesandchangenotification,

//usedforthehallsensorinputs

voidRunMotor(void);//Thisfunctioninitializesallvariables

//andinterruptsusedforstartingandrunning

//themotor

voidStopMotor(void);//Thisfunctionclearsallflags,andstopsanything

//relatedtomotorcontrol,andalsodisablesPWMs

voidSpeedControl(void);//ThisfunctioncontainsallASMandCoperations

//fordoingthePIDControlloopforthespeed

voidForceCommutation(void);//Whenmotoristoslowtogenerateinterrupts

//onhalls,thisfunctionforcesacommutation

voidChargeBootstraps(void);//Atthebeginingofthemotoroperation,the

//bootstrapcapsarechargedwiththisfunction

//Constantsusedforproperlyenergizingthemotordependingonthe

//rotor'sposition

intPhaseValues[6]__attribute__((far,section(".const,r")))=

{PHASE_ZERO,PHASE_ONE,PHASE_TWO,PHASE_THREE,PHASE_FOUR,PHASE_FIVE};

//Inthesinewavegenerationalgorithmweneedanoffsettobeaddedtothe

//pointerwhenenergizingthemotorinCCW.Thisisdonetocompensatean

2

F:

\dspic\CE003_Sinusoidal_BLDC_010908\CE003_Sinusoidal_BLDC\source\SinusoidalBLDCv1.1.c

//asymetryofthesinewave

intPhaseOffset=4100;

//Flagsusedfortheapplication

struct

{

unsignedMotorRunning:

1;//Thisbitis1ifmotorrunning

unsignedunused:

15;

}Flags;

unsignedintPhase;//ThisvariableisincrementedbythePWMinterrupt

//inordertogenerateapropersinewave.Itsvalue

//isincrementedbyavalueofPhaseInc,which

//representsthefrequencyofthegeneratedsinewave

signedintPhaseInc;//DeltaincrementsofthePhasevariable,calculated

//intheTIMER1interrupt(each1ms)andusedin

//thePWMinterrupt(each50us)

signedintPhaseAdvance;//Usedforextendingmotorspeedrange.Thisvalue

//isaddeddirectlytotheparameterspassedtothe

//SVMfunction(thesinewavegenerationsubroutine)

unsignedintHallValue;//Thisvariableholdsthehallsensorinputreadings

unsignedintSector;//Thisvariablesholdspresentsectorvalue,whichis

//therotorposition

unsignedintLastSector;//Thisvariableholdsthelastsectorvalue.This

//iscriticaltofilterslowslewrateontheHall

//effectsensorshardware

unsignedintMotorStalledCounter=0;//Thisvariablegetsincrementedeach

//1ms,andisclearedeverytimeanew

//sectorisdetected.Usedfor

//ForceCommutationandMotorStalled

//protectionfunctions

//ThisarraytranslatesthehallstatevaluereadfromthedigitalI/Otothe

//propersector.Hallvaluesof0or7representillegalvaluesandtherefore

//return-1.

charSectorTable[]={-1,4,2,3,0,5,1,-1};

unsignedcharCurrent_Direction;//Currentmechanicalmotordirectionof

//rotationCalculatedinhallsinterrupts

unsignedcharRequired_Direction;//Requiredmechanicalmotordirectionof

//rotation,willhavethesamesignasthe

//ControlOutputvariablefromtheSpeed

//Controller

//VariablescontainingthePeriodofhalfanelectricalcycle,whichisan

//interrupteachedgeofoneofthehallsensorinput

unsignedintPastCapture,ActualCapture,Period;

//Usedasatemporalvariabletoperformafractionaldivideoperationin

//assembly

SFRAC16_MINPERIOD=MINPERIOD-1;

SFRAC16MeasuredSpeed,RefSpeed;//ActualandDesiredspeedsforthePID

//controller,thatwillgeneratetheerror

SFRAC16ControlOutput=0;//Controlleroutput,usedasavoltageoutput,

//useitssig

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1