1 / 13

Output Compare

Output Compare. 2008/04/17. 暫存器. TMRy : Timer y 的計數暫存器 PRy : Timer y 的週期暫存器 OCxR : 輸出比較主要暫存器 OCxRS :輸出比較次要暫存器 OCxIF : 輸出比較中斷旗標. 計數器. Timer2 Timer3. 輸出比較模式. OC1CONbits.OCM Single Compare Mode 比較符合設為 High (OC_LOW_HIGH) 比較符合設為 Low (OC_HIGH_LOW) 比較符合電位反轉 (OC_TOGGLE_PULSE)

gaston
Download Presentation

Output Compare

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. Output Compare 2008/04/17

  2. 暫存器 • TMRy:Timer y的計數暫存器 • PRy: Timer y的週期暫存器 • OCxR: 輸出比較主要暫存器 • OCxRS:輸出比較次要暫存器 • OCxIF: 輸出比較中斷旗標

  3. 計數器 • Timer2 • Timer3

  4. 輸出比較模式 • OC1CONbits.OCM • Single Compare Mode • 比較符合設為High (OC_LOW_HIGH) • 比較符合設為Low (OC_HIGH_LOW) • 比較符合電位反轉 (OC_TOGGLE_PULSE) • Dual Compare Mode • 單一脈衝 (OC_SINGLE_PULSE) • 連續脈衝 (OC_CONTINUE_PULSE) • Pulse-Wide Modulation (PWM) Mode • (OC_PWM_FAULT_PIN_DISABLE) • (OC_PWM_FAULT_PIN_ENABLE)

  5. Single Compare Mode • OC1CONbits.OCM = 0b001 • 將輸出初始化為Low • 比較符合時,將輸出設為High TMRy OCxR OCx OCxIF 2 Tcy

  6. Single Compare Mode • OC1CONbits.OCM = 0b010 • 將輸出初始化為High • 比較符合時,將輸出設為Low TMRy OCxR OCx OCxIF 2 Tcy

  7. Single Compare Mode • OC1CONbits.OCM = 0b011 • 比較符合時,將輸出反轉 TMRy OCxR OCx OCxIF 2 Tcy 使用者清除

  8. Dual Compare Mode • OC1CONbits.OCM = 0b100 • 碰到OCxR設為High,碰到OCxRS設為Low • 輸出產生單一脈衝 TMRy OCxRS OCxR OCx OCxIF 2 Tcy

  9. Dual Compare Mode • OC1CONbits.OCM = 0b101 • 輸出產生連續脈衝 TMRy OCxRS OCxR OCx OCxIF 2 Tcy

  10. Pulse-Wide Modulation (PWM) Mode • OC1CONbits.OCM = 0b110 or 0b111 • 比較符合時,將輸出設為Low • TMRy重置後,輸出設為High Period = (PRy + 1) Duty Cycle = (OCxRS ) TMRy OCxR OCx OCxIF

  11. Pulse-Wide Modulation (PWM) Mode • OCxR:Duty暫存器 • OCxRS:Duty緩衝暫存器 • 初始化時 • 將Duty寫入OCxRS • 將Duty初始值寫入OCxR • 輸出比較動作時 • 將下一週期的Duty寫入OCxRS • 週期開始時OCxR會讀入 OCxRS值

  12. EX13-2 ADCBUF0 != 0 • 連續脈衝模式 • PR2 = 0xE100 • OCxR = 0x0000, OCxRS = ADCBUF<<6 • 0x0000 < OCxRS < 0xFFC0 Period = (PR2 + 1) Duty Cycle = (OC1RS ) TMR2 OC1RS OC1R OC1

  13. EX13-2 ADCBUF0 = 0 ADCBUF0 = 0x0000 => OCxR = 0xFFFF, OCxRS = 0x0000 OC1R Period = (PR2 + 1) TMR2 OC1RS OC1

More Related