1 / 10

PWM

PWM. PTPER: 代表 PWM 的週期暫存器 PTSIDL: 0 = 繼續動作 1 = 閒置模式 PDC1~3: 設定 PWM 的責任週期 PTMR: PWM 內部計數值 PTCKPS: 設定除頻的數值 00 = 1 01 = 4 10 = 16 11 = 64. PWM 的四種模式 PTMOD<1,0> 00 = Free run mode. 01 = Signal-Event Mode 10 = Up/Down Counting Mode

herve
Download Presentation

PWM

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PWM

  2. PTPER:代表 PWM 的週期暫存器 PTSIDL: 0 = 繼續動作 1 = 閒置模式 PDC1~3:設定PWM的責任週期 PTMR:PWM內部計數值 PTCKPS:設定除頻的數值 00=1 01=4 10=16 11=64

  3. PWM的四種模式 PTMOD<1,0>00 = Free run mode. 01 = Signal-Event Mode 10 = Up/Down Counting Mode 11 = Up/Down Counting Mode with Interrupt for double PWM updates PWMCON1 register PMOD3~PMOD1 1 = 獨立輸出 0 = 互補輸出 PEN3H~PEN1L 1 = 作PWM的I/O 0 = 作一般I/O用途 OVDCON Register POVD3H~POVD1L 1 = PWM輸出 0 = PWM無輸出,但會對應到POUT POUT3H~POUT1L(POVD為0時才會進入判斷) 1 = 輸出High 0 = 輸出Low

  4. FREE RUNNING MODE

  5. CONTINUOUS UP/DOWN COUNT MODE

  6. #include <p30F4011.h> //呼叫p30F3011(IC)指令巨集 _FWDT(WDT_OFF); void PWM_Initial(void) { PTPER = 1250; //PWM = (20MHz / 16 / 1250) = 1 kHz IEC2bits.PWMIE = 0; //Disable PWM Interrupt 禁止PWM中斷 PTCON = 0xA008; // 0b 1010 0000 0000 1000 PWMCON1 = 0x0777; // 0b 0000 0111 0111 0111 PDC1 = 1250; //設定duty cycle的大小 100%為PTPER2倍=2500 OVDCON= 0x0100; //設定PWM的輸出腳位 IPC9bits.PWMIP = 6;//優先權 } int main(void) { PWM_Initial(); while(1); }

  7. 請設計 PWM1=30%,頻率=2 KHz PWM2=60% PWM3=90% PWM3請利用互補輸出,其他則利用獨立輸出即可。 練習

  8. 原因是在初始化的时候,PDCx为0,而工作在single event的模式只能进一次中断,所以ISR里面设置的PDCx没有起作用,除非PTEN再置位一次。 PWM 的時脈可配置為 4 種不同的工作模式: •自動運行模式 •單事件模式 •連續遞增/遞減計數模式 •帶雙更新中斷的連續遞增/遞減計數模式 通過 PTCON 時的 SFR 中的 PTMOD<1 時 00 分>位可選擇這 4 種模式。 遞增/遞減計數模式支持產生中心對齊的脈寬調製器。單事件模式使 PWM 的模塊可支持某些電子換相電機(流腦)的脈衝控制。PWM 的時 基產生的中斷信號取決於 PTCON 時的 SFR 中的模式選擇位 (PTMOD<1:0>)和後分頻比位(PTOPS<3:0>)。

More Related