Các chế độ hoạt độngSingle compare match mode, Dual compare match mode generating either one output pulse or a sequence of output pulses, Pulse Width Modulation PWM mode... Single com
Trang 1Output Compare
Chuyên đề II
Vi điều khiển và ứng dụng
Trang 2OC with DsPIC
2
Trang 3Chi tiết
3
Trang 4Chức năng
4
Trang 5Các chế độ hoạt động
Single compare match mode,
Dual compare match mode generating either one output pulse or a sequence of output pulses,
Pulse Width Modulation (PWM) mode
5
Trang 6Single compare match
OCx pin is high, initial state is low, and interrupt is generated,
OCx pin is low, initial state is high, and interrupt is generated,
State of OCx pin toggles and interrupt is generated
6
Trang 7OCx pin is high control bits OCM<2:0> are set to 001
7
Trang 8OCx pin is low
OCM<2:0> are set to 010
8
Trang 9Single compare match, pin OCx toggles
OCM<2:0> areset to 011
9
Trang 10Ví dụ
10
Trang 11Dual compare match
mode
single pulse and an interrupt request,
a sequence of pulses and an interrupt request
control bits OCM<2:0> are set to 100 or 101
11
Trang 12Single output pulse at pin Ocx
OCM<2:0> are set to 100
12
Trang 13Sequence of output pulses at pin Ocx
control bits OCM<2:0> are set to 101
13
Trang 14Ví dụ
14
Trang 15The Pulse Width
Trang 16PWM mode without fault protection input
Set the PWM period by writing to the selected
timer period register, PRy.
Set the PWM duty cycle by writing to the OCxRS register.
Write the OCxR register with the initial duty cycle.
Enable interrupts for the selected timer.
Configure the output compare module for one of two PWM operation modes by writing 100 to
control bits OCM<2:0> (OCxCON<2:0>).
Set the TMRy prescale value and enable the
selected time base.
16
Trang 17PWM mode with fault
protection input pin
Input pin OCxFA for the output compare
Trang 18PWM period and duty
Calculation of the PWM period for a microcontroller having
a 10MHz clock with x4 PLL, Device clock rate is 40MHz The instruction clock frequency is FCY=FOSC/4, i.e
10MHz Timer 2 prescale setting is 4 Calculate the PWM period for the maximum value PR2=0xFFFF=65535.
TPWM = (65535+1) x 0.1µs x (4) = 26.21 ms, i.e fPWM = 1/TPWM = 38.14 Hz.
18
Trang 19PWM duty cycle
If the duty cycle register,OCxR, is loaded
with 0000, the duty cycle is zero and pin OCx will remain low throughout the PWM period
If the duty cycle register is greater that PRy, the output pin OCx will remain high
throughout the PWM period (100% duty cycle)
If OCxR is equal to PRy, the OCx pin will be high in the first PWM cycle and low in the subsequent PWM cycle
19
Trang 20Ví dụ
20
Trang 21Mạch D/A
21
Trang 22Ví dụ sóng vuông
22
Trang 23Ví dụ sóng hình thang
23
Trang 24Sóng hình sin
24
Trang 25A second order filter
25
Trang 26Ví dụ ứng dụng
26
Trang 27Circular buffer
27
Trang 28Circular buffer
28
Trang 29Circular Buffer
29
Trang 30Phương pháp hoạt động
Difficulites
30
Trang 31Xử lý lỗi
Always Keep One Slot Open
Use a Fill Count
Read / Write Counts
31
Trang 32Ví dụ
32