Timer/counter1 output compare registera – ocr1a, Timer/counter1 in pwm mode, Attiny15l – Rainbow Electronics ATtiny15L User Manual
Page 31
31
ATtiny15L
1187E–AVR–06/02
Timer/Counter1 Output
Compare RegisterA – OCR1A
The Output Compare Register 1A is an 8-bit read/write register.
The Timer/Counter Output Compare Register 1A contains the data to be continuously
compared with Timer/Counter1. Actions on compare matches are specified in TCCR1. A
compare match occurs only if Timer/Counter1 counts to the OCR1A value. A software
write that sets TCNT1 and OCR1A to the same value does not generate a compare
match.
A compare match will set (one) the Compare Interrupt Flag in the CPU clock cycle fol-
lowing the compare event.
Timer/Counter1 in PWM Mode
When the PWM mode is selected, Timer/Counter1 and the Output Compare Register A
(OCR1A) form an 8-bit, free-running and glitch-free PWM with outputs on the
PB1(OC1A) pin. Timer/Counter1 acts as an up-counter, counting up from $00 up to the
value specified in the second Output Compare Register OCR1B, and starting from $00
up again. When the counter value matches the contents of the Output Compare Regis-
ter OCR1A, the PB1(OC1A) pin is set or cleared according to the settings of the
COM1A1/COM1A0 bits in the Timer/Counter1 Control Registers TCCR1. Refer to Table
12 for details.
Note that in PWM mode, writing to the Output Compare OCR1A, the data value is first
transferred to a temporary location. The value is latched into OCR1A when the
Timer/Counter reaches OCR1B. This prevents the occurrence of odd-length PWM
pulses (glitches) in the event of an unsynchronized OCR1A write. See Figure 22 for an
example.
Bit
7
6
5
4
3
2
1
0
$2E
MSB
LSB
OCR1A
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0
0
0
0
0
0
0
0
Table 12. Compare Mode Select in PWM Mode
COM1A1
COM1A0
Effect on Compare Pin
0
0
Not connected
0
1
Not connected
1
0
Cleared on compare match (up-counting) (non-inverted PWM). Set
when TCNT1 = $00.
1
1
Set on compare match (up-counting) (inverted PWM). Cleared when
TCNT1 = $00.