150 likes | 421 Views
Motor Control PWM. 2008/4/23. MCPWM 相關電路圖. 暫存器. PTPER : PWM 週期暫存器 PTMR : PWM 計數暫存器 PTMRbits.PTDIR :計數方向 PDCx :第 x 組 PWM 責任週期暫存器 PWMIF : PWM 中斷旗標. PWM Time Base Mode. Free Running mode (PWM_MOD_FREE) Single Event mode (PWM_MOD_SING) Continuous Up/Down Count mode (PWM_MOD_UPDN)
E N D
Motor Control PWM 2008/4/23
暫存器 • PTPER:PWM週期暫存器 • PTMR:PWM計數暫存器 • PTMRbits.PTDIR:計數方向 • PDCx:第x組PWM責任週期暫存器 • PWMIF:PWM中斷旗標
PWM Time Base Mode • Free Running mode • (PWM_MOD_FREE) • Single Event mode • (PWM_MOD_SING) • Continuous Up/Down Count mode • (PWM_MOD_UPDN) • Continuous Up/Down Count mode with interrupts for double-updates • (PWM_MOD_DBL)
對齊模式 • 邊緣對齊 • Free Running mode • Single Event mode • 中央對齊 • Continuous Up/Down Count mode
Free Running mode • PTCONbits.PTMOD = 0b00 • PTMR遞增計數,與PTPER符合後重置,週而復始。 Period PTPER PTMR PDCx<15:1> PWMxH Duty Cycle 產生中斷
Single Event mode • PTCONbits.PTMOD = 0b01 • 設定PTEN後開始遞增計數 • PTMR與PTPER比較符合後,PTMR重置,PTEN自動清除 PTPER PDCx<15:1> PTMR PTEN PWMxH PWMIF
Continuous Up/Down Count mode • PTCONbits.PTMOD = 0b10 • PTMR遞增計數到PTPER後開始遞減計數 • PTMR遞減計數到0後開始遞增計數 Period PTPER PTMR PDCx<15:1> PWMxH PTDIR 產生中斷
Up/Down Count & Double Updates • PTCONbits.PTMOD = 0b11 • PTMR等於0或是頂到PTPER都產生中斷 Period PTPER PTMR PDCx<15:1> PWMxH PTDIR 產生中斷
週期的計算 • Free Running Count Mode • PTPER = FCY / (FPWM.Prescaler) – 1 • Up/Down Counting Mode • PTPER = FCY / (FPWM.Prescaler .2) – 1
PDCx 0 1 • PDCx<15:1>用來與PTMR<14:0>比較 • PDCx<0>用來決定PWM訊號邊緣發生在TCY或是TCY/2 • 所以 PTPER = 0x7FFF, PDCx = 0x7FFF 時 Duty = 50% 15 PDCx
PDCx 9TCY PTPER = 8 TCY PTMR PDC1 = 12 PDC1<15:1> = 6, PDC1<0> = 0 Duty = 6 / (8+1) = 67% PWM1H TCY/2 PDC2 = 13 PDC2<15:1> = 6, PDC2<0> = 1 Duty = 6.5 / (8+1) = 72% PWM2H
責任週期的計算 • Free Running Count Mode • Duty cycle = [(PDCx / 2) – DT] / (PTPER + 1) • Up/Down Counting Mode • Duty cycle = (PDCx – DT) / [(PTPER + 1) . 2] Note: DT = Dead Time
PWM Output Mode • Complementary (PWM_MODx_COMP) • Independent (PWM_MODx_IND) PWMxH PWMxL PWMxH PWMxL