background image

AN908

DS00908A-page 20

 2004 Microchip Technology Inc.

UserParms.h

//#define TORQUE_MODE

#define DIAGNOSTICS

//****************  Oscillator ************************************

#define dFoscExt

7372800

// External Crystal or Clock Frequency (Hz)

#define dPLL

8

// PLL ratio

#define dLoopTimeInSec

0.00005

// PWM Period - 100 uSec, 10Khz PWM

#define dDeadTimeSec

0.000002

// Deadtime in seconds

// Derived

#define dFosc

(dFoscExt*dPLL)

// Clock frequency (Hz)

#define dFcy

(dFosc/4)

// Instruction cycle frequency (Hz)

#define dTcy

(1.0/dFcy)

// Instruction cycle period (sec)

#define dDeadTime

(int)(dDeadTimeSec*dFcy)

// Dead time in dTcys 

#define dLoopInTcy

(dLoopTimeInSec/dTcy)

// Basic loop period in units of Tcy

#define dDispLoopTime

0.100

// Display and button polling loop

//****************  Motor Parameters ******************************

#define diPoles

1

// Number of pole pairs

#define diCntsPerRev

2000

// Encoder Lines per revolution

#define diNomRPM

3600

// Name Plate Motor RPM

#define dfRotorTmConst

0.078

// Rotor time constant in sec, from mfgr

//**************** Measurement *************************************

#define diIrpPerCalc

30

// PWM loops per velocity calculation

//************** PI Coefficients ************************************

#define dDqKp

0x2000

// 4.0

(NKo = 4)

#define dDqKi

0x0100;

// 0.125

#define dDqKc

0x0100;

// 0.125

#define dDqOutMax

0x5A82;

// 0.707

set to prevent saturation

#define dQqKp

0x2000;

// 4.0

(NKo = 4)

#define dQqKi

0x0100;

// 0.125

#define dQqKc

0x0100;

// 0.125

#define dQqOutMax

0x5A82;

// 0.707

set to prevent saturation

#define dQrefqKp

0x4000

// 8.0

(NKo = 4)

#define dQrefqKi

0x0800

// 1.0

#define dQrefqKc

0x0800

// 1.0

#define dQrefqOutMax

0x3FFF

// 0.4999

set to prevent saturation

//************** ADC Scaling ***************************************

// Scaling constants:

Determined by calibration or hardware design. 

#define dqK

0x3FFF;

// equivalent to 0.4999

#define dqKa

0x3FFF;

// equivalent to 0.4999

#define dqKb

0x3FFF;

// equivalent to 0.4999

//************** Field Weakening **************************************

// Flux reference value in constant torque range. 

// Determined empirically to give rated volts/hertz

#define dqK1

3750;

// 

Содержание AN908

Страница 1: ...of the drive voltage you also need to decrease the amplitude by a proportional amount Otherwise the motor will consume excessive current at low input frequencies This control method is called Volts He...

Страница 2: ...currents to get the desired rotor currents which cannot be measured directly With the coordinate transformation the stator currents can be controlled like DC values using standard control loops VECTO...

Страница 3: ...M PARK TRANSFORM At this point you have the stator current Phasor repre sented on a 2 axis orthogonal system with the axis called The next step is to transform into another 2 axis system that is rotat...

Страница 4: ...the motor is accounted for in the flux estimator equations and is included in the calculated angle The flux estimator calculates a new flux position based on stator currents the rotor velocity and th...

Страница 5: ...ed frequently enough so that the system can be properly controlled The error signal is formed by sub tracting the desired setting of the parameter to be controlled from the actual measured value of th...

Страница 6: ...or T2 T the average for the period will be UOUT FIGURE 8 AVERAGE SPACE VECTOR MODULATION The values for T1 and T2 can be extracted with no extra calculations by using a modified Inverse Clark transfor...

Страница 7: ...egister locations at the end of the code function Most of these variables are grouped into structures of related param eters to provide efficient access from the C or assembly code Each W register use...

Страница 8: ...second CalcRef s This file contains the CalcRefVec function which calculates the scaled 3 phase voltage output vector Vr1 Vr2 Vr3 from v and v The function implements the inverse Clarke function whic...

Страница 9: ...terrupt CalcVelIrp if uGF bit RunMotor Set LED1 for diagnostics pinLED1 1 Calculate velocity from accumulated encoder counts CalcVel Calculate qIa qIb MeasCompCurr Calculate qId qIq from qSin qCos qIa...

Страница 10: ...loop control is maintained You can experiment with field weakening in this application by changing the defined reference value in UserParms h By lowering this value you can limit the available voltage...

Страница 11: ...nd Encoder The following motor and encoder combination was used to develop this application and select the software tuning parameters Leeson Cat 102684 motor 1 3 HP 3450 RPM U S Digital encoder model...

Страница 12: ...le user s guide for the default jumper configuration The following jumper configuration should be used for the motor control development board The isolated hall effect current sensors are used to meas...

Страница 13: ...on RB11 AN11 AI not used in application RB12 AN12 AI not used in application RB13 AN13 AI not used in application RB14 AN14 AI not used in application RB15 AN15 OCFB CN12 O not used in application POR...

Страница 14: ...lication RF2 U1RX I not used in application RF3 U1TX O not used in application RF4 U2RX CN17 I not used in application RF5 U2TX CN18 O not used in application RF6 EMUC3 SCK1 INT0 I not used in applica...

Страница 15: ...change some of the values in the UserParms h file Refer to the Software Tuning section of this document for more information on the adjustment of values in UserParms h Also you will need to modify th...

Страница 16: ...e a reversal of encoder signals with respect to motor wiring and direction of rotation If this is suspected reverse the A and B signals on the encoder wiring connections The encoder wiring will also d...

Страница 17: ...n this application that are interdependent The outer loop controls the motor velocity The two inner loops control the transformed motor currents Id and Iq As mentioned previously the Id loop is respon...

Страница 18: ...ELOCITY 1000 TO 2000 RPM STEP TR 0 078 SEC Figure 16 shows the same phase current and velocity data shown in Figure 15 In this case a step change is made from 1000 RPM to 2000 RPM in open loop mode Th...

Страница 19: ...herewith by Microchip Technology Incorporated the Company is intended and supplied to you the Company s customer for use solely and exclusively with products manufactured by the Company The software i...

Страница 20: ...r revolution define diNomRPM 3600 Name Plate Motor RPM define dfRotorTmConst 0 078 Rotor time constant in sec from mfgr Measurement define diIrpPerCalc 30 PWM loops per velocity calculation PI Coeffic...

Страница 21: ...ged to use program space for storage of sine data Added DiagnosticsOutput function that uses output compare channels to output control variable information Added TORQUE_MODE definition to bypass veloc...

Страница 22: ...rm ReadADCParm int iRPM WORD iMaxLoopCnt WORD iLoopCnt WORD iDispLoopCnt void __attribute__ __interrupt__ _ADCInterrupt void void SetupBoard void bool SetupParm void void DoControl void void Dis_RPM B...

Страница 23: ...t while waiting MeasCompCurr while pinButton1 when button 1 is released uGF bit RunMotor 1 then start motor Run the motor uGF bit ChangeMode 1 Enable the driver IC on the motor control PCB pinPWMOutpu...

Страница 24: ...GF bit ChangeMode 1 uGF bit OpenLoop uGF bit OpenLoop pinLED2 uGF bit OpenLoop while running button 3 will double half the speed or torque demand if pinButton3 if uGF bit Btn3Pressed uGF bit Btn3Press...

Страница 25: ...ue 8 else CtrlParm qVelRef ReadADCParm qADValue 16 if uGF bit OpenLoop OPENLOOP force rotating angle Vd Vq if uGF bit ChangeMode just changed to openloop uGF bit ChangeMode 0 synchronize angles OpenLo...

Страница 26: ...ference value read from the potentiometer is used directly as the torque reference VqRef ifdefTORQUE_MODE CtrlParm qVqRef CtrlParm qVelRef else Check to see if new velocity information is available by...

Страница 27: ...ecution of display and button functions iDispLoopCnt acumulate encoder counts since last interrupt CalcVelIrp if uGF bit RunMotor Set LED1 for diagnostics pinLED1 1 use TMR1 to measure interrupt time...

Страница 28: ...bChrPosR else Wrt_S_LCD bChrPosC bChrPosR iRPM EncoderParm iDeltaCnt 60 MotorParm fLoopPeriod MotorParm iIrpPerCalc EncoderParm iCntsPerRev Wrt_Signed_Int_LCD iRPM bChrPosC 1 bChrPosR bool SetupParm v...

Страница 29: ...caleFluxPeriod 1 0 MotorParm fScaleFluxRPS Fraction of revolution per LoopTime at maximum flux velocity MotorParm fScaleFracRevPerLoop MotorParm fLoopPeriod MotorParm fScaleFluxRPS Scaled flux speed o...

Страница 30: ...ef SVGen Set PWM period to Loop Time SVGenParm iPWMPeriod dLoopInTcy TIMER 1 PR1 0xFFFF T1CONbits TON 1 T1CONbits TCKPS 1 prescale of 8 1 08504 uS tick Motor PWM PDC1 0 PDC2 0 PDC3 0 PDC4 0 Center ali...

Страница 31: ...H0 CH1 CH2 CH3 simultaneously when CHPS 1x Samples CH0 and CH1 simultaneously when CHPS 01 ADCON1bits SIMSAM 1 Sampling begins immediately after last conversion completes SAMP bit is auto set ADCON1bi...

Страница 32: ...006 OC8CON 0x0006 T2CONbits TON 1 endif return False ifdefDIAGNOSTICS void DiagnosticsOutput void int Data if IFS0bits T2IF IFS0bits T2IF 0 Data ParkParm qIq 4 0xfff if Data 0x1ff0 Data 0x1ff0 if Data...

Страница 33: ...l Runtime equation qMechVel qKvel 2 15 Delta 2 Nvel Scaling equations fVelCalcPeriod fVelIrpPeriod iIrpPerCalc MaxCntRate CntsPerRev ScaleMechRPS MaxDeltaCnt fVelCalcPeriod MaxCntRate qKvel 2 15 2 Nve...

Страница 34: ...scaled by maximum current qVelSlip Mechnical Slip velocity in RPS scaled by fScaleMechRPS qAngFlux Flux angle scaled by pi Scaled Equations qImag qImag qKcur qId qImag qVelSlip Kslip qIq qImag qAngFlu...

Страница 35: ...rADC1 qIb 2 qKb CorrADC2 The factor of 2 is designed to allow qKa qKb to be given in 1 15 Functional prototypes void MeasCompCurr void void InitMeasCompCurr short iOffset_a short iOffset_b On Start Mu...

Страница 36: ...Offset add _MeasCurrParm ADC_iOffsetLb mov w w1 w0 addc _MeasCurrParm ADC_iOffsetHb return ClarkePark s ClarkePark Description Calculate Clarke Park transforms Assumes the Cos and Sin values are in qS...

Страница 37: ...Ibeta Ia OneBySq3 2 Ib OneBySq3 mov w OneBySq3 Sq3W 1 sqrt 3 in 1 15 format mov w _ParkParm Park_qIa IaW mpy Sq3W IaW A mov w _ParkParm Park_qIb IbW mac Sq3W IbW A mac Sq3W IbW A mov w _ParkParm Park_...

Страница 38: ...Magnetizing current scaled by maximum current 1 31 qVelSlip Mechnical Slip velocity in RPS scaled by fScaleMechRPS qAngFlux Flux angle scaled by pi Scaled Equations qdImag qdImag qKcur qId qdImag qVe...

Страница 39: ...rMod_qKcur w5 mac w4 w5 A add Kcur Id Imag to Imag sac A w7 mov w ACCALL w6 mov w w6 _CurModelParm CurMod_qdImag mov w w7 _CurModelParm CurMod_qdImag 2 qVelSlip qKslip qIq qdImag First make qIqW and q...

Страница 40: ...1 0 We also know that we have maximum precision sac A w6 repeat 17 divf w6 ImagW w0 KslipW IqW ImagW w1 remainder Limit maximum slip speed mov w _CurModelParm CurMod_qMaxSlipVel w1 cp w1 w0 qMaxSlipSp...

Страница 41: ...Registers modified w3 w7 A Timing About 14 instruction cycles include general inc External references include park inc Register usage equ ParmW w3 Ptr to ParkParm structure equ SinW w4 equ CosW w5 eq...

Страница 42: ...ters Input arguments None Return Void SFR Settings required CORCON SATA 0 Support routines required None Local Stack usage None Registers modified w0 w4 w5 w6 Timing About 20 instruction cycles includ...

Страница 43: ...VbetaW 1 A Vr2 Vbeta 2 sqrt 3 2 Valpha mac ValphaW ScaleW A add Valpha sqrt 3 2 to A sac A WorkW mov w WorkW _SVGenParm SVGen_qVr2 AccA Vbeta 2 lac VbetaW 1 A Vr3 Vbeta 2 sqrt 3 2 Valpha msc ValphaW...

Страница 44: ...PosW _EncoderParm Encod_iPrevCnt clr w _EncoderParm Encod_iAccumCnt Load iVelCntDwn mov w _EncoderParm Encod_iIrpPerCalc WREG mov w WREG _EncoderParm Encod_iVelCntDwn return CalcVelIrp Called from tim...

Страница 45: ...nt Pos if iDelta 0 Delta 0 either because 1 vel is 0 or 2 Vel 0 and encoder wrapped around if Delta EncoderParm iCntsPerRev 2 Delta EncoderParm iCntsPerRev 2 Neg speed wrapped around Delta EncoderParm...

Страница 46: ...c Delta New Prev sub w PosW WorkW DeltaW bra N jEncoder5 Delta 0 Delta 0 either because 1 vel is 0 or 2 Vel 0 and wrapped around lsr w _EncoderParm Encod_iCntsPerRev WREG WREG CntsPerRev 2 Is Delta Cn...

Страница 47: ...iVelCntDwn iIrpPerCalc mov w _EncoderParm Encod_iIrpPerCalc WREG mov w WREG _EncoderParm Encod_iVelCntDwn Copy iAccumCnt to iDeltaCnt then iAccumCnt 0 mov w _EncoderParm Encod_iAccumCnt DeltaW mov w D...

Страница 48: ...cVel qVelMech qKvel Delta 2 Nvel 2 15 iDeltaCnt is an integer but as Q15 it iDeltaCnt 2 15 mov w _EncoderParm Encod_iDeltaCnt DeltaW mov w _EncoderParm Encod_qKvel WorkW mpy WorkW DeltaW A dKvel Delta...

Страница 49: ...ParkParm structure must contain qSin qCos qIa and qIb On Exit ParkParm will contain qId qIq Parameters Input arguments None Return Void SFR Settings required CORCON SATA 0 If there is any chance that...

Страница 50: ...Park_qIa IalphaW mov w IalphaW _ParkParm Park_qIalpha sac A IbetaW mov w IbetaW _ParkParm Park_qIbeta Ialpha and Ibeta have been calculated Now do rotation Get qSin qCos from ParkParm structure mov w...

Страница 51: ...ians AngFlux AngFlux fLoopPeriod 2 pi VelFluxRPS Scaled Variables qdImag Magnetizing current scaled by maximum current 1 31 qVelSlip Mechnical Slip velocity in RPS scaled by fScaleMechRPS qAngFlux Flu...

Страница 52: ...bal CurModel _CurModel CurModel qdImag qdImag qKcur qId qdImag magnetizing current mov w _CurModelParm CurMod_qdImag w6 mov w _CurModelParm CurMod_qdImag 2 w7 lac w7 A mov w w6 ACCALL mov w _ParkParm...

Страница 53: ...can be shifted without putting a one in the msb location preserves sign ff1l ImagW ShiftW sub w ShiftW 2 ShiftW shifts necessary to put 1 in bit 14 Shift ImagW ImagW ShiftW sl ImagW ShiftW ImagW Shif...

Страница 54: ...qKdelta w5 mac w4 w5 A Need to temporarily turn off data space write saturation while accumulator is stored This is because qAngFlux represents the flux angle and must be able to wrap beyond 0x7FFF bc...

Страница 55: ...ture must contain _FdWeakParm FdWeak_qK1 On Exit FdWeakParm will contain _CtrlParm Ctrl_qVdRef Parameters Input arguments None Return Void SFR Settings required CORCON SATA 0 CORCON IF 0 Support routi...

Страница 56: ...ark void On Entry The ParkParm structure must contain qCos qSin qVd and qVq On Exit ParkParm will contain qValpha qVbeta Parameters Input arguments None Return Void SFR Settings required CORCON SATA 0...

Страница 57: ...ParkParm structure mov w _ParkParm Park_qSin SinW mov w _ParkParm Park_qCos CosW Valpha Vd cos Angle Vq sin Angle mpy CosW VdW A Vd qCos A msc SinW VqW A sub Vq qSin from A mov w _ParkParm Park_qValp...

Страница 58: ...ng constant qKa and qKb must be set elsewhere such that qIa 2 qKa CorrADC1 qIb 2 qKb CorrADC2 The factor of 2 is designed to allow qKa qKb to be given in 1 15 Functional prototypes void MeasCompCurr v...

Страница 59: ...sCurrParm ADC_iOffsetLa mov w w1 w0 addc _MeasCurrParm ADC_iOffsetHa CorrADC2 ADCBUF2 iOffsetHb 2 16 qIb 2 qKb CorrADC2 mov w _MeasCurrParm ADC_iOffsetHb w0 sub w _ADCBUF2 WREG w0 ADC Offset clr w w1...

Страница 60: ...y fScaleMechRPS and the iPoles is required to get Flux vel from Mech vel and the 2 is to scale 2 pi into pi Functional prototype void OpenLoop void On Entry OpenLoopParm structure must contain On Exit...

Страница 61: ...rm OpLoop_qDeltaFlux qAngFlux qAngFlux qDeltaFlux mov w OpenLoopParm OpLoop_qAngFlux Work1W add w Work0W Work1W Work0W mov w Work0W _OpenLoopParm OpLoop_qAngFlux return void InitOpenLoop void Initiali...

Страница 62: ...5 format by adjusting the constant by a power of 2 which is removed when the calculation is completed Kp is scaled Kp qKp 2 NKo Ki Kc are scaled Ki qKi Kc qKc Functional prototype void InitPI tPIParm...

Страница 63: ...global _InitPI global InitPI _InitPI InitPI mov w w1 BaseW0 PI_qOut return global _CalcPI global CalcPI _CalcPI CalcPI Err InRef InMeas mov w BaseW0 PI_qInRef WorkW7 mov w BaseW0 PI_qInMeas WorkW5 sub...

Страница 64: ...Outmin mov w UnlimitW6 OutW1 OutW1 U jPI5 mov w OutW1 BaseW0 PI_qOut Ki Err mov w BaseW0 PI_qKi WorkW5 mpy ErrW4 WorkW5 A Exc U Out sub w UnlimitW6 OutW1 UnlimitW6 Ki Err Kc Exc mov w BaseW0 PI_qKc Wo...

Страница 65: ...ates unsigned value 0 2 qK void ReadSignedADC0 tReadADCParm pParm Calculates signed value 2 qK 2 qK On Entry ReadADCParm structure must contain qK ADC channel 0 must contain signed fractional value On...

Страница 66: ...onal i e convert from 1 9999 to 0 0 9999 btg Work1W 15 lsr w Work1W Work1W mpy Work0W Work1W A sac A 1 Work0W mov w Work0W ParmBaseW ADC_qADValue return global _ReadSignedADC0 global ReadSignedADC0 _R...

Страница 67: ...ne Return Void SFR Settings required CORCON SATA 0 CORCON IF 0 Support routines required None Local Stack usage 0 Registers modified w0 w2 w3 w4 w5 w6 AccA Timing 34 instruction cycles C Version of co...

Страница 68: ...ctor 6 1 1 0 240 300 degrees T1 Vr3 T2 Vr2 CalcTimes dPWM1 Tb dPWM2 Tc dPWM3 Ta else Sector 2 0 1 0 300 0 degrees T1 Vr3 T2 Vr1 CalcTimes dPWM1 Ta dPWM2 Tc dPWM3 Tb else x00 Must be Sector 4 since Sec...

Страница 69: ...Vr3W w6 equ TcW w6 equ dPWM1 PDC1 equ dPWM2 PDC2 equ dPWM3 PDC3 CODE section text global _CalcSVGen global CalcSVGen _CalcSVGen CalcSVGen Get qVr1 qVr2 qVr3 mov w _SVGenParm SVGen_qVr1 Vr1W mov w _SV...

Страница 70: ...w Vr2W T2W neg w Vr3W T1W rcall CalcTimes dPWM1 Tb dPWM2 Ta dPWM3 Tc mov w TbW dPWM1 mov w TaW dPWM2 mov w TcW dPWM3 return jCalcRef20 Test Vr2 cp0 Vr2W bra LT jCalcRef30 Vr2W 0 Test Vr3 cp0 Vr3W bra...

Страница 71: ...ion cycles CalcTimes T1 PWM T1 Since T1 is in 1 15 and PWM in integer we do multiply by 2 PWM T1 as integers and use upper word of results Load PWMPeriod sl w _SVGenParm SVGen_iPWMPeriod WREG Mul PWM...

Страница 72: ...nal prototype void SinCos void On Entry ParkParm structure must contain qAngle On Exit ParkParm will contain qSin qCos qAngle is unchanged Parameters Input arguments None Return Void SFR Settings requ...

Страница 73: ...cture mov w _ParkParm Park_qAngle ParkParmW Calculate Index and Remainder for fetching and interpolating Sin mov w TableSize Work0W mov w ParkParmW Work1W load qAngle inc ptr to qCos mul uu Work0W Wor...

Страница 74: ...off end of table but if we use only BYTE operations the wrap is automatic Actualy only add 0x3E since Index increment by two above add b 0x3E IndexW add w IndexW pTabBaseW pTabPtrW Get Y1 Y0 SinTable...

Страница 75: ...ochip Technology Incorporated Printed in the U S A All Rights Reserved Printed on recycled paper Note the following details of the code protection feature on Microchip devices Microchip products meet...

Страница 76: ...Tel 86 21 6275 5700 Fax 86 21 6275 5060 China Shenzhen Rm 1812 18 F Building A United Plaza No 5022 Binhe Road Futian District Shenzhen 518033 China Tel 86 755 82901380 Fax 86 755 8295 1393 China Shu...

Отзывы: