PIC BLDC三相電機(jī)研讀總結(jié)及舵機(jī)測試框架_第1頁
PIC BLDC三相電機(jī)研讀總結(jié)及舵機(jī)測試框架_第2頁
PIC BLDC三相電機(jī)研讀總結(jié)及舵機(jī)測試框架_第3頁
PIC BLDC三相電機(jī)研讀總結(jié)及舵機(jī)測試框架_第4頁
PIC BLDC三相電機(jī)研讀總結(jié)及舵機(jī)測試框架_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、PIC BLDC三相電機(jī)研讀總結(jié)(james14888gmailcom)ADC中斷處理void _attribute_(_interrupt_,auto_psv) _ADC1Interrupt(void)uint16 u16MotorNeutralVoltage;uint16 u16MotorPhaseA;uint16 u16MotorPhaseB; uint16 u16MotorPhaseC; DesiredSpeed = ADC1BUF0; /POT u16MotorPhaseA = ADC1BUF3; /-V1 u16MotorPhaseB = ADC1BUF2; /-V2 u16Mot

2、orPhaseC = ADC1BUF1; /-V3u16MotorNeutralVoltage = (u16MotorPhaseA + u16MotorPhaseB + u16MotorPhaseC)/3;AD1CON1bits.DONE = 0;IFS0bits.AD1IF = 0;/* ADC SAMPLING & BMEF signals comparison */if(u16MotorPhaseA > u16MotorNeutralVoltage)Comparator.PhaseAOutput = 1; else Comparator.PhaseAOutput = 0;i

3、f(u16MotorPhaseB > u16MotorNeutralVoltage)Comparator.PhaseBOutput = 1; else Comparator.PhaseBOutput = 0;if(u16MotorPhaseC > u16MotorNeutralVoltage)Comparator.PhaseCOutput = 1; else Comparator.PhaseCOutput = 0;u16ComparatorOutputs = (Comparator.PhaseCOutput<<2) & 0x0007;u16ComparatorO

4、utputs |= (Comparator.PhaseBOutput<<1);u16ComparatorOutputs |= Comparator.PhaseAOutput;輸出兩個參量:DesiredSpeed電位器定位的目標(biāo)速度u16ComparatorOutputs 與平均電壓比較的結(jié)果指示 主函數(shù)int main(void) PLLFBD=38; / M=40 80MHz ;40MIPS CLKDIVbits.PLLPOST=0;/ N2=2 CLKDIVbits.PLLPRE=0;/ N1=2 RCONbits.SWDTEN=0;while(OSCCONbits.LOCK

5、 != 1) ;/ Wait for PLL to lockKps = 3000;Kis = 2;PILoopControllerOutput = 0;timer3value = 0;timer3avg = 0;.for(;)while (!S1);/ wait for S1 button to be hitwhile (S1)/ wait till button is releasedDelayNmSec(20);u16CurrentPWMDutyCycle = 1;u16DesiredPWMDutyCycle = 0;DesiredSpeed = 0;ActualSpeed = 0;Spe

6、edError = 0;SpeedIntegral = 0;PILoopControllerOutput = 0;timer3value = 0;timer3avg = 0;PWM1CON1 = 0x0777;/ enable PWM outputsDelayNmSec(1);Flags.RampUpBEMF =1;Flags.RunMotor = 1;/ indicationg the run motor condition.while (Flags.RunMotor)/ while motor is runningwhile(Flags.RampUpBEMF)if(u16CurrentPW

7、MDutyCycle < MIN_DUTY_CYCLE) / 1469 = 100% duty cycle u16CurrentPWMDutyCycle+;DelayNmSec(1);else/ MIN_DUTY_CYCLE = 72;Flags.RampUpBEMF = 0;T3CONbits.TON = 1;if (S1)/ if S5 is pressedPWM1CON1 = 0x0700;/ disable PWM outputs P1OVDCON = 0x0000;/ overide PWM low.Flags.RampUpBEMF = 0;Flags.RunMotor = 0

8、;/ reset run flagu16CurrentPWMDutyCycle = 1;while (S1)/ wait for key releaseDelayNmSec(20);/end of motor running loop/end of infinite loop/end of main function從主函數(shù)可以看出,它的算法控制系數(shù) Kps 為 3000,Kis 為 2;PWM的占空比有最小值MIN_DUTY_CYCLE,為 72。PWM中斷處理:void _attribute_(_interrupt_,auto_psv) _MPWM1Interrupt (void) if(

9、Flags.Direction = CW) if(u16ComparatorOutputsADC_XORADCCommState)& CW_ADC_MASKADCCommState) ADC_bemf_filter |= 0x01; else if(u16ComparatorOutputsADC_XORADCCommState)& CCW_ADC_MASKADCCommState) ADC_bemf_filter |= 0x01; if(u16CurrentPWMDutyCycle > 160) /u16CurrentPWMDutyCycle P1SECMPbits.SE

10、VTCMP = u16CurrentPWMDutyCycle>>1; else if(u16CurrentPWMDutyCycle>76) /P1SECMPbits.SEVTCMP =48; P1SECMPbits.SEVTCMP = u16CurrentPWMDutyCycle>>3; else P1SECMPbits.SEVTCMP = 0; ADC_bemf_filter = ADC_BEMF_FILTERADC_bemf_filter; if (ADC_bemf_filter&0b00000001) Commutate(); Comparator.

11、Commutation = Comparator.Commutation; /Commutation u16CommutationStatus = Comparator.Commutation; /Ramp-up period to detect the rotor position if(Flags.RampUpBEMF) / P1DC1=P1DC2=P1DC3=u16CurrentPWMDutyCycle; /u16CurrentPWMDutyCycle if (+ PWMticks > MAX_PWMticks) / MAX_PWMticks = 1024 Commutate();

12、 IFS3bits.PWM1IF = 0;PWM中斷處理函數(shù)_MPWM1Interrupt( ) 的核心內(nèi)容是處理換向。一是PWM中斷計數(shù)到達(dá)1024個調(diào)用一次換向Commutate(),或者是ADC輸出中三個輸出不平衡,又沒有被濾波濾掉,這調(diào)用一次換向Commutate()。 PWM中斷的第二個任務(wù)就是控制ADC采樣的時間, 當(dāng)占空比比較大時,采樣間隔比較大;但占空比比較小時,采樣間隔比較小。其中:ADC_XOR8 = 0x0000,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000CW_ADC_MASK8 = 0x0000,0x0002,0x0

13、001,0x0004,0x0002,0x0001,0x0004,0x0000ADC_BEMF_FILTER64= 0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12,0x14,0x16,0x18,0x1A,0x1C,0x1E0x20,0x22,0x24,0x26,0x28,0x2A,0x2C,0x2E,0x01,0x01,0x01,0x36,0x01,0x3A,0x3C,0x3E,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x01,0x01,0x01,0x16,0x01,0x1A,0x1C,0x1E,0x01

14、,0x01,0x01,0x26,0x01,0x2A,0x2C,0x2E,0x01,0x01,0x01,0x36,0x01,0x3A,0x3C,0x3E ;問題:用三個數(shù)組,變動下標(biāo),就可以實(shí)現(xiàn)濾波過濾,算法原理是什么?換向處理void Commutate(void)/ The code below is uses TMR3 to calculate the speed of the rotorif (ADCCommState = INDEX)/ has the same position been sensed?if (u8PoleCounter+ >= POLEPAIRS) / has

15、 one mech rev elasped?/ if yes then read timer 3T3CONbits.TON = 0;/ Stop TIMER3timer3value = TMR3;TMR3 = 0;timer3avg = (timer3avg + timer3value) >> 1);if(!Flags.RampUpBEMF)SpeedPILoopController();u8PoleCounter = 1;T3CONbits.TON = 1;/ Start TIMER3 /CommutationADC_bemf_filter=0;if (+ADCCommState

16、>6)ADCCommState=1; if(Flags.Direction = CW) P1OVDCON = CW_PWM_STATEADCCommState; else P1OVDCON = CCW_PWM_STATEADCCommState;PWMticks=0;換向處理主要處理兩件事情。一件是速度的PI算法反饋控制SpeedPILoopController();另一件是產(chǎn)生三相控制信號。其中:1) TIMER3用來計算電機(jī)轉(zhuǎn)速。2) 數(shù)組CW_PWM_STATE8 = 0x0000,0x2001,0x2004,0x0204,0x0210,0x0810,0x0801,0x0000;和

17、PIC的PWM硬件與本軟件共同產(chǎn)生如下的控制信號(其中PWM脈沖為20KHz):POVD1 : I/O引腳由PWM發(fā)生器控制POUT1 : I/O 引腳被驅(qū)動為有效狀態(tài)0 : I/O引腳由POUT寄存器控制0 : I/O 引腳被驅(qū)動為無效狀態(tài)POVDPOUT3H3H2H2L1H1L3H3L2H2L1H1L000000000000100000000001100000000100000010000100000010010000001000010000001000000001000000000000PI控制算法void SpeedPILoopController(void) /For the HUR

18、ST motor the Timer3Avg values/TIMER3 counts = 9562 AT 7.5% dutycycle (P1DC1 = 109) /TIMER3 counts = 714 AT 100% dutycycle (P1DC1 = 1469)/RPSelectrical = 19-261Hz /RPMelctrical = 1179-15669RPM /Normalizing TIMER3 counts to electrical RPMActualSpeed = (SPEEDMULT/timer3avg)*60;/ADC POT RANGE 0-1024, 10

19、24*16 = MAXSPEED in electrical RPM DesiredSpeed = DesiredSpeed<<4;/Calculating ErrorSpeedError = DesiredSpeed - ActualSpeed;SpeedIntegral += SpeedError;/Dividing PI output by PI controller gain (2exp14)PILoopControllerOutput = (long)Kps*(long)SpeedError + (long)Kis*(long)SpeedIntegral) >>

20、; 14); /Divided by 11 to normalize the PI output to PWM PDCx values u16DesiredPWMDutyCycle = u16DesiredPWMDutyCycle + (PILoopControllerOutput/11); / Max and Min PWM duty cycle limitsif (u16DesiredPWMDutyCycle < MIN_DUTY_CYCLE)u16DesiredPWMDutyCycle = MIN_DUTY_CYCLE;SpeedIntegral = 0;if (u16DesiredPWMDutyCycle > MAX_DUTY_CYCLE)u16DesiredPWMDutyCycle = MAX_DUTY_CYCLE;SpeedIntegral = 0; P1DC1 = u16DesiredPWMDutyCycle;P1DC2 = u16DesiredPWMDutyCycle;P1DC3 = u16DesiredPWMDutyCycle;u16CurrentPWM

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論