Beruflich Dokumente
Kultur Dokumente
a.
b.
E.
Automatically Control power to light intensity by controlling the
power to the lamp where on-time vs. off-time is an effective control.
1|P a ge
L.122A.5
2.
C.
DS-81, TXT-574
D.
E.
T3CON is used to configure the timer to be used, prescale, clock
source and start/stop of the timer. DS-148, TXT-574
F.
G.
Example program 15.1 to receive clock pulses on Timer1 pin
T1CKI (RC0) and toggle an LED on RC2 (CCP1 pin) after every 10th
input clock pulse. TXT-576
2|P a ge
L.122A.5
H.
Example 15.2 creates a square wave with a 40ms period and a
50% duty cycle on CCP1 pin using the compare mode. TXT-577
3|P a ge
L.122A.5
3.
e.
Read the Timer1 (or Timer3) register value on the second rising
edge and save the end value.
f.
Subtract the start value (d) from the end value (e).
E.
Example 15-3 measures the period of the incoming waveform on
CCP1 pin (RC2) and puts the measured results on PORTB and PORTD.
The measurement is in terms of Fosc/4 clock period. TXT-581
F.
Example 15-4 illustrates a method for measuring pulse width of
an incoming waveform. Eg. Measuring the On-Time of a PWM signal
or measuring the duration of a single event from on to off states.
4|P a ge
L.122A.5
G.
Measuring Pulse Width requires starting the Timer1 with the
rising-edge of the input and ending with the trailing edge of the same
pulse. TXT-582 Example program 15-4 follows. TXT-583
5|P a ge
L.122A.5
6|P a ge
L.122A.5
4.
C.
The Duty Cycle of PWM is the percent of ON-Time for the Period
of the PWM. The Duty Cycle value is always a percentage of the Period
and therefore always a percentage of the PR2 value in this example.
TXT-588
D.
Example: 2.5kHz PWM frequency with a 10Mhz XTAL and a
75% duty cycle find the value to be loaded into CCPR1L.
PR2 = [(10MHz/(4 x 2.5kHz x 4)] -1 = 250-1 = 249 (the period of the PWM)
Duty Cycle = 249 x 75% = 186.75 therefore load CCPR1L with 186 and
DC1B2:DC1B1 with 11 for the .75 decimal portion of the calculation .
7|P a ge
L.122A.5
E.
g.
Start Timer2.
F.
Example 15-5 illustrates a PWM output on CCP1 pin with a
2.5kHz frequency and a 75% duty cycle using TMR2IF flag
8|P a ge
L.122A.5
5.
B.
C.
D.
c.
6.
B.
Timer Resource
CCP/ECCP Mode
Capture
Compare
PWM
C.
Timer Resources
Timer1 or Timer3
Timer1 or Timer3
Timer2
9|P a ge
L.122A.5
D.
II.
C.
Example 15-6 uses Timer 3 as the counter and toggles the
CCP1/ECCP1 pin every 20 pulses.
10 | P a g e
L.122A.5
2.
e.
Read the Timer1 (or Timer3) register value on the second risingedge and save the second value.
f.
C.
Subtract the start value (d) from the ending value (e)
Example 15-7 captures the pulse on-time feeding the ECCP1 pin
11 | P a g e
L.122A.5
3.
B.
C.
ECCP provides 2 and 4 ECCP output pins to drive Half-Bridge
and Full-H-Bridge motor drive circuits. DS-175, TXT-597
D.
The PWM outputs are multiplexed with I/O pins and are
designated P1A, P1B, P1C, and P1D. The polarity of the PWM pins is
configurable and selected by setting the CCP1M bits in the CCP1CON
register. Refer to table 16-1 DS-175
E.
g.
Start Timer2
F.
Example 17-3 illustrates the Full-Bridge implementation of the
PWM in ECCP TXT-668
;Program 17-3
CLRF TRISD
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
AGAIN CLRF
BCF
WAIT BTFSS
BRA
BRA
L.122A.5
13 | P a g e